cond (or

cond (or

cadking2k5
Advocate Advocate
1,100 Views
11 Replies
Message 1 of 12

cond (or

cadking2k5
Advocate
Advocate

what is wrong with this do I need a (or after (Cond I don't want to do a (and with each one and have to put the (if under each one if the angle is equal to one of the cond and when equal to one of the If's

(setq angsd (angle cen int))
(cond
((= (cvunit 30 "DEGREE" "RADIAN") angsd))
((= (cvunit 120 "DEGREE" "RADIAN") angsd))
((= (cvunit 210 "DEGREE" "RADIAN") angsd))
((= (cvunit 300 "DEGREE" "RADIAN") angsd))
(if (<= pi ang)
(command "_arc" "C" cen fspt scpt)
(setq arc (ssget "L"))
)
(if (> pi amg)
(command "_arc" "C" cen scpt fspt)
(setq arc (ssget "L"))
)
)

 

0 Likes
1,101 Views
11 Replies
Replies (11)
Message 2 of 12

Moshe-A
Mentor
Mentor

@cadking2k5 hi,

 

the (angle) function returns angle in radians and that what you wanted? but it is more easy to work in degrees.

in the following c:test function i convert the angle to degrees and than turn it to real.

 

 

enjoy

moshe

 

 

 

(defun c:test (/ angsd cen int fspt scpt ss)
 (setq angsd (angle cen int))
  
 (if (or
      (= (atof (angtos angsd 0 2))  30.0)
      (= (atof (angtos angsd 0 2)) 120.0)
      (= (atof (angtos angsd 0 2)) 210.0)
      (= (atof (angtos angsd 0 2)) 300.0)
     )
  (progn
   (if (<= angsd 180.0)
    (command "_arc" "C" cen fspt scpt)
    (command "_arc" "C" cen scpt fspt)
   )

   (setq ss (ssget "L"))
  ); progn
 ); if
); c:test

 

 

0 Likes
Message 3 of 12

_gile
Consultant
Consultant

Hi,

 

IMO, you should take the habit to work with angles in radians overall when they represent fractions of pi.

You should also always use a tolerance (fuzz) when comparing angles due to the double-precision floating-point lack of accuracy.

 

If I do not totally misunderstand your question and assuming angsd, ang and amg are 3 different values, your code could have been written like this.

 

(if
  (or (equal angsd (* pi (/ 1. 6.)) 1e-9)
      (equal angsd (* pi (/ 4. 6.)) 1e-9)
      (equal angsd (* pi (/ 7. 6.)) 1e-9)
      (equal angsd (* pi (/ 10. 6.)) 1e-9)
  )
   (progn
     (<= pi ang)
     (command "_arc" "C" cen fspt scpt)
     (setq arc (ssget "L"))
   )
   (if
     (> pi amg)
      (command "_arc" "C" cen scpt fspt)
      (setq arc (ssget "L"))
   )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 4 of 12

_gile
Consultant
Consultant

Oopss!...

There's a mistake in the upper code. It should have been:

(if
  (or (equal angsd (* pi (/ 1. 6.)) 1e-6) 
      (equal angsd (* pi (/ 4. 6.)) 1e-6)
      (equal angsd (* pi (/ 7. 6.)) 1e-6)
      (equal angsd (* pi (/ 10. 6.)) 1e-6)
  )
   (progn
     (if
       (<= pi ang)
        (command "_arc" "C" cen fspt scpt)
        (setq arc (ssget "L"))
     )
     (if
       (> pi amg)
        (command "_arc" "C" cen scpt fspt)
        (setq arc (ssget "L"))
     )
   )
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 12

dbhunia
Advisor
Advisor

Hi,

 

I think it's a part of a program ...... you can try this.....

 

(setq angsd (angle cen int))
(if (or
	(= (cvunit 30 "DEGREE" "RADIAN") angsd)
	(= (cvunit 120 "DEGREE" "RADIAN") angsd)
	(= (cvunit 210 "DEGREE" "RADIAN") angsd)
	(= (cvunit 300 "DEGREE" "RADIAN") angsd)
    )
    (progn
	(if (<= pi ang)
	(command "_arc" "C" cen fspt scpt)
	(setq arc (ssget "L"))
	)
	(if (> pi amg)
	(command "_arc" "C" cen scpt fspt)
	(setq arc (ssget "L"))
	)
    )
)

 

 

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 12

cadffm
Consultant
Consultant

@cadking2k5

aMg was a typo, or? i erased it and hoping it is right.

 

   (setq lastelem (entlast))
   (if (equal (/ pi 6) (rem angsd (/ pi 2)) 0.00000001) ; 30°/120°/210°/300°/...?	
       (if (<= pi ang)
	   (command "_.ARC" "_c" cen fspt scpt)
           (command "_.ARC" "_c" cen scpt fspt)
       )
   )
   (if (/= lastelem (entlast)) ; new ARC created?
       (progn ; then..
         (ssadd (entlast) (setq arc (ssadd)))
         (alert "well done, and so on..")
       )
       (alert (strcat "# " (angtos angsd 0 15) " #"))
   )

Sebastian

0 Likes
Message 7 of 12

Kent1Cooper
Consultant
Consultant

I'm starting from @_gile's suggestion because I agree that (equal) with a fuzz factor is necessary, and that working in radians is better, but I'm incorporating @Moshe-A's use of one  (if) function to test the relationship to 180 degrees, with 'then' and 'else' expressions in it, rather than separate  tests of two relationships.  But the following simplifies the angle check considerably, since all values are 30 degrees more than a multiple of 90 degrees, and it places that (if) function in a different place, to eliminate the redundancy of spelling out the bits of the Arc command twice [and just to illustrate a different way, puts the result in the 'arc' selection set differently]:

(if (equal (rem angsd (/ pi 2)) (/ pi 6) 1e-6)
 (progn; then
(command "_.arc" "_c" cen); leave in Arc command (if (< pi ang); [it's never going to be =] (command fspt scpt); then (command scpt fspt); else ); if
(setq arc (ssadd (entlast))) ); progn ); if

 

Kent Cooper, AIA
0 Likes
Message 8 of 12

cadking2k5
Advocate
Advocate

that is nice but what do I use for these two groups 330, 60, 150, 240,  and 0,  90, 180 ,270 see it is equal to PI these are the 45 degrees angles on a isometric drawing

0 Likes
Message 9 of 12

cadffm
Consultant
Consultant

The 0,90,180,270.. in the same way and for the other list of angles..

 

There was nothing to read in these terms from the angles, so why you are asking now?

Check _gile answer above with OR and EQUAL

 

 

Sebastian

0 Likes
Message 10 of 12

_gile
Consultant
Consultant

If you want to keep on going to the "rem route", you can use:

(equal (rem angsd (/ pi 2.)) (/ pi 3.) 1e-6) ; 60, 150,240, 330

and

(equal (rem angsd (/ pi 2.)) 0. 1e-6)

 

But, IMO, you should not use code you do not clearly understand because you may have difficulties with code maintenance in some months or years.

Instead, you can use a less elegant but more easily readable code like this:

(or
  (equal angsd (* pi (/ 1. 3.)) 1e-6)    ; 60°
  (equal angsd (* pi (/ 5. 6.)) 1e-6)    ; 150°
  (equal angsd (* pi (/ 4. 3.)) 1e-6)    ; 240°
  (equal angsd (* pi (/ 11. 6.)) 1e-6)   ; 330°
)

and

(or
  (equal angsd 0. 1e-6)            ; 0°
  (equal angsd (* pi 0.5) 1e-6)    ; 90°
  (equal angsd pi 1e-6)    	   ; 180°
  (equal angsd (* pi 0.75 1e-6)    ; 270°
)

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 11 of 12

Kent1Cooper
Consultant
Consultant

@_gile wrote:

....

....
(equal angsd (* pi 0.75 1e-6) ; 270° )

 

 

That last one should be:

 

    (equal angsd (* pi 1.5) 1e-6)    ; 270°

 

(* pi 0.75) woould be 135°.

 

Kent Cooper, AIA
Message 12 of 12

_gile
Consultant
Consultant

Oopss!...

Thanks for correcting it, @Kent1Cooper.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes