Write a graphics program that prompts
the user to enter graphics objects using the mouse or/and the keyboard.
Draw these graphics objectsq make calculations and print out the results .
Your program must be tested with an example given after every task.
13. Enter a triangle and find a point placed inside it
what i do:
Code:
#include <cmath>
using namespace std;
#include "ccc_win.h"
int ccc_win_main()
{
//imput 3 points
Point a=cwin.get_mouse("Click on the first point:");
cwin << a;
Point b=cwin.get_mouse("Click on the second point:");
cwin << b;
Point c=cwin.get_mouse("Click on the third point:");
cwin << c;
// lines
Line l1(a,b);
Line l2(b,c);
Line l3(c,a);
// geting coordinates of the points
double x1=a.get_x();
double y1=a.get_y();
double x2=b.get_x();
double y2=b.get_y();
double x3=c.get_x();
double y3=c.get_y();
// determine the length of the external sides
double dist1=sqrt(sqrt(x1-x2) + sqrt(y1-y2));
double dist2=sqrt(sqrt(x2-x3) + sqrt(y2-y3));
double dist3=sqrt(sqrt(x3-x1) + sqrt(y3-y1));
//result triangle
cwin << a << b << c << l1 << l2 << l3;
Point d=cwin.get_mouse("Click on the trinagle:");
double x4=d.get_x();
double y4=d.get_y();
Line l4(a,d);
Line l5(b,d);
Line l6(c,d);
// determine the length of the internal lines
double dist4=sqrt(sqrt(x1-x4) + sqrt(y1-y4));
double dist5=sqrt(sqrt(x2-x4) + sqrt(y2-y4));
double dist6=sqrt(sqrt(x3-x4) + sqrt(y3-y4));
// limits the point in the range of the triangle
double s=sqrt((dist1+dist2-dist3)*(dist1-dist2+dist3)*(-dist1+dist2+dist3)*(dist1+dist2+dist3))*0.25;
double s1=sqrt((dist1+dist5-dist4)*(dist1-dist5+dist4)*(-dist1+dist5+dist4)*(dist1+dist5+dist4))*0.25;
double s2=sqrt((dist2+dist6-dist5)*(dist2-dist6+dist5)*(-dist2+dist6+dist5)*(dist2+dist6+dist5))*0.25;
double s3=sqrt((dist3+dist4-dist6)*(dist3-dist4+dist6)*(-dist3+dist4+dist6)*(dist3+dist4+dist6))*0.25;
if (fabs(s-(s1+s2+s3))<1e-6)
cwin << d;
else
cwin << Message (Point(0,0),"the point must be inside the triangle!");
return 0;
}