Where a and b are not both zero. The program should display a menu with the foll
ID: 3592212 • Letter: W
Question
Where a and b are not both zero.
The program should display a menu with the following options:
a) Enter points
b) Compute the distance
c) Display the line equation
d) Find the closest point to the line in c
e) Exit
The program will finalize ONLY when option e) is chosen.
Given the following list of point coordinates and label: Point Label X-Coordinate Y-Coordinate 50.2 45.7 76.7 12 75.8 48 99.1 14 48 25 23 36 123 34.6 Table 1: Point Information The information is given as three arrays: i) A char array named point_label, for column 1 in Table 1 ii A double array named x_coord, for column 2 in Table 1 iii)A double array named y coord, for column 3 in Table 1 The table information can be hard coded Given two points, entered using the labels (i.e. A and B), the program will compute: a) The distance between the two points b) The equation of the line crossing these points in the form: y mx+k c) Among the other points, the closest perpendicular point to the line described by the two points given(i.e. if A and B are chosen, then look for which of C,D,F,G are the closest) The distance from a point Po(Xo.yo) to a line in the form ax+by+c-0, is defined as: laxo byo +cl distance(ax + by + c = 0, P0)- 2Explanation / Answer
#include <stdio.h>
#include<math.h>
int main()
{
// I will denote points by 2D array
double points[7][2]; ///points[1][] is A point
///points[2][] is B point So on.
printf("Enter point A to I "); // like 1 2
for(int i=0;i<7;i++) // 5 6
{ printf("%d ",i);
double x,y;
scanf("%lf %lf", &x, &y);
points[i][0]=x;
points[i][1]=y;
//printf("/n point A and B are %lf %lf ",points[0][0],points[0][1]);
}
printf(" point A and B are %lf %lf and %lf %lf ",points[0][0],points[0][1],points[1][0],points[1][1]);
float distance=((points[0][0]-points[1][0])*(points[0][0]-points[1][0])+(points[0][1]-points[1][1])*(points[0][1]-points[1][1]));
distance=sqrt(distance);
printf("Distance between A and B is = %lf ",distance);
float m=(points[1][1]-points[0][1])/(points[1][0]-points[0][0]);
float c=points[1][1]-m*points[1][0];
printf("equation of the line which pass through A and B is Y = %lf X + %lf /n ",m ,c );
char clsest_point;
int point;
float cosest_dis=0;
for(int i=2;i<7;i++)
{
distance=abs(points[i][1]-m*points[i][0]-c)/(1+m*m);
if(cosest_dis>distance)
{
cosest_dis=distance;
point=i;
}
}
printf("cosest_dis %lf",98+point,cosest_dis);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.