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
|
#include <cmath>
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
//prototypes
double randomDouble(const double& from, const double& to);
double lineSegLen(const float& lp0x, const float& lp0y, const float& lp1x, const float& lp1y);
bool lineInCircle(const float& lp0x, const float& lp0y, const float& lp1x, const float& lp1y, const float& cmpx, const float& cmpy, const float& radius);
int main()
{
//variables being used
float cmpx;
float cmpy;
float lp0x;
float lp0y;
float lp1x;
float lp1y;
float radius;
srand(time(0));
//assign variable
cmpx = randomDouble(-99.9, 99.9);
cmpy = randomDouble(-99.9, 99.9);
lp0x = randomDouble(-99.9, 99.9);
lp0y = randomDouble(-99.9, 99.9);
lp1x = randomDouble(-99.9, 99.9);
lp1y = randomDouble(-99.9, 99.9);
radius = randomDouble(0.1, 99.9);
//output line segment data
cout << right;
cout << "Line segment's 1st x coordinate: " << setw(5) << lp0x << endl;
cout << "Line segment's 1st y coordinate: " << setw(5) << lp0y << endl;
cout << "Line segment's 2nd x coordinate: " << setw(5) << lp1x << endl;
cout << "Line segment's 2nd y coordinate: " << setw(5) << lp1y << endl;
//output midpoint data
cout << "\nCircle's Midpoint x coordinate: " << cmpx << endl;
cout << "Circle's Midpoint y coordinate: " << cmpy << endl;
//output radius data
cout << "\nCircle's Radius: " << radius << endl;
//output bool statement
if (lineInCircle(lp0x, lp0y, lp1x, lp1y, cmpx, cmpy, radius))
cout << "\nThe line segment is in the circle!" << endl;
else
cout<< "\nThe line segment is not in the circle!" << endl;
return EXIT_SUCCESS;
}
//define randomDouble prototype
double randomDouble(const double& from, const double& to)
{
return rand() % static_cast<int>((to - from -.1) * 10.0) / 10.0 + from;
}
//define lineSegLen prototype
double lineSegLen(const float& lp0x, const float& lp0y, const float& lp1x, const float& lp1y)
{
return sqrt(pow(lp0x - lp1x, 2.0) + pow(lp0y - lp1y, 2.0));
}
//define lineInCircle prototype
bool lineInCircle(const float& lp0x, const float& lp0y, const float& lp1x, const float& lp1y, const float& cmpx, const float& cmpy, const float& radius)
{
return lineSegLen(lp0x, lp0y, cmpx, cmpy) <= radius && lineSegLen(lp1x, lp1y, cmpx, cmpy) <= radius;
}
|