MCPcopy Create free account
hub / github.com/NikLever/ThreeJS-PathEditor / calcDistancePointToLine

Method calcDistancePointToLine

geometry.js:15–20  ·  view source on GitHub ↗
(line1, line2, pnt)

Source from the content-addressed store, hash-verified

13
14 //Returns float, the shortest distance to the (infinite) line.
15 static calcDistancePointToLine(line1, line2, pnt) {
16 const L2 = ( ((line2.x - line1.x) * (line2.x - line1.x)) + ((line2.y - line1.y) * (line2.y - line1.y)) );
17 if(L2 == 0) return false;
18 const s = (((line1.y - pnt.y) * (line2.x - line1.x)) - ((line1.x - pnt.x) * (line2.y - line1.y))) / L2;
19 return Math.abs(s) * Math.sqrt(L2);
20 }
21
22 //Returns bool, whether the projected point is actually inside the (finite) line segment.
23 static calcIsInsideLineSegment(line1, line2, pnt) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected