PDA

View Full Version : Using the inters function in Lisp


Lions60
2007-07-06, 09:29 PM
I am having trouble finding the intersection between two lines. I have searched the help files and also searched here on Augi and couldn't find much. I have all four points needed to find the intersection. In the code below at the bottom where i am finding the interesection there is a commented line of code. This line of code returns the correct intersection point but gives me an error and terminates the program. The uncommented line of code (the on ewithout the ;; in front of it) works without any errors, but does not return the correct intersection point between the two lines. Any help would be appreciated.

An Economizer module is just a rectangle of any width and height. I have been using one with an x dimension of 80 and a y dimension of 120.

(defun C:Econo ()
(setq old_osnap(getvar "osmode"))
;;Getting Upper right Hand corner of Economizer module
(setq pnt1 (getpoint "\nSelect the upper right hand corner of the Economizer Section: \n"))
;;Getting Lower Left Hand corner of Economizer module
(setq pnt2 (getcorner pnt1 "\nSelect the lower left hand corner of the Economizer Section: \n"))
(setvar "osmode" 0)
;;Getting Angle the economizer will be placed at
(setq ang (getreal "Enter angle of economizer <30 or 45>:\n"))
;;Getting Center point of Economizer module.
(setq cpnt (list(/(+(car pnt1)(car pnt2))2)(/(+(cadr pnt1)(cadr pnt2))2)))
;;Second point from center of module at the angle specified by the user.
(setq cpnt1 (polar cpnt (dtr ang)3))
;;Getting the boudary of the economizer module
(setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
(setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))

;;Finding the intersection of where the center point would cross the first point selected.
;;(setq inters1 (inters (car cpnt) (cadr cpnt) (car pnt1) (cadr pnt1)))
(setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
(setvar "osmode" old_osnap)
)

Lions60
2007-07-06, 09:49 PM
I also tried using the code below and it works without errors but does not return the correct intersection between a line at either a 45 degree angle or a 30 degree angle from the center of the rectangle.


(setq inters1 (inters (list(car cpnt) (cadr cpnt)) (list(car cpnt1) (cadr cpnt1)) (list(car pnt1) (cadr pnt1)) (list(car bndry2) (cadr bndry2))nil))

pferreira
2007-07-07, 12:09 AM
Hello i have been trying to see what was wrong but i couldn't´t find anything wrong, the only thing that could be missing was the print to the command line of the coordinates.
Look here!

(defun C:Econo ()
(setq old_osnap(getvar "osmode"))
;;Getting Upper right Hand corner of Economizer module
(setq pnt1 (getpoint "nSelect the upper right hand corner of the Economizer Section: n"))
;;Getting Lower Left Hand corner of Economizer module
(setq pnt2 (getcorner pnt1 "nSelect the lower left hand corner of the Economizer Section: n"))
(setvar "osmode" 0)
;;Getting Angle the economizer will be placed at
(setq ang (getreal "Enter angle of economizer <30 or 45>:n"))
;;Getting Center point of Economizer module.
(setq cpnt (list(/(+(car pnt1)(car pnt2))2)(/(+(cadr pnt1)(cadr pnt2))2)))
;;Second point from center of module at the angle specified by the user.
(setq cpnt1 (polar cpnt (dtr ang) 3))
;;Getting the boudary of the economizer module
(setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
(setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))

;;Finding the intersection of where the center point would cross the first point selected.
;;(setq inters1 (inters (car cpnt) (cadr cpnt) (car pnt1) (cadr pnt1)))
(setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
(vl-cmdf "pline" cpnt cpnt1 "")
(vl-cmdf "pline" pnt1 bndry2 "")
(princ inters1)
(setvar "osmode" old_osnap)
(princ);;exit
)

(defun dtr (numberOfDegrees)
(* pi (/ numberOfDegrees 180.0))
)


Best Regards

peter
2007-07-09, 03:27 AM
The intersectwith method of a line can also get the intersection of two lines objects.

(defun C:INTX (/ objLine1 objLine2)
(setq objLine1 (vlax-ename->vla-object (car (entsel "\nSelect first line: ")))
objLine2 (vlax-ename->vla-object (car (entsel "\nSelect second line: ")))
)
(vlax-invoke objLine1 "intersectwith" objLine2 0)
)

Adesu
2007-07-09, 03:46 AM
Hi Lions60,
Test this code

(defun dtr (a)
(* pi (/ a 180.0))
)

(defun C:Econo (/ ang bndry1 bndry2 coord cpnt cpnt1 el1 el2 old_osnap pnt1 pnt2 vevo1 vevo2)
(setq old_osnap(getvar "osmode"))
(setq pnt1 (getpoint "\nSelect the upper right hand corner of the Economizer Section: \n"))
; (4.26591 25.9316 0.0)
(setq pnt2 (getcorner pnt1 "\nSelect the lower left hand corner of the Economizer Section: \n"))
; (35.7619 3.30618 0.0)
(setvar "osmode" 0)
(setq ang (getreal "Enter angle of economizer <30 or 45>:\n"))
; 30.0
(setq cpnt (list(/ (+(car pnt1)(car pnt2))2)(/ (+(cadr pnt1)(cadr pnt2))2)))
; (20.0139 14.6189)
(setq cpnt1 (polar cpnt (dtr ang) 3))
; (22.612 16.1189)
(setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
; (35.7619 25.9316 0.0)
(setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))
; (4.26591 3.30618 0.0)
(command "_line" cpnt cpnt1 "")
(setq el1 (entlast))
(setq vevo1 (vlax-ename->vla-object el1))
(command "_line" pnt1 bndry2 "")
(setq el2 (entlast))
(setq vevo2 (vlax-ename->vla-object el2))
(setq coord (vlax-invoke vevo1 'IntersectWith vevo2 1))
(alert (strcat "\nThis intersection at"
"\n"
"\n"
"(" (rtos (car coord))
","
(rtos (cadr coord))
","
(rtos (caddr coord))
")")))
;(command "_erase" el1 el2 "")
;(setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
(setvar "osmode" old_osnap)
)

Lions60
2007-07-09, 02:27 PM
Thanks everyone for their help. I tried the methods posted and they all returned the same value , but where drawing the line from a different point than expected. I figured the problem out to be that i was turning my osnaps back on to soon so instead of drawing a line from the intended point it was snapping to an endpoint.