কমপ্লেক্স নম্বর ব্যবহার করে একটি পয়েন্ট X কে অন্য পয়েন্ট Y-র সাপেক্ষে θ কোণে এন্টিক্লকওয়াইজ ঘুরানো যায়। <complex> হেডারের polar(mag, angle) ফাংশন কমপ্লেক্স নম্বর রিটার্ন করে।
সূত্র
X কে Y-র সাপেক্ষে ঘুরানো: (X - Y) * polar(1.0, θ) + Y
ধাপসমূহ
- ট্রান্সলেশন: X থেকে Y বিয়োগ করুন (Y নতুন অরিজিন)।
- রোটেশন: (X-Y) কে polar(1.0, θ) দিয়ে গুণ করুন।
- ব্যাক-ট্রান্সলেশন: ফলাফলে Y যোগ করুন।
C++ প্রোগ্রাম
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> point;
#define x real()
#define y imag()
int main() {
point X(5.0, 3.0);
point Y(2.0, 4.0);
double theta = 3.14 / 2; // 90 ডিগ্রি
point Xnew = (X - Y) * polar(1.0, theta) + Y;
cout << "Rotating X 90 degrees anti-clockwise about Y becomes: ";
cout << "(" << Xnew.x << ", " << Xnew.y << ")" << endl;
return 0;
}
আউটপুট: rotating X 90 degrees anti-clockwise about Y becomes: (3.00239, 6.9992)