This is my notepad where i collect the useful snippets of OpenSCAD code that i use over and over. Some better curated than others, some formatted for clarity some for efficiency.
Thursday, May 25, 2017
Euclidean distance between a point and a line segment
Function to find the shortest distance between a point and a line segment
Usage:
echo(point_to_line( [150,50,0], [0,0,0], [100,0,0] ));
function point_to_line(p,a,b)=
let(
pa = p - a,
ba = b - a,
h = clamp( (pa*ba)/ (ba*ba)))
norm( pa - ba*h ) ;
function clamp(a, b = 0, c = 1) = min(max(a, b), c);
No comments:
Post a Comment