मान लीजिए हमारे पास एक सर्कल के व्यास के दो एंडपॉइंट्स हैं। ये (x1, y1) और (x2, y2) हैं, हमें सर्कल का केंद्र ढूंढना है। तो यदि दो बिंदु (-9, 3) और (5, -7) हैं, तो केंद्र (-2, -2) पर है।
हम जानते हैं कि दो बिंदुओं के मिड पॉइंट्स हैं -
(xₘ, yₘ) = ((x₁ + x₂)/2, (y₁ + y₂)/2)
उदाहरण
#includeusing namespace std; class point{ public: float x, y; point(float x, float y){ this->x = x; this->y = y; } void display(){ cout << "(" << x << ", " << y << ")"; } }; point center(point p1, point p2) { int x, y; x = (float)(p1.x + p2.x) / 2; y = (float)(p1.y + p2.y) / 2; point res(x, y); return res; } int main() { point p1(-9.0, 3.0), p2(5.0, -7.0); point res = center(p1, p2); cout << "Center is at: "; res.display(); }
आउटपुट
Center is at: (-2, -2)