12 lines
298 B
GLSL
12 lines
298 B
GLSL
float closestPointOnLineParam (vec2 a, vec2 b, vec2 p) {
|
|
return dot(p - a,b-a) / dot(b-a,b-a);
|
|
}
|
|
vec2 closestPointOnSeg (vec2 a,vec2 b, vec2 p) {
|
|
float x = closestPointOnLineParam(a,b,p);
|
|
if (x < 0) {
|
|
return a;
|
|
} else{ if (x > 1) { return b; }
|
|
{ return a + (x * (b- a));}
|
|
}
|
|
}
|