// l1 - line start, l2 - line end, x - point // perp() returns vec2(y,-x) -- a perpendicular vector // dot() returns v1.x * v2.x + v1.y * v2.y -- it's the 2D vector dot product // normalized() returns vec2(x/length,y/length), where length = sqrt(x*x+y*y) ln = ( l2 - l1 ).perp().normalized(); distance = dot( ln, x ) - dot( ln, l1 ); // positive distance means that point's on the left side, negative - on the right Note: this assumes screen-space axis directions, not the mathematical (Y+ points down, not up).
"ln" is the line normal - a normalized vector that points away from line and is perpendicular to it. The "perp" function returns the vector, turned 90 degrees counter-clockwise.
Both "dot" functions return projections of points on an axis that is defined by the line normal. "distance" is a subtraction of those projections, which makes it a distance from an infinite version of the line defined by the two points "p1" and "p2".
Now it wasn't clearly defined whether you need a finite or an infinite line (and if this, what kind of infinite). I initially assumed infinite so... this code works with all kinds of "infinite" - you really need one point and the line normal to use this method.