Last active
September 13, 2019 23:20
-
-
Save katsaii/c4de749b509a729d9e54cdf80bcd5670 to your computer and use it in GitHub Desktop.
Finds the distance between a point and a line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// @desc Finds the minimum distance between a point and a 2D line. | |
/// @param x {Real} The X position of the point. | |
/// @param y {Real} The Y position of the point. | |
/// @param u1 {Real} The first X position of the line. | |
/// @param w1 {Real} The first Y position of the line. | |
/// @param u2 {Real} The second X position of the line. | |
/// @param w2 {Real} The second Y position of the line. | |
var qx = argument0; | |
var qy = argument1; | |
var px = argument2; | |
var py = argument3; | |
var ux = argument4 - px; | |
var uy = argument5 - py; | |
var nx = uy; | |
var ny = -ux; | |
return (dot_product(nx, ny, px, py) - dot_product(nx, ny, qx, qy)) / | |
dot_product(nx, ny, nx, ny); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment