TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: David Bethel on November 24, 2005, 01:27:35 PM

Title: Comparing angles
Post by: David Bethel on November 24, 2005, 01:27:35 PM
Okay, I'm having a brain fade  I need to compare 2 angles to see if they are
within 90 degrees.  The angles can pass thru the X axis 
ie ang1 = 350 degrees & ang2 = 15 degrees ( 25 degree included angle ) so return T

The angles be randomly CW & CCW ( not like an ARCs CCW )
The angles will always be in radians

I'm tring to comapre the current view angle with the previous view angle

Code: [Select]
;;;loop thru a (while) statement
(setq cva (angle '(0 0) (getvar "VIEWDIR"))
(if (not pva)
    (setq pva cva))
;;;if the previous angle and current angle are with 90 degrees then do some more stuff
(setq pva cva); record the previous view angle
;;;Go to the next viewpoint & loop

I need to find if the current view angle changed more than 90 degrees different from the previous one.


TIA  -David
Title: Re: Comparing angles
Post by: David Bethel on November 24, 2005, 02:56:55 PM
I think my brain finally kicked back in

Code: [Select]
  (setq a1 0.1)
        a2 3.0))

  (or (< (abs (- a1 a2)) (* pi 0.5))
      (> (abs (- a1 a2)) (* pi 1.5)))


-David
Title: Re: Comparing angles
Post by: CAB on November 24, 2005, 08:11:32 PM
Here are some I have collected, source unknown.
Code: [Select]
;;=====================================================================
;; compute the absolute delta angle between 2 angles a1 & a2
(defun @delta (a1 a2)
  (abs ; added to return a positave angle only
  (cond
    ((> a1 (+ a2 pi)) (- (+ a2 pi pi) a1))
    ((> a2 (+ a1 pi)) (- a2 a1 pi pi))
    ((- a2 a1))
  )
 )
)
;;=====================================================================
;;  same results as above, except no (abs added
;; compute the delta angle between 2 angles a1 & a2
(defun @delta (a1 a2)
  (cond
    ((> a1 (+ a2 pi)) (setq a2 (+ a2 pi pi)))
    ((> a2 (+ a1 pi)) (setq a1 (+ a1 pi pi)))
  )
  (- a2 a1)
)
;;=====================================================================
Title: Re: Comparing angles
Post by: MP on November 24, 2005, 08:20:46 PM
I would guess those came from John Uhden CAB. He uses the @ prefix quite frequently.
Title: Re: Comparing angles
Post by: LE on November 24, 2005, 10:23:12 PM
Yes they are from John.... to bad he does not participate on this type of forums and also that he closed his web site too...
Title: Re: Comparing angles
Post by: CAB on November 24, 2005, 11:08:59 PM
Thanks guys, I had clipped them out of some routines & saved them as DeltaAngle.lsp
This was before I started recording the authors.
Title: Re: Comparing angles
Post by: David Bethel on November 25, 2005, 09:43:08 AM
Yep,

Sure enough I had a @delta subr in my collection and it had mention of John Uhden.  I told you brain fade.

Code: [Select]
(defun @delta (a1 a2)
  (cond ((> a1 (+ a2 pi))
         (- (+ a2 pi pi) a1))
        ((> a2 (+ a1 pi))
         (- a2 a1 pi pi))
        ((- a2 a1))))

Thanks all.  -David
Title: Re: Comparing angles
Post by: David Bethel on November 25, 2005, 11:47:08 AM
I think Jiohn is still around.  -David

http://www.cadlantic.com/
Title: Re: Comparing angles
Post by: LE on November 25, 2005, 11:49:55 AM
Thanks.... I tried to get to his web site, several times before.... without luck, great.