কম্পিউটার টিউটোরিয়াল

C++ প্রোগ্রাম: আভভ-বিলো-অন টেস্ট ব্যবহার করে লাইনের সাপেক্ষে পয়েন্টের পজিশন বের করা


এটি একটি C++ প্রোগ্রাম যা আভভ-বিলো-অন টেস্ট ব্যবহার করে একটি লাইনের সাপেক্ষে একটি পয়েন্টের পজিশন বের করে। প্লেনে যেকোনো পয়েন্ট t (xt, yt) এর অবস্থান লাইন L যা m এবং n কানেক্ট করে, তার সাপেক্ষে স্কালার s ক্যালকুলেট করে বের করা হয় -

Y = A xt + B yt + C

যদি Y < 0, t লাইন L-এর ক্লকওয়াইজ হাফপ্লেনে থাকে; যদি Y > 0, t কাউন্টার-ক্লকওয়াইজ হাফপ্লেনে থাকে; যদি Y = 0, t লাইন L-এর ওপর থাকে।

অ্যালগরিদম

শুরু
    পয়েন্টগুলো ইনপুট নাও।
    লাইনের সমীকরণের জন্য, কম্পাইলেশনের প্রতিবার rand ফাংশন ব্যবহার করে x এবং y-এর কোয়ফিশিয়েন্ট (x1,x2,y1,y2) এর জন্য র‍্যান্ডম নম্বর জেনারেট করো।
    s ক্যালকুলেট করো: (y2 - y1) * x + (x1 - x2) * y + (x2 * y1 - x1 * y2)।
    যদি (s < 0)
        প্রিন্ট করো "The point lies below the line or left side of the line"।
    অন্যথায় যদি (s > 0)
        প্রিন্ট করো "The point lies above the line or right side of the line"।
    অন্যথায়
        প্রিন্ট করো "The point lies on the line"।
শেষ

উদাহরণ কোড

#include <stdlib.h> 
#include <iostream> 
#include <math.h> 
#include <time.h> 
using namespace std; 
const int L = 0; 
const int H = 20; 
int main(int argc, char **argv) { 
    time_t seconds; 
    time(&seconds); 
    srand((unsigned int) seconds); 
    int x1, x2, y1, y2; 
    x1 = rand() % (H - L + 1) + L; 
    x2 = rand() % (H - L + 1) + L; 
    y1 = rand() % (H - L + 1) + L; 
    y2 = rand() % (H - L + 1) + L; 
    cout << "The Equation of the 1st line is: (" << (y2 - y1) << ")x+(" << (x1 - x2) << ")y+(" << (x2 * y1 - x1 * y2) << ") = 0\n"; 
    int x, y; 
    cout << "\nEnter the point:"; 
    cin >> x; 
    cin >> y; 
    int s = (y2 - y1) * x + (x1 - x2) * y + (x2 * y1 - x1 * y2); 
    if (s < 0) 
        cout << "The point lies below the line or left side of the line"; 
    else if (s > 0) 
        cout << "The point lies above the line or right side of the line"; 
    else 
        cout << "The point lies on the line"; 
    return 0; 
}

আউটপুট

The Equation of the 1st line is: (7)x+(0)y+(-105) = 0
Enter the point: 7 6
The point lies below the line or left side of the line

  1. C++ দিয়ে লাইনের এক ছোরা এবং মিডপয়েন্ট দিয়ে অন্য ছোরা বের করা

  2. সি++-এ একটি রেখার মিড-পয়েন্ট বের করার প্রোগ্রাম

  3. সি++-এ ত্রিভুজের কেন্ড্রয়েড (Centroid) বের করার প্রোগ্রাম

  4. সি++-এ সমান্তরাল চতুর্ভুজের (Parallelogram) ক্ষেত্রফল বের করার প্রোগ্রাম