Clear Filters
Clear Filters

직선과 점사이의 거리

16 views (last 30 days)
JunYoung Lee
JunYoung Lee on 6 Jul 2022
Edited: Divit on 8 Sep 2023
2D 평면에서 두점을 알고있고 q1, q2
한점을 알고있을때 p
d = (det([q2-q1;p-q1]))/norm(q2-q1)
이 코드를 쓰면 직선과 (q2와 q1을 지나는 직선) 과 점(p)사이의 거리가 결과적으로 나오는데
왜 그렇게 나오는지 코드해석이 안됩니다... 의미가 뭘까요 저코드에? 외적인가요?

Answers (1)

Divit
Divit on 8 Sep 2023
Edited: Divit on 8 Sep 2023
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.
det([q2 - q1; p - q1])
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:

Categories

Find more on 기초 수학 in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!