;;--------------------- aboveline --------------------------------------- ;; Purpose: given 2D points p1,p2,p3 ;; determines if p3 lies above or below the line defined ;; by p1,p2 ;; Needs: two points p1,p2 to determine the line ;; point p3 to test ;; fuzz to determine required proximity to line ;; Returns: 1 if p3 is above the line ;; 0 if on the line ;; -1 if below the line ;; nil if the line is vertical or p1,p2 are coincident ;;---------------------------------------------------------------- (defun aboveline (p1 p2 p3 fuzz / m ret y3 yprime) (if (= (car p1) (car p2)) (setq ret nil) (progn (setq m (/ (- (cadr p2) (cadr p1)) (- (car p2) (car p1))) yprime (+ (cadr p1) (* m (- (car p3) (car p1)))) y3 (cadr p3) ) (cond ((equal y3 yprime fuzz) (setq ret 0)) ((> y3 yprime) (setq ret 1)) ((< y3 yprime) (setq ret -1)) );cond );progn );if ret );aboveline ;;--------------------- rightofline --------------------------------------- ;; Purpose: given 2D points p1,p2,p3 ;; determines if p3 lies right or left of the line defined ;; by p1,p2 ;; Needs: two points p1,p2 to determine the line ;; point p3 to test ;; fuzz to determine required proximity to line ;; Returns: 1 if p3 is right of the line ;; 0 if on the line ;; -1 if left of the line ;; nil if the line is horizontal or p1,p2 are coincident ;;---------------------------------------------------------------- (defun rightofline (p1 p2 p3 fuzz / m ret x3 xprime) (if (= (car p1) (car p2)) (setq ret nil) (progn (setq m (/ (- (cadr p2) (cadr p1)) (- (car p2) (car p1))) xprime (+ (car p1) (/ (- (cadr p3) (cadr p1)) m)) x3 (car p3) ) (cond ((equal x3 xprime fuzz) (setq ret 0)) ((> x3 xprime) (setq ret 1)) ((< x3 xprime) (setq ret -1)) );cond );progn );if ret );rightofline