Uploaded by iit2019092

assignment

advertisement
Find the coordinates of the midpoint of the
line joining two points
Tanish Patel IIT2019092
Contact:​IIT2019092@iiita.ac.in
Semester 1 B.Tech., Information Technology,
Indian Institute of Information Technology, Allahabad
Abstract: In this paper, we have devised an
algorithm to find the coordinates of the
midpoint of the line joining two points in
two-dimensions.
Keywords: ​Midpoint, coordinates, real number
Introduction:
Geometrically, the midpoint is the middle point
of a line segment. It is equidistant from both
end points, and it is the centroid both of the
segment and of the endpoints. It bisects the
segment.
Mathematical Formula:
To find the coordinates of the midpoint of the
line joining two points (x1,y1) and (x2,y2) the
mathematical formula used is:
midpoint x=(​x1+x2)/2
midpoint y=​(y1+y2)/2
Algorithm:
input-​Enter the value of x1,y1,x2,y2
output-​The midpoint of the line joining
(x1,y1) and (x2,y2).
Step1:Enter the value of x1
Step2:Enter the value of y1
Step 3: Enter the value of x2
Step 4: Enter the value of y2
Step5: Calculate midpoint x=(x1+x2)/2 and
midpoint y=(y1+y2)/2
Code:
int main()
{
float x1,x2,y1,y2,midpoint x, midpointy;
printf("Enter the x coordinate of endpoint
1:");
scanf("%f", &x1);
printf("Enter the y coordinate of endpoint
1:");
scanf("%f", &y1);
printf("Enter the x coordinate of endpoint
2:");
scanf("%f", &x2);
printf("Enter the y coordinate of endpoint
2:");
scanf("%f", &y2);
printf("The endpoints of line are :
(%0.2f,%0.2f) and (%0.2f,%0.2f)", x1,y1,x2,y2);
midpoint x=(x1+x2)/2;
midpointy=(y1+y2)/2;
printf("midpoint: (%0.2f,%0.2f)", midpoint
x,midpoint y);
getch();
return 0;
}
Time Analysis(Calculated on codeblocks):
x1
y1
x2
y2
(x1
+x2
)/2
(y1
+y2
)/2
Ti
me(
s)
1
2
3
4
2
3
0.02
36
38
40
42
340
4
0.08
CONCLUSION
The algorithm and the code are written and
working well for small and large inputs.
REFERENCES
[1] Wikipedia
[2]www.codingconnect.net
Download