File Exchange

image thumbnail

Perpendiculars to line segments

version 1.0.0 (65.3 KB) by Peter Seibold
Calculate the foot points fP of perpendiculars and the minimal distances D from a point P to a 2D or 3D line segment.

1 Download

Updated 25 Dec 2020

View License

FEATURES.
• 2D or 3D line segments
• Output of perpendicular foot coordinates
• Output of minimal distances to line segments
• Indicator for perpendicular foot position

INPUT:
P : Reference point, P=[xr,xr] or P=[xr,yr,zr]
sP: Starting points, sP=[Xs,Ys] or sP=[Xs,Ys,Zs]
eP: Ending points, eP=[Xe,Ye] or eP=[Xe,Ye,Ze]

OUTPUT:
fP: Foot points X,Y where the perpendiculars hits the line segments
If perpendicular is outside of line segment, take closest data point.
D : Distances from P to line segments
outside: Indicator for pependicular position
outside 0: Perpendicular inside line segment
outside 1: Perpendicular outside start of line segment
outside 2: Perpendicular outside end of line segment

EXAMPLE (2D):
P=[0,0];sP=[-4,1;-4,2;-1,2];eP=[-2,1;-2,4;1,2];
[fP,D,outside]=Perpendicular2Line(P,sP,eP)

See also the demonstration file Examples.m

The basic principle is from Ken Eaton, https://stackoverflow.com/questions/43991659/how-do-i-compute-the-shortest-distance-from-a-point-to-line-segments

Cite As

Peter Seibold (2020). Perpendiculars to line segments, MATLAB Central File Exchange. Retrieved December 25, 2020.

Comments and Ratings (0)

MATLAB Release Compatibility
Created with R2016a
Compatible with R2020a and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Perpendicular2Line_201225