समस्या विवरण
एक वृत्त (केंद्र h,k और त्रिज्या r) और रेखा (ax+by+c=0) दी गई है। जांचें कि रेखा वृत्त को स्पर्श करती है, प्रतिच्छेद करती है, या बाहर है।
विधि
- केंद्र से रेखा की लंबवत दूरी P निकालें: P = |ah + bk + c| / √(a²+b²)
- P की त्रिज्या r से तुलना करें:
- P > r → बाहर
- P = r → स्पर्श करती है
- P < r → प्रतिच्छेद करती है
उदाहरण कोड
#include <iostream>
#include <cmath>
using namespace std;
void isTouchOrIntersect(int a, int b, int c, int h, int k, int radius) {
int dist = abs(a * h + b * k + c) / sqrt(a * a + b * b);
if (radius == dist)
cout << "Touching the circle" << endl;
else if (radius > dist)
cout << "Intersecting the circle" << endl;
else
cout << "Outside the circle" << endl;
}
int main() {
int radius = 5, h = 0, k = 0;
int a = 3, b = 4, c = 25;
isTouchOrIntersect(a, b, c, h, k, radius);
return 0;
}
आउटपुट
Touching the circle