1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <cmath>
using namespace std;
class Distance
{
private:
double x1, x2;
double y1, y2;
double dist;
public:
void set(double a1, double a2, double b1, double b2);
double get_dist()
{
return dist;
}
void rotate(double alpha);
void polar(double x1, double y1, double& r, double& theta);
private:
double calculate();
};
int main()
{
Distance coordinates;
double x1, x2;
double y1, y2;
double dx, dy, slope, interc, px, py, left, top, right, bottom, alpha;
cout << "Enter the first x : ";
cin >> x1;
cout << "Enter the first y : ";
cin >> y1;
cout << "Enter the second x : ";
cin >> x2;
cout << "Enter the second y : ";
cin >> y2;
cout << "Enter an angle : ";
cin >> alpha;
coordinates.set(x1, x2, y1, y2);
cout << "\n\nThe distance is " << coordinates.get_dist() << endl;
dx = x2 - x1;
dy = y2 - y1;
slope = dy / dx;
interc = y1 - slope * x1;
if (x1 < x2)
{
left = x1;
right = x2;
}
else
{
left = x2;
right = x1;
}
if (y1 < y2)
{
top = y1;
bottom = y2;
}
else
{
top = y1;
bottom = y2;
}
if (slope * px + interc >(py - 0.01) &&
slope * px + interc < (py + 0.01))
{
if (px >= left && px <= right &&
py >= top && py <= bottom)
{
cout << "The point lies in the line\n";
}
else
cout << "The point is outside the line\n";
}
else
{
cout << "The point is outside the line\n";
}
system("pause");
return 0;
}
void Distance::set(double a1, double a2, double b1, double b2)
{
x1 = a1;
x2 = a2;
y1 = b1;
y2 = b2;
dist = calculate();
}
double Distance::calculate()
{
return (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));
}
void Distance::rotate(double alpha)
{
x1 = x1 * cos(alpha) - y1 * sin(alpha);
y1 = y1 * cos(alpha) + x1 * cos(alpha);
}
void Distance::polar(double x1, double y1, double& r, double& theta)
{
r = sqrt((pow(x1, 2)) + (pow(y1, 2)));
theta = atan(y1 / x1);
theta = (theta * 180) / 3.141592654;
}
| |