Author Topic: Comparing angles  (Read 3045 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Comparing angles
« 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
R12 Dos - A2K

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Comparing angles
« Reply #1 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
R12 Dos - A2K

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Comparing angles
« Reply #2 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)
)
;;=====================================================================
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Comparing angles
« Reply #3 on: November 24, 2005, 08:20:46 PM »
I would guess those came from John Uhden CAB. He uses the @ prefix quite frequently.
« Last Edit: November 24, 2005, 10:19:25 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

LE

  • Guest
Re: Comparing angles
« Reply #4 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...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Comparing angles
« Reply #5 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Comparing angles
« Reply #6 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
R12 Dos - A2K

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Comparing angles
« Reply #7 on: November 25, 2005, 11:47:08 AM »
I think Jiohn is still around.  -David

http://www.cadlantic.com/
R12 Dos - A2K

LE

  • Guest
Re: Comparing angles
« Reply #8 on: November 25, 2005, 11:49:55 AM »
Thanks.... I tried to get to his web site, several times before.... without luck, great.