Hi JunYoung Lee,
I’ll break down the explanation in points for easy understanding.
1. Define Vectors:
- q1 and q2 represent the coordinates of the two known points that define the line.
- p represents the coordinates of the point for which you want to find the distance to the line.
- Note that vector quantities are represented using bold alphabets.
2. Calculate Vector Difference:
- q2 - q1 represents a vector that points from q1 to q2. This vector defines the direction and length of the line segment between q1 and q2.
- p - q1 represents a vector that points from q1 to p. This vector defines the direction and length from q1 to the point p.
3. Calculate Determinant:
Compute the determinant of the 2x2 matrix formed by these vectors.
The determinant essentially measures the "signed" area of the parallelogram formed by these vectors.
4. Normalize Vector:
Calculate the norm (magnitude) of q2 - q1, which represents the length of the line segment between q1 and q2.
5. Final Distance:
Finally, divide the determinant by the length of the line segment q2 - q1.
d = (det([q2 - q1; p - q1])) / norm(q2 - q1)
This formula gives you the perpendicular distance from point p to the line passing through q1 and q2. The result will be positive if the point p is on one side of the line, negative if it's on the opposite side, and zero if it lies on the line itself.
To know more you can refer to the following documentation links: