Calculate closest distance between a point and a line segment
Calculate the distance between a finite line segment and a point. Using distanceToLineSegment.squared can often be more efficient.
Kind: Exported function
Param | Type | Description |
---|---|---|
lx1 | number |
x-coordinate of line segment's first point |
ly1 | number |
y-coordinate of line segment's first point |
lx2 | number |
x-coordinate of the line segment's second point |
ly2 | number |
y-coordinate of the line segment's second point |
px | number |
x coordinate of point |
py | number |
y coordinate of point |
Calculate the square of the distance between a finite line segment and a point. This version takes somewhat less convenient parameters than distanceToLineSegment.squared, but is more efficient if you are calling it multiple times for the same line segment, since you pass in some easily pre-calculated values for the segment.
Kind: static method of distanceToLineSegment
Param | Type | Description |
---|---|---|
lx1 | number |
x-coordinate of line segment's first point |
ly1 | number |
y-coordinate of line segment's first point |
ldx | number |
x-coordinate of the line segment's second point minus lx1 |
ldy | number |
y-coordinate of the line segment's second point minus ly1 |
lineLengthSquared | number |
must be ldx*ldx + ldy*ldy. Remember, this precalculation is for efficiency when calling this multiple times for the same line segment. |
px | number |
x coordinate of point |
py | number |
y coordinate of point |
Calculate the square of the distance between a finite line segment and a point.
Kind: static method of distanceToLineSegment
Param | Type | Description |
---|---|---|
lx1 | number |
x-coordinate of line segment's first point |
ly1 | number |
y-coordinate of line segment's first point |
lx2 | number |
x-coordinate of the line segment's second point |
ly2 | number |
y-coordinate of the line segment's second point |
px | number |
x coordinate of point |
py | number |
y coordinate of point |
MIT