Skip to content

JavaScript module to calculate the closest distance between a point and a line segment

Notifications You must be signed in to change notification settings

scottglz/distance-to-line-segment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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

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

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

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

License

MIT

About

JavaScript module to calculate the closest distance between a point and a line segment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published