old code

F

Filip Spasic

Guest
Hi, i found some 10 year old code for gesture recognition, and since its free i copied it. one error appears, and its something about a function called : line_distance. apparently this doesnt exist now. does anyone maybe know what this did, and if there is an equivalent function now. in this code it took 6 arguments (x1 y1 x2 y2 x3y3), and judging by the comments on the site it was posted on, the whole code worked very well
 

FrostyCat

Redemption Seeker
There has never been a built-in function called line_distance with 6 arguments. Look where you got the code from for a script named line_distance and copy that.
 
D

dannyjenn

Guest
This is just a wild guess, but maybe line_distance() is supposed to imagine a line running through points (x1,y1) and (x2,y2), and then figure out the distance between point (x3,y3) and the closest point on that line. If that's the case, what you're looking for is the distance between the third point and the point at which the first line intersects with whatever perpendicular line passes through the third point. So the script would be as follows (unless I got the math wrong... I haven't double-checked this):
Code:
var m = (y2-y1)/(x2/x1);
var b = y1 - (m*x1);
var _m = -1/m;
var _b = y3 - (_m*x3);
var x4, y4;
x4 = (_b-b)/(m-_m);
y4 = m*x4+b;
return point_distance(x3,y3,x4,y4);
 
Last edited by a moderator:
Top