Abdul Kahar
Abdul Kahar

Reputation: 37

Detect if a 3D point with radius is passed by a line of two 3D points? (C#)

I have three 3D points, just say p1, p2, and p3. I am able to make a line that connects p1 and p2. Then, the p3 will be in between the p1 and p2 but not collinear. I want to know if the p3 is close to the line. How to check it? enter image description here

Upvotes: 1

Views: 172

Answers (1)

Fattie
Fattie

Reputation: 12287

2D

You're just finding the height of a triangle. Fortunately you can instantly google the formula:

https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line

enter image description here

3D

Again, the formula is widely available

https://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html

enter image description here

Generally ..

Here's the bible that all game programmers have to memorize by heart!

http://amazon.com/Mathematics-Programming-Computer-Graphics-Third/dp/1435458869

enter image description here

Upvotes: 0

Related Questions