0.2.0 • Published 8 years ago

distance-to-line-segment v0.2.0

Weekly downloads
4,777
License
MIT
Repository
github
Last release
8 years ago

distance-to-line-segment

Calculate closest distance between a point and a line segment

API

distance-to-line-segment

distanceToLineSegment(lx1, ly1, lx2, ly2, px, py) ⏏

Calculate the distance between a finite line segment and a point. Using distanceToLineSegment.squared can often be more efficient.

Kind: Exported function

ParamTypeDescription
lx1numberx-coordinate of line segment's first point
ly1numbery-coordinate of line segment's first point
lx2numberx-coordinate of the line segment's second point
ly2numbery-coordinate of the line segment's second point
pxnumberx coordinate of point
pynumbery coordinate of point

distanceToLineSegment.squaredWithPrecalc(lx1, ly1, ldx, ldy, lineLengthSquared, px, py)

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

ParamTypeDescription
lx1numberx-coordinate of line segment's first point
ly1numbery-coordinate of line segment's first point
ldxnumberx-coordinate of the line segment's second point minus lx1
ldynumbery-coordinate of the line segment's second point minus ly1
lineLengthSquarednumbermust be ldx*ldx + ldy*ldy. Remember, this precalculation is for efficiency when calling this multiple times for the same line segment.
pxnumberx coordinate of point
pynumbery coordinate of point

distanceToLineSegment.squared(lx1, ly1, lx2, ly2, px, py)

Calculate the square of the distance between a finite line segment and a point.

Kind: static method of distanceToLineSegment

ParamTypeDescription
lx1numberx-coordinate of line segment's first point
ly1numbery-coordinate of line segment's first point
lx2numberx-coordinate of the line segment's second point
ly2numbery-coordinate of the line segment's second point
pxnumberx coordinate of point
pynumbery coordinate of point

License

MIT