Enter the endpoints of the first line segment: 2.0 2.0 0 Enter the endpoints of
ID: 3567373 • Letter: E
Question
Enter the endpoints of the first line segment: 2.0 2.0 0 Enter the endpoints of the second line segment: 0 2.0 2.0 The intersecting point is: (1, 1) Enter the endpoints of the first line segment: 2.0 2.0 0 0 Enter the endpoints of the second line segment: 3 3 1 1 The two lines do not cross **6.35 (Geometry: intersection) Suppose two line segments intersect. The two end-points for the first line segment are (xl, yl) and (x2, y2) and for the second line segment are (x3, y3) and (x4, y5). Write the following function that returns the intersecting point if the two lines intersect: ideoNote V Ind ntersecttng point void intersectPoint(double xl, double yl, double x2, double y2, double x3 , double y3, double x4, double y4, double& x, double& y, bool& isIntersecting) Write a program that prompts the user to enter these four endpoints and displays the intersecting point. (Hint: Use the function for solving 2 X 2 linear equations in Programming Exercise 6.33.)Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int i,j,k,l,n;
double x1,y1,x2,y2,x3,y3,x4,y4;
cout << " Enter the end points of the first line segment :" ;
cin >> x1 >> y1 >> x2 >> y2;
cout << " Enter the end points of the second line segment :" ;
cin >> x3 >> y3 >> x4 >> y4;
double m1,m2;
m1=(y2-y1)/(x2-x1);
m2=(y4-y3)/(x4-x3);
if((m1>=m2-0.0000001)&&(m1<=m2+0.0000001))
cout << "The two lines do not intersect " << endl;
else
{
double x,y;
x=(((x2*y1-x1*y2)/(x2-x1))-((x4*y3-x3*y4)/(x4-x3)))/(m2-m1);
y=m1*x+((x2*y1-x1*y2)/(x2-x1));
cout << "The intersecing points are " << x <<" " << y << endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.