closestPointToPointParameter method
point
- the point for which to return a point parameter.
clampToLine
- Whether to clamp the result to the range [0, 1]
.
Returns a point parameter based on the closest point as projected on the
line segment. If clampToLine
is true, then the returned
value will be between 0
and 1
.
Implementation
double closestPointToPointParameter(Vector3 point, bool clampToLine) {
_startP.sub2(point, start);
_startEnd.sub2(end, start);
final startEnd2 = _startEnd.dot(_startEnd);
final startEndStartP = _startEnd.dot(_startP);
double t = startEndStartP / startEnd2;
if (clampToLine) {
t = MathUtils.clamp(t, 0, 1);
}
return t;
}