পয়েন্ট ক্লাস সংজ্ঞা
STL-র <complex> হেডার থেকে complex<double> ব্যবহার করে পয়েন্ট ক্লাস বানানো যায়। রিয়েল পার্টকে x-কোঅর্ডিনেট এবং ইমেজিনারি পার্টকে y-কোঅর্ডিনেট হিসেবে ব্যবহার করা হয়।
#include <complex> typedef complex<double> point; #define x real() #define y imag()
নোট: x এবং y ম্যাক্রো, ভেরিয়েবল নয়।
উদাহরণ ১: বেসিক পয়েন্ট
#include <iostream>
#include <complex>
using namespace std;
typedef complex<double> point;
#define x real()
#define y imag()
int main() {
point my_pt(4.0, 5.0);
cout << "The point is :(" << my_pt.x << ", " << my_pt.y << ")";
}
The point is :(4, 5)
জ্যামিতিক অপারেশন
- অরিজিন থেকে দূরত্ব:
abs(P) - X-অক্ষের সাথে কোণ:
arg(P)(রেডিয়ানে) - অরিজিন wzglęতে ঘুরানো:
P * polar(r, θ)
উদাহরণ ২: জ্যামিতিক অপারেশন
#include <iostream>
#include <complex>
#define PI 3.1415
using namespace std;
typedef complex<double> point;
#define x real()
#define y imag()
void print_point(point my_pt) {
cout << "(" << my_pt.x << ", " << my_pt.y << ")";
}
int main() {
point my_pt(6.0, 7.0);
cout << "The point is: "; print_point(my_pt); cout << endl;
cout << "Distance from origin: " << abs(my_pt) << endl;
cout << "Angle with X-axis: (" << arg(my_pt) << ") rad = (" << arg(my_pt)*(180/PI) << " deg)" << endl;
point rot_point = my_pt * polar(1.0, PI/2); // ৯০ ডিগ্রি ঘুরানো
cout << "After 90 deg rotation: "; print_point(rot_point);
}
The point is:(6, 7) Distance from origin:9.21954 Angle with X-axis: (0.86217) rad = (49.4002 deg) After 90 deg rotation: (-6.99972, 6.00032)