আমরা একটি C++ প্রোগ্রাম বিবেচনা করব যা চেক করবে একটি পয়েন্ট d একটি প্লেনে পয়েন্ট a, b, c দ্বারা সংজ্ঞায়িত সার্কেলের ভিতরে কি বাইরে, নিচের সমীকরণ ব্যবহার করে:
s = (x-xt)^2 + (y-yt)^2 – r*r
যেখানে, প্লেনে যেকোনো পয়েন্ট t (xt, yt) এর অবস্থান ৩টি পয়েন্ট (x1, y1), (x2, y2), (x3, y3) দ্বারা সংজ্ঞায়িত সার্কেলের সাপেক্ষে।
s < 0 হলে, t সার্কেলের ভিতরে।
s > 0 হলে, t সার্কেলের বাইরে।
s = 0 হলে, t সার্কেলের ওপর।
অ্যালগরিদম
শুরু
পয়েন্টগুলো ইনপুট নাও।
কনস্ট্যান্ট L = 0 এবং H = 20 ডিক্লেয়ার করো।
সমীকরণের ভেরিয়েবল ডিক্লেয়ার করো।
সমীকরণ তৈরি করার জন্য, কম্পাইলেশনের প্রতিবার র্যান্ডম নম্বর জেনারেট করো x এবং y-এর কোয়ফিশিয়েন্টের জন্য rand ব্যবহার করে।
সার্কেলের সেন্টার ক্যালকুলেট করো।
সার্কেলের রেডিয়াস ক্যালকুলেট করো।
s ক্যালকুলেট করো।
যদি s < 0, প্রিন্ট করো "point lies inside the circle"।
অন্যথায় যদি s > 0, প্রিন্ট করো "point lies outside the circle"।
অন্যথায় যদি s = 0, প্রিন্ট করো "point lies on the circle"।
শেষউদাহরণ কোড
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
const int L = 0;
const int H = 20;
int main(int argc, char **argv) {
time_t s;
time(&s);
srand((unsigned int) s);
double x1, x2, y1, y2, x3, y3;
double a1, a2, c1, c2, r;
x1 = rand() % (H - L + 1) + L;
x2 = rand() % (H - L + 1) + L;
x3 = rand() % (H - L + 1) + L;
y1 = rand() % (H - L + 1) + L;
y2 = rand() % (H - L + 1) + L;
y3 = rand() % (H - L + 1) + L;
a1 = (y1 - y2) / (x1 - x2);
a2 = (y3 - y2) / (x3 - x2);
c1 = ((a1 * a2 * (y3 - y1)) + (a1 * (x2 + x3)) - (a2 * (x1 + x2))) / (2 * (a1 - a2)); // সার্কেলের সেন্টার
c2 = ((((x1 + x2) / 2) - c1) / (-1 * a1)) + ((y1 + y2) / 2); // সার্কেলের সেন্টার
r = sqrt(((x3 - c1) * (x3 - c1)) + ((y3 - c2) * (y3 - c2))); // রেডিয়াস
cout << "The points on the circle are: (" << x1 << ", " << y1 << "), (" << x2 << ", " << y2 << "), (" << x3 << ", " << y3 << ")";
cout << "\nThe center of the circle is (" << c1 << ", " << c2 << ") and radius is " << r;
cout << "\nEnter the point: ";
int u, v;
cin >> u;
cin >> v;
double s1 = ((u - c1) * (u - c1)) + ((v - c2) * (v - c1)) - (r * r);
if (s1 < 0)
cout << "\nThe point lies inside the circle";
else if (s1 > 0)
cout << "\nThe point lies outside the circle";
else
cout << "\nThe point lies on the circle";
return 0;
}আউটপুট
The points on the circle are: (8, 4), (9, 17), (5, 9) The center of the circle is (12.6364, 10.8182) and radius is 7.84983 Enter the point: 7 6 The point lies outside the circle