Write a program that will take two lines in a two dimensional space and print ou
ID: 3537869 • Letter: W
Question
Write a program that will take two lines in
a two dimensional space and print out
whether they
- Intersect
- Are parallel
- Are co-located- (they are lines are the same line, they occupy the same location in the coordinate system. Example: line 1 given by (1,1) and (2,2); line 2 given by (5,5) and (7,7) Remember the lines are infinite as in geometry, they are not line segments.)
- A line is represented by a pair of points
given as (x0,y0) and (x1,y1)
- Entering a pair of points as (0,0) means
exit
Decisions
- What data is needed to answer those
questions
- What are the special cases, if any?
- What is your C representation for a line?
- Notes
- These are lines in the Euclidian sense, not
line segments
-The coordinates are not restricted to be
integers
Hints
m = (y0 -y1)/(x0-x1)
Explanation / Answer
#include<stdio.h>
int main()
{
int x[4],y[4];
float slope1,slope2;
int factor;
printf( " enter line 1 point co-ordiantes ");
scanf("%d%d",&x[0],&y[0]);
printf( " enter line 1 point co-ordiantes ");
scanf("%d%d",&x[1],&y[1]);
printf( " enter line 2 point co-ordiantes ");
scanf("%d%d",&x[2],&y[2]);
printf( " enter line 2 point co-ordiantes ");
scanf("%d%d",&x[3],&y[3]);
slope1 = (float)(y[1]-y[0])/(float)(x[1]-x[0]);
slope2 = (float)(y[3]-y[2])/(float)(x[3]-x[2]);
if(slope1==slope2)
{
printf(" lines are parllel ");
}
if( (y[0]-slope1*x[0]) != (y[2]-slope2*x[2]))
{
printf(" lines will intersect " );
}
factor = y[0]/x[0];
if(y[1]==x[1]*factor)
{
printf(" points are co-located. " );
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.