Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

X,Y,Z help ???

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
184 Views, 9 Replies

X,Y,Z help ???

I know this is probably a basic and easy prob. but I can't seam to solve it.
I wont to be able to draw a line and then pick a point and know witch side
of the line I'm on.
Please see my code below, if you run my code and draw a Vert. line from
Bott. to Top, the code works fine, but if you draw the line from Top to
Bott. then it gets it wrong.
Can anyone show me how to get my code to work with any angle line, drawn
with any pick order.

thx,
Barry

(defun C:xpt ( / pt1 pt2 ang ptMid pt3)
(setq pt1 (getpoint "\nFirst Point: ")
pt2 (getpoint "\nSecont Point: " pt1)
ang (angle pt1 pt2)
ptMid (polar pt1 ang (* 0.5 (distance pt1 pt2)))
);_ setq
(command "line" pt1 pt2 "")

(while (/= (car (setq pt3 (grread 'T 1 0))) 3)
(if (and (> (angle ptMid (cadr pt3)) ang)
(< (angle ptMid (cadr pt3)) (+ ang pi))
);_ and
(princ "\nDo stuff on Left: ")
(princ "\nDo stuff on Right: ")
);_ if
);_ while

(princ)
)
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

How about this little gem....

;;;Tony Tanzillo.
;;; (vector-side )
;;; Returns an integer code indicating position of
;;; in relation to the directed vector whose endpoints are
;;; and .
;;; Result Meaning
;;; -1 Point is to the right of vector.
;;; 0 Point is on (colinear with) vector
;;; 1 Point is to the left of vector.
(defun vector-side (v1 v2 p / r)
(setq r (- (* (- (car v2) (car v1)) (- (cadr p) (cadr v1)))
(* (- (cadr v2) (cadr v1)) (- (car p) (car v1)))
)
)
(cond ((equal r 0.0 1e-8) 0)
(t (fix (/ (abs r) r)))
)
)


--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


> I know this is probably a basic and easy prob. but I can't seam to solve
it.
> I wont to be able to draw a line and then pick a point and know witch side
> of the line I'm on.
Message 3 of 10
Anonymous
in reply to: Anonymous

Hello Barry, here is:

(defun pt-left (a b c / area a0 a1 b0 b1 c0 c1)
(setq a0 (car a)
a1 (cadr a)
b0 (car b)
b1 (cadr b)
c0 (car c)
c1 (cadr c))
(setq area (+
(- (* a0 b1) (* a1 b0))
(- (* a1 c0) (* a0 c1))
(- (* b0 c1) (* c0 b1))))
(and
(> area 0)
(not (equal area 0 0.0000001))))

(defun C:XPT (/ pt1 pt2 ang ptMid pt3)
(setq pt1 (getpoint "\nFirst Point: ")
pt2 (getpoint "\nSecont Point: " pt1)
ang (angle pt1 pt2)
ptMid (polar pt1 ang (* 0.5 (distance pt1 pt2))))
(command "._line" pt1 pt2 "")
(while (/= (car (setq pt3 (grread 'T 1 0))) 3)
(if (pt-left pt1 pt2 (cadr pt3))
(princ "\nDo stuff on Left: ")
(princ "\nDo stuff on Right: ")))
(princ))
Message 4 of 10
Anonymous
in reply to: Anonymous

thx guys, I new you'd come through.

"Luis Esquivel" wrote in message
news:9CF83235F169731E04BC8B242D9899F6@in.WebX.maYIadrTaRb...
> Hello Barry, here is:
>
> (defun pt-left (a b c / area a0 a1 b0 b1 c0 c1)
> (setq a0 (car a)
> a1 (cadr a)
> b0 (car b)
> b1 (cadr b)
> c0 (car c)
> c1 (cadr c))
> (setq area (+
> (- (* a0 b1) (* a1 b0))
> (- (* a1 c0) (* a0 c1))
> (- (* b0 c1) (* c0 b1))))
> (and
> (> area 0)
> (not (equal area 0 0.0000001))))
>
> (defun C:XPT (/ pt1 pt2 ang ptMid pt3)
> (setq pt1 (getpoint "\nFirst Point: ")
> pt2 (getpoint "\nSecont Point: " pt1)
> ang (angle pt1 pt2)
> ptMid (polar pt1 ang (* 0.5 (distance pt1 pt2))))
> (command "._line" pt1 pt2 "")
> (while (/= (car (setq pt3 (grread 'T 1 0))) 3)
> (if (pt-left pt1 pt2 (cadr pt3))
> (princ "\nDo stuff on Left: ")
> (princ "\nDo stuff on Right: ")))
> (princ))
>
>
Message 5 of 10
Anonymous
in reply to: Anonymous

Here's my version:

;;--------------------- 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
Message 6 of 10
btlsp
in reply to: Anonymous

What is "above" or "below", would a better criteria be: along the vector, left or right, as is a point, left or right of an existing sample vector.
Message 7 of 10
Anonymous
in reply to: Anonymous

Add another flavor, which is, oddly, 15-20% faster:

;;D. C. Broad, Jr.
;;(sideof )
(defun SideOf (p1 p2 p / r)
(setq r
(cond
((equal p1 p 1e-10) 0)
(t (sin (- (angle p1 p)(angle p1 p2))))))
(if (equal r 0 1e-10) 0 r)
)

;;return values
;;negative = point is to the right side of the ray
;;0 = point is on the ray
;;otherwise point is on the left side of the ray.
;;P1 should not equal P2 for meaningful results.


"Jason Piercey" wrote in message news:A8426880E85726F2E3292A28AC724D8D@in.WebX.maYIadrTaRb...
> How about this little gem....
>
> ;;;Tony Tanzillo.
> ;;; (vector-side )
> ;;; Returns an integer code indicating position of
> ;;; in relation to the directed vector whose endpoints are
> ;;; and .
> ;;; Result Meaning
> ;;; -1 Point is to the right of vector.
> ;;; 0 Point is on (colinear with) vector
> ;;; 1 Point is to the left of vector.
> (defun vector-side (v1 v2 p / r)
> (setq r (- (* (- (car v2) (car v1)) (- (cadr p) (cadr v1)))
> (* (- (cadr v2) (cadr v1)) (- (car p) (car v1)))
> )
> )
> (cond ((equal r 0.0 1e-8) 0)
> (t (fix (/ (abs r) r)))
> )
> )
>
>
> --
> -Jason
>
> Member of the Autodesk Discussion Forum Moderator Program
>
>
> > I know this is probably a basic and easy prob. but I can't seam to solve
> it.
> > I wont to be able to draw a line and then pick a point and know witch side
> > of the line I'm on.
>
>
>
Message 8 of 10
Anonymous
in reply to: Anonymous

How do you know it's 15-20% faster?

thx,
Barry

"Doug Broad" wrote in message
news:029E17652EE293E9CBF9D3AC8667324B@in.WebX.maYIadrTaRb...
> Add another flavor, which is, oddly, 15-20% faster:
>
> ;;D. C. Broad, Jr.
> ;;(sideof )
> (defun SideOf (p1 p2 p / r)
> (setq r
> (cond
> ((equal p1 p 1e-10) 0)
> (t (sin (- (angle p1 p)(angle p1 p2))))))
> (if (equal r 0 1e-10) 0 r)
> )
>
> ;;return values
> ;;negative = point is to the right side of the ray
> ;;0 = point is on the ray
> ;;otherwise point is on the left side of the ray.
> ;;P1 should not equal P2 for meaningful results.
>
>
> "Jason Piercey" wrote in message
news:A8426880E85726F2E3292A28AC724D8D@in.WebX.maYIadrTaRb...
> > How about this little gem....
> >
> > ;;;Tony Tanzillo.
> > ;;; (vector-side )
> > ;;; Returns an integer code indicating position of
> > ;;; in relation to the directed vector whose endpoints are
> > ;;; and .
> > ;;; Result Meaning
> > ;;; -1 Point is to the right of vector.
> > ;;; 0 Point is on (colinear with) vector
> > ;;; 1 Point is to the left of vector.
> > (defun vector-side (v1 v2 p / r)
> > (setq r (- (* (- (car v2) (car v1)) (- (cadr p) (cadr v1)))
> > (* (- (cadr v2) (cadr v1)) (- (car p) (car v1)))
> > )
> > )
> > (cond ((equal r 0.0 1e-8) 0)
> > (t (fix (/ (abs r) r)))
> > )
> > )
> >
> >
> > --
> > -Jason
> >
> > Member of the Autodesk Discussion Forum Moderator Program
> >
> >
> > > I know this is probably a basic and easy prob. but I can't seam to
solve
> > it.
> > > I wont to be able to draw a line and then pick a point and know witch
side
> > > of the line I'm on.
> >
> >
> >
>
>
Message 9 of 10
Anonymous
in reply to: Anonymous

Benchmarked it with R. Robert Bell's Bench program with a variety
of points and 1000 loops each time. I didn't expect the ANGLE and
SIN functions to beat Tony's more basic math operations. Typically
trig functions are slower. So the results surprised me.

Regards,
Doug

"Barry Ralphs" wrote in message news:18856BBFF7A96D627BBE811E3140F19B@in.WebX.maYIadrTaRb...
> How do you know it's 15-20% faster?
>
> thx,
> Barry
>
> "Doug Broad" wrote in message
> news:029E17652EE293E9CBF9D3AC8667324B@in.WebX.maYIadrTaRb...
> > Add another flavor, which is, oddly, 15-20% faster:
> >
> > ;;D. C. Broad, Jr.
> > ;;(sideof )
> > (defun SideOf (p1 p2 p / r)
> > (setq r
> > (cond
> > ((equal p1 p 1e-10) 0)
> > (t (sin (- (angle p1 p)(angle p1 p2))))))
> > (if (equal r 0 1e-10) 0 r)
> > )
> >
> > ;;return values
> > ;;negative = point is to the right side of the ray
> > ;;0 = point is on the ray
> > ;;otherwise point is on the left side of the ray.
> > ;;P1 should not equal P2 for meaningful results.
> >
> >
> > "Jason Piercey" wrote in message
> news:A8426880E85726F2E3292A28AC724D8D@in.WebX.maYIadrTaRb...
> > > How about this little gem....
> > >
> > > ;;;Tony Tanzillo.
> > > ;;; (vector-side )
> > > ;;; Returns an integer code indicating position of
> > > ;;; in relation to the directed vector whose endpoints are
> > > ;;; and .
> > > ;;; Result Meaning
> > > ;;; -1 Point is to the right of vector.
> > > ;;; 0 Point is on (colinear with) vector
> > > ;;; 1 Point is to the left of vector.
> > > (defun vector-side (v1 v2 p / r)
> > > (setq r (- (* (- (car v2) (car v1)) (- (cadr p) (cadr v1)))
> > > (* (- (cadr v2) (cadr v1)) (- (car p) (car v1)))
> > > )
> > > )
> > > (cond ((equal r 0.0 1e-8) 0)
> > > (t (fix (/ (abs r) r)))
> > > )
> > > )
> > >
> > >
> > > --
> > > -Jason
> > >
> > > Member of the Autodesk Discussion Forum Moderator Program
> > >
> > >
> > > > I know this is probably a basic and easy prob. but I can't seam to
> solve
> > > it.
> > > > I wont to be able to draw a line and then pick a point and know witch
> side
> > > > of the line I'm on.
> > >
> > >
> > >
> >
> >
>
>
Message 10 of 10
btlsp
in reply to: Anonymous

My two cents, must be run with support routines(bt_dnd@hotmail.com).
(defun C:LR ()
;/)
(svar)
;-----------------------------------------------
;...interface
(if (not imlr)(setq imlr (list 2
"Pick Line" (entlast)
"Pick Point" (getvar "lastpoint") )))
;-----------------------------------------------
;...set variables
(setq
imlr (imp imlr)
e2 (mget imlr 1 0)
v4 (mget imlr 1 1)
v2 (mget (tl e2) 0 1)
v3 (mget (tl e2) 0 0)
v9 (nrm (cpt v2 k))
v5 (vc2 v3 v4)
v6 (prj v5 (cpt v2 k))
v7 (nrm v6) )
(if (equal v7 v9 (exp -7))(setq dec "R")
(setq dec "L") )
(itzovr)
dec )

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost