Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Perpendicular from point to segment in 2d

procedure PerpendicularPntToSegment(x1, y1, x2, y2, Px, Py: Double; var Nx, Ny: Double); var R: Double; Dx: Double; Dy: Double; begin Dx := x2 - x1; Dy := y2 - y1; R := ((Px - x1) * Dx + (Py - y1) * Dy) / Sqr(Dx * Dx + Dy * Dy); Nx := x1 + R * Dx; Ny := y1 + R * Dy; end; (* End PerpendicularPntSegment *) // trouve la perpendiculaire entre un point et une droite (2D)