Determine whether lines are intersecting or
not.
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<graphics.h>
void main()
{
clrscr();
int x1,x2,y1,y2,x3,x4,y3,y4;
int gd=DETECT,gm;
initgraph(&gd,&gm,"d:\\turboc3");
cout<<"Enter the co-ordinates of 1st
line:";
cout<<"\n\nCo-ordinates of Initial
points:";
cout<<"\nx-axis:";
cin>>x1;
cout<<"y-axis:";
cin>>y1;
cout<<"Enter the co-ordinates of End
points:";
cout<<"\nx-axis:";
cin>>x2;
cout<<"y-axis:";
cin>>y2;
cout<<"\n\nEnter the co-ordinates of 2nd
line:";
cout<<"\n\nCo-ordinates of Initial
points:";
cout<<"\nx-axis:";
cin>>x3;
cout<<"y-axis:";
cin>>y3;
cout<<"Enter the co-ordinates of End
points:";
cout<<"\nx-axis:";
cin>>x4;
cout<<"y-axis:";
cin>>y4;
line(x1,y1,x2,y2);
line(x3,y3,x4,y4);
if((x3<x1)&&(x4>x2)&&(y3<y1)&&(y4>y2))
{
cout<<"Lines are intersecting:" ;
}
else
{
cout<<"lines are not intersecting:";
}
getch();
}
Output:
Case 1: lines
are Intersecting:
Enter the co-ordinates of 1st line:
Co-ordinates of Initial points:
x-axis:100
y-axis:150
Enter the co-ordinates of End points:
x-axis:600
y-axis:175
Enter the co-ordinates of 2nd line:
Co-ordinates of Initial points:
x-axis:50
y-axis:125
Enter the co-ordinates of End points:
x-axis:700
y-axis:200
2: lines are
not Intersecting:
Enter the co-ordinates of 1st line:
Co-ordinates of Initial points:
x-axis:100
y-axis:200
Enter the co-ordinates of End points:
x-axis:200
y-axis:250
Enter the co-ordinates of 2nd line:
Co-ordinates of Initial points:
x-axis:120
y-axis:230
Enter the co-ordinates of End points:
x-axis:220
y-axis:280
No comments:
Post a Comment