video thumbnail 5:30
Gamedev Maths: distance from point to line

2017-06-13

[public] 39.4K views, 1.23K likes, 24.0 dislikes audio only

In this video we determine an equation for the shortest distance between some point C, and the line passing through points A and B.

The equation is: dst = abs((C.x-A.x) * (-B.y+A.y) + (C.y-A.y) * (B.x-A.x)) / sqrt((-B.y+A.y)^2 + (B.x-A.x)^2)

We also see how this equation can be modified to determine if two points lie on the same side of a line.

C# code for the equations can be found here: https://github.com/SebLague/Gamedev-Maths/blob/master/DistanceToLine.cs

If you'd like to support these videos, you can do so with a recurring pledge on Patreon, or a one-time donation through PayPal. https://www.patreon.com/SebastianLague

https://www.paypal.me/SebastianLague


Calculate a Vector That Is Perpendicular to Ab
/youtube/video/KHuI9bXZS74?t=33.459999
The Dot Product of these Two Vectors
/youtube/video/KHuI9bXZS74?t=156.03
Calculate the Length of P
/youtube/video/KHuI9bXZS74?t=248.59