Back to Cosmos

Distance Between two Points

code/computational_geometry/src/distance_between_points/README.md

latest1.1 KB
Original Source

Distance Between two Points

Calculating the distance between two points is done by creating a right-angled triangle using the two points. The line between the two points is the hypotenuse (the longest side, opposite to the 90° angle). Lines drawn along the X and Y-axes complete the other sides of the triangle, whose lengths can be found by finding the change in X and change in Y between the two points. We then use the Pythagorean theorem to find the length of the hypotenuse, which is the distance between the two points. If you didn't quite get that, the diagram below should help:

Image credit: By Jim.belk, public domain, https://commons.wikimedia.org/wiki/File:Distance_Formula.svg

Thus, using the Pythagorean theorem, the equation for the length of d would be:

d = sqrt((x2 - x1)^2 + (y2 - y1)^2)

Sources and more info:


<p align="center"> A massive collaborative effort by <a href="https://github.com/OpenGenus/cosmos">OpenGenus Foundation</a> </p>