এই টিউটোরিয়ালে তিনটি নন-колিনিয়ার পয়েন্ট দিয়ে ত্রিভুজের পরিকেন্দ্র বের করার প্রোগ্রাম দেখানো হয়েছে।
পদ্ধতি
- দুটি বাহু থেকে লাইন ইকুয়েশন বের করুন।
- তাদের লম্ব সমদ্বিবাগক (perpendicular bisector) বের করুন।
- দুটি লম্ব সমদ্বিবাগকের ছেদবিন্দুই পরিকেন্দ্র।
C++ প্রোগ্রাম
#include <iostream>
#include <cfloat>
using namespace std;
#define pdd pair<double, double>
void lineFromPoints(pdd P, pdd Q, double &a, double &b, double &c) {
a = Q.second - P.second;
b = P.first - Q.first;
c = a * P.first + b * P.second;
}
void perpendicularBisectorFromLine(pdd P, pdd Q, double &a, double &b, double &c) {
pdd mid = {(P.first + Q.first)/2, (P.second + Q.second)/2};
c = -b * mid.first + a * mid.second;
double temp = a;
a = -b;
b = temp;
}
pdd lineLineIntersection(double a1, double b1, double c1,
double a2, double b2, double c2) {
double det = a1*b2 - a2*b1;
if (det == 0) return {FLT_MAX, FLT_MAX};
double x = (b2*c1 - b1*c2) / det;
double y = (a1*c2 - a2*c1) / det;
return {x, y};
}
void findCircumCenter(pdd P, pdd Q, pdd R) {
double a, b, c, e, f, g;
lineFromPoints(P, Q, a, b, c);
lineFromPoints(Q, R, e, f, g);
perpendicularBisectorFromLine(P, Q, a, b, c);
perpendicularBisectorFromLine(Q, R, e, f, g);
pdd center = lineLineIntersection(a, b, c, e, f, g);
if (center.first == FLT_MAX)
cout << "বিন্দুগুলো কলিনিয়ার, ত্রিভুজ তৈরি হয়নি\n";
else
cout << "পরিকেন্দ্র: (" << center.first << ", " << center.second << ")\n";
}
int main() {
pdd P = {6, 0}, Q = {0, 0}, R = {0, 8};
findCircumCenter(P, Q, R);
return 0;
}
আউটপুট
পরিকেন্দ্র: (3, 4)