;;; io.lsp ;;; a program that determines if a point is inside or outside a perimeter ;;; copyright 2009 by charles robbins ;;; charles robbins provides this code for your use. Use the code to your benefit ;;; and at your own risk. Charles Robbins does not guarantee that the code is error ;;; free in your application. (alert "Inside / Outside.lsp - copyright 2007 by charles robbins. type io to start") ;;; start the program (defun c:io (/) ;;; drawing setup (setq osm (getvar "osmode")) ; gets osnap settings and assigns to osm (setvar "osmode" 32) ; osnap setting set to intersection only ;;; setup layers (command "layer" "n" "tracing_the_polygon" "c" "red" "tracing_the_polygon" "") (command "layer" "s" "tracing_the_polygon" "") ;;; Number if shapes (setq globalanswer "o") (setq q4 (getint "\nHow many shapes to outline? ")) (setq globalcounter 0) (while (< globalcounter q4) ;;; collect the points on the perimeter (setq counter 0) (setq pointlist nil) (setq q1 "y") (while (= q1 "y") (setq pn (getpoint "\nPick perimeter point")) (if (= counter 0)(setq p0 pn)) (if (= counter 1)(command "pline" p0 pn "")) (if (> counter 1)(progn (command "pline" "" pn "") (setq pc pn) ) ) (setq pointlist (cons pn pointlist)) (if (and (> counter 0)(= (car p0)(car pn))(= (cadr p0)(cadr pn))(= (caddr p0)(caddr pn)))(setq q1 "n")) (setq counter (1+ counter)) ) ;;; collect the check point (if (= globalcounter 0)(setq pt (getpoint "\nPick the inside or outside check point"))) ;;; calculate the angle of the border line (setq counter 0) (setq qty (length pointlist)) (setq pointlist (reverse pointlist)) (while (< counter (1- qty)) (setq p1 (nth counter pointlist)) (if (= counter (1- qty))(setq p2 (nth 0 pointlist))(setq p2 (nth (1+ counter) pointlist))) (setq angle1 (angle p1 p2)) (setq angle2 (angle p1 pt)) (setq answer (- angle2 angle1)) (if (< answer 0)(setq q3 "o")) (if (and (>= answer 0)(<= answer pi))(setq q3 "i")) (if (> answer pi)(setq q3 "o")) (if (and (>= angle2 0)(< angle2 (/ pi 2.0))(> angle1 (* 1.5 pi))(<= angle1 (* 2.0 pi)))(setq q3 "i")) (if (and (>= angle1 0)(< angle1 (/ pi 2.0))(> angle2 (* 1.5 pi))(<= angle2 (* 2.0 pi)))(setq q3 "o")) (if (= q3 "o")(setq counter qty)) (setq counter (1+ counter)) ) (if (= q3 "i")(setq globalanswer "i" globalcounter q4 ) ) (setq globalcounter (1+ globalcounter)) ) ;;; alert message (if (= globalanswer "o")(alert "The point is outside the perimeter")) (if (= globalanswer "i")(alert "The point is inside the perimeter")) (setq ss1 (ssget "x" '((8 . "tracing_the_polygon")))) (command "erase" ss1 "") ;;; end of program (setvar "osmode" osm) (gc) (princ) )