;; | ---------------------------------------------------------------------------- ;; | GE_PerpPt ;; | ---------------------------------------------------------------------------- ;; | Function : Locate the perpendicular drop point from a point pp to any line ;; | segment defined by two other points pt1 and pt2 ;; | Argument : [pp] - Point to drop from ;; | [p1] - First Point of line segment ;; | [p2] - Second Point of line segment ;; | Return : The drop point on the line segment ;; | e-mail : rakesh.rao@4d-technologies.com ;; | Web : www.4d-technologies.com ;; | ---------------------------------------------------------------------------- (defun GE_PerpPt( pp p1 p2 / x y x1 x2 x3 x4 y1 y2 y3 y4 m p4) (setq x (car pp) y (cadr pp) x1 (car p1) y1 (cadr p1) x2 (car p2) y2 (cadr p2) ) (cond ((equal x1 x2 0.0000001) ; Vertical line (setq x4 x1 y4 y p4 (list x4 y4 0.0) ) ) ((equal y1 y2 0.0000001) ; Horizontal line (setq x4 x y4 y1 p4 (list x4 y4 0.0) ) ) (T (setq m (/ (- y2 y1) (- x2 x1)) ; gradient p1- p2 x4 (/ (+ (/ x m) (+ y (- (* m x1) y1))) (+ (/ 1 m) m)) y4 (+ y1 (* m (- x4 x1))) p4 (list x4 y4 0.0) ) ) ) p4 )