Linear algebra, How to calculate the distance from one point to a line

handsometan

HandsomeTan

Posted on November 19, 2024

Linear algebra, How to calculate the distance from one point to a line

For this question, we usually think about a formula learned in junior high school:
Image description
but there are some issues where we find it difficult to define the values of A, B, and C, therefore we have a more convenient formula as follows:
float length = dot(ab, ap) / dot(ab, ab) // caculate distance p point to ab line which can generate the projected length of ap line on ab line. This is the projection scale factor. Then multiply ap vector by this length to obtain an ad vector, a line segment on ap. At last, we use lenght() function to compute the distance of pd line segment that is the distance p point to the ab straight line.

💖 💪 🙅 🚩
handsometan
HandsomeTan

Posted on November 19, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related