Author Topic: Angles again.  (Read 6175 times)

0 Members and 1 Guest are viewing this topic.

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Angles again.
« on: October 17, 2004, 05:40:57 PM »
Hey guys, I am trying to figure of a better way that I can do this, but haven't been able to think of anything...and clues as to where i can start?

Code: [Select]
(if
(or (>= 0.00000 ang1) (< 0.392699 ang1) (> 5.890489 ang1) (<= 6.28318 ang1) (> 2.748889 ang1) (< 3.534287 ang1)) ; End or
(setq pnt (* 0.17 lts))
)
       (if
(or (> 0.392699 ang1) (< 1.178097 ang1) (> 1.963491 ang1) (< 2.748889 ang1) (> 3.534287 ang1)
    (< 4.319689 ang1) (> 5.105087 ang1) (< 5.890485 ang1)) ; End or
(setq pnt (* 0.11 lts))
       )
       (if
(or (> 1.178097 ang1) (< 1.963491 ang1) (> 4.319689 ang1) (< 5.105087 ang1))
(setq pnt (* 0.09 lts))
)


What I am trying to do if you can't figure, is if the angle between any two points (ang1) fits the criteria given, it will set my point (pnt) according to the factors given. I know i am probably over thinking this here, but I am trying, and have been getting a lot better.

Rug
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #1 on: October 17, 2004, 06:02:25 PM »
I don't know if I really understand what you're saying / asking but perhaps this will illuminate (the equality functions will take more than 2 arguments) ...

Code: [Select]
(defun foo ( ang1 angx ang2 resultThen resultElse )
    (if (<= ang1 angx ang2)
        resultThen
        resultElse
    )
)


(foo 0 45 90 '(0 0) '(100 100)) => (0 0)
(foo 0 270 90 '(0 0) '(100 100)) => (100 100)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Angles again.
« Reply #2 on: October 17, 2004, 06:14:27 PM »
This is what I am essentially trying to get out:

Code: [Select]
If angle from user (ang1) is anywhere between 0d-22.5d or 157.5d-202.5d then set the var pnt to 0.17 times the ltscale. If the angle is between 22.5d-67.5d, 112.5d-157.5d, 202.5d-247.5d, or 292.5d-337.5d then set the var pnt to 0.11 times the letscale.

The same goes for the remaining angles. All of the numbers in my arguments are the radian equivalencies to the degrees i gave above. Hopefully this will help a bit more MP.
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #3 on: October 17, 2004, 06:47:24 PM »
Generically what you're saying is if Condition1 then Result1, and so on for x scenarios of Condition and Result. The only thing I note is no default value. Consider ...

Code: [Select]
(defun Foo ( ang scenarios default / result )
    (vl-some
       '(lambda (scenario)
            (if (<= (car scenario) ang (cadr scenario))
                (setq result (caddr scenario))
            )    
        )
        scenarios
    )    
    (if result
        result
        default
    )    
)

(defun TestFoo ( x )
    (Foo
        x
       '(
            (0 2 100) ;; scenario 1
            (3 5 200) ;; scenario 2
            (6 8 300) ;; scenario 3
        )
        400 ;; default value
    )
)

(TestFoo 1.5) => 100
(TestFoo 4) => 200
(TestFoo 7) => 300
(TestFoo 11) => 400

Can you see your problem in these terms?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Ron Heigh

  • Guest
Angles again.
« Reply #4 on: October 17, 2004, 06:51:44 PM »
Will this work?
Code: [Select]
(setq val:multiplier
(cond
  ((= (>= ang1 0d) (<= ang1 22.5d)) 0.17)
  ((= (> ang1 22.5d) (<= ang1 67.5d)) 0.11)
  ((= (> ang1 67.5d) (<= ang1 112.5d)) 0.09)
  ((= (> ang1 112.5d) (<= ang1 157.5d)) 0.11)
  ((= (> ang1 157.5d) (<= ang1 202.5d)) 0.17)
  ((= (> ang1 202.5d) (<= ang1 247.5d)) 0.11)
  ((= (> ang1 247.5d) (<= ang1 292.5d)) 0.09)
  ((= (> ang1 292.5d) (<= ang1 337.5d)) 0.11)
  ((= (> ang1 337.5d) (< ang1 360.0d)) 0.09)
) ;_ end of cond
  ) ;_ end of setq
(setq pnt (* val:multiplier lts))


Check my numbers to make sure they are what you need.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #5 on: October 17, 2004, 07:06:49 PM »
Just a thought, but I think from a syntax perspective it would be better to replace = with and in those cond statements [tho I prefer the (<= a x b) useage] and it's usually a good idea to have a default value, lest the structure return nil if no conditions are met. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Ron Heigh

  • Guest
Angles again.
« Reply #6 on: October 17, 2004, 08:47:21 PM »
Quote from: MP
Just a thought, but I think from a syntax perspective it would be better to replace = with and in those cond statements [tho I prefer the (<= a x b) useage] and it's usually a good idea to have a default value, lest the structure return nil if no conditions are met. :)


What is the difference between = and and?
Your right about the default value.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #7 on: October 17, 2004, 09:01:49 PM »
Quote from: Ron Heigh
What is the difference between = and and?

Generally speaking = is used to test the equality of supplied numerical values, whereas and is used to test the logical and of supplied arguments, returning nil if any of the arguments evaluate to nil.

So .. is the result of (< num1 num2) a numerical value or something that evaluates to nil or t?

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #8 on: October 17, 2004, 11:18:57 PM »
Another technique that works well for range testing (which is what rugaroo is doing) is to top test.

For example, say I wanted to capture ranges less than 0, 0 .. 9.99, 10 .. 99.99, 100 and greater ...

Code: [Select]
(defun foo ( int )
    (princ
        (strcat
            (itoa int)
            " is "
            (cond
                ((<= 100 int) "greater than or equal to 100")  
                ((<= 10 int)  "between 10 and 99.999")
                ((<= 0 int)   "between 0 and 9.99")
                (t            "less than 0")
            )
            "\n"
        )    
    )
    (princ)
)

;;  example ...

(foreach x '(-5 5 50 500)
    (foo x)
)

-5 is less than 0
5 is between 0 and 9.99
50 is between 10 and 99.999
500 is greater than or equal to 100
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Angles again.
« Reply #9 on: October 17, 2004, 11:58:38 PM »
Well, I would love to say who is helping me more here..but for some reason i am having a problem with my getkword...well here is the over all code, so maybe this will help some more.

Code: [Select]
;;;-------------------------------------------------------------;;;
;;;           CNOTES.lsp - Created by: Roland W. Frye           ;;;
;;;           Version: V.1.0-NG Released: 2004.10.20            ;;;
;;;               For Support Information visit:                ;;;
;;;            http://www.civildraftingservices.com             ;;;
;;;-------------------------------------------------------------;;;

(defun c:const (/)
  (setq cmd (getvar "cmdecho")
fil (getvar "filedia")
lts (getvar "ltscale")
snp (getvar "snapang")
cla (getvar "clayer")
blp (getvar "blipmode")
  ) ; End Setq
  (setvar "cmdecho" 0)
  (setvar "filedia" 0)
  (initget 1
  "CIRCLE ELLIPSE SQUARE HEXAGON TRIANGLE"
  )
  (setq ans
(getkword
  "\nConstruction note type - <Circle/Ellipse/Square/Hexagon/Triangle>: "
)
  )
  (cond (= (= ans "Circle") T)
(if
(progn
  (setvar "blipmode" 1)
  (setq pnt1 (getpoint "\nStarting point of leader:")
pnt2 (getpoint "\nEnding point of leader:")
cnot (getint "\nConstruction note number:")
  ) ; End setq
  (if
    (= nil
(tblsearch "layer" "P-CNOTE-T")
    )
     (command "layer" "m" "P-CNOTE-T" "C" "7" "" "")
     (command "layer" "S" "P-CNOTE-T" "")
  ) ; End if
  (command "leader" pnt1 pnt2 "" "" "none")
; End Command - Leader
  (setq pnt (* 0.09 lts)
  ) ; End setq
  (command ".-insert"
   "cnote"
   "s"
   lts
   (polar pnt2 (angle pnt1 pnt2) pnt)
   snp
   cnot
  ) ; End command - note insert
  (setvar "blipmode" blp) ; Restore variable
  (command "regen") ; Regen to eliminate blips
  (princ) ; Clear
  (setvar "cmdecho" cmd) ; Restore variable
  (setvar "filedia" fil) ; Restore variable
  (setvar "clayer" cla) ; Restore variable
  (princ) ; Clear Exit
) ; End progn
)
  )
  (cond (= (= ANS "Ellipse") t)
(progn
(setvar "blipmode" 1)
(setq pnt1 (getpoint "\nStarting point of leader:")
      pnt2 (getpoint "\nEnding point of leader:")
      cnot (getint "\nConstruction note number:")
      ang1 (angle pnt1 pnt2)
) ; End setq
(if
  (= nil
     (tblsearch "layer" "P-CNOTE-T")
  )
   (command "layer" "m" "P-CNOTE-T" "C" "7" "" "")
   (command "layer" "S" "P-CNOTE-T" "")
) ; End if
(setq val:multiplier
(cond
 ((= (>= ang1 0.00000) (<= ang1 0.392699)) 0.17)
 ((= (> ang1 0.392699) (<= ang1 1.178097)) 0.11)
 ((= (> ang1 1.178097) (<= ang1 1.963491)) 0.09)
 ((= (> ang1 1.963491) (<= ang1 2.748889)) -0.11)
 ((= (> ang1 2.748889) (<= ang1 3.534287)) -0.17)
 ((= (> ang1 3.534287) (<= ang1 4.319689)) -0.11)
 ((= (> ang1 4.319689) (<= ang1 5.105087)) -0.09)
 ((= (> ang1 5.105087) (<= ang1 5.890485)) 0.11)
 ((= (> ang1 5.890485) (< ang1 6.28318)) 0.17)
) ;_ end of cond
) ;_ end of setq
(setq pnt (* val:multiplier lts))
(command "leader" pnt1 pnt2 "" "" "none")
; End Command - Leader
(command ".-insert"
 "enote"
 "s"
 lts
 (polar pnt2 (angle pnt1 pnt2) pnt)
 snp
 cnot
) ; End command - note insert
(setvar "blipmode" blp) ; Restore variable
(command "regen") ; Regen to eliminate blips
(princ) ; Clear
(setvar "cmdecho" cmd) ; Restore variable
(setvar "filedia" fil) ; Restore variable
(setvar "clayer" cla) ; Restore variable
) ; End progn
  ) ; End setq
  (princ) ; Clear Exit
)
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Angles again.
« Reply #10 on: October 18, 2004, 12:09:49 AM »
Try:
Code: [Select]
(initget 1 "Circle Ellipse Square Hexagon Triangle")
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Angles again.
« Reply #11 on: October 18, 2004, 12:55:13 AM »
Well I toyed with it for a bit and to my demise got it to work...well almost. :) Well I hope this is making sense to you guys what i am doing here.

Code: [Select]
;;;-------------------------------------------------------------;;;
;;;           CNOTES.lsp - Created by: Roland W. Frye           ;;;
;;;           Version: V.1.0-NG Released: 2004.10.20            ;;;
;;;               For Support Information visit:                ;;;
;;;            http://www.civildraftingservices.com             ;;;
;;;-------------------------------------------------------------;;;

(defun c:const (/)
  (setq cmd (getvar "cmdecho")
fil (getvar "filedia")
lts (getvar "ltscale")
snp (getvar "snapang")
cla (getvar "clayer")
blp (getvar "blipmode")
  ) ; End Setq
  (setvar "cmdecho" 0)
  (setvar "filedia" 0)
  (initget 1 "Circle Ellipse Square Hexagon Triangle")
  (setq ans
(getkword
  "\nConstruction note type - <Circle/Ellipse/Square/Hexagon/Triangle>: "
)
  )
  (if
    (= ans "Circle")
     (progn
       (setvar "blipmode" 1)
       (setq pnt1 (getpoint "\nStarting point of leader:")
    pnt2 (getpoint "\nEnding point of leader:")
    cnot (getint "\nConstruction note number:")
       ) ; End setq
       (if
(= nil
   (tblsearch "layer" "P-CNOTE-T")
)
 (command "layer" "m" "P-CNOTE-T" "C" "7" "" "")
 (command "layer" "S" "P-CNOTE-T" "")
       ) ; End if
       (command "leader" pnt1 pnt2 "" "" "none")
; End Command - Leader
       (setq pnt (* 0.09 lts)
       ) ; End setq
       (command ".-insert"
"cnote"
"s"
lts
(polar pnt2 (angle pnt1 pnt2) pnt)
snp
cnot
       ) ; End command - note insert
       (setvar "blipmode" blp) ; Restore variable
       (command "regen") ; Regen to eliminate blips
       (princ) ; Clear
       (setvar "cmdecho" cmd) ; Restore variable
       (setvar "filedia" fil) ; Restore variable
       (setvar "clayer" cla) ; Restore variable
       (princ) ; Clear Exit
     ) ; End progn
  )

  (if
    (= ANS "Ellipse")
     (progn
       (setvar "blipmode" 1)
       (setq pnt1 (getpoint "\nStarting point of leader:")
    pnt2 (getpoint "\nEnding point of leader:")
    cnot (getint "\nConstruction note number:")
    ang1 (angle pnt1 pnt2)
       ) ; End setq
       (if
(= nil
   (tblsearch "layer" "P-CNOTE-T")
)
 (command "layer" "m" "P-CNOTE-T" "C" "7" "" "")
 (command "layer" "S" "P-CNOTE-T" "")
       ) ; End if
       (setq val:multiplier
     (cond
((= (>= ang1 0.00000) (<= ang1 0.392699)) 0.17)
((= (> ang1 0.392699) (<= ang1 1.178097)) 0.11)
((= (> ang1 1.178097) (<= ang1 1.963491)) 0.09)
((= (> ang1 1.963491) (<= ang1 2.748889)) -0.11)
((= (> ang1 2.748889) (<= ang1 3.534287)) -0.17)
((= (> ang1 3.534287) (<= ang1 4.319689)) 0.11)
((= (> ang1 4.319689) (<= ang1 5.105087)) 0.09)
((= (> ang1 5.105087) (<= ang1 5.890485)) 0.11)
((= (> ang1 5.890485) (< ang1 6.28318)) 0.17)
     ) ;_ end of cond
       ) ;_ end of setq
       (setq pnt (* val:multiplier lts))
       (command "leader" pnt1 pnt2 "" "" "none")
; End Command - Leader
       (command ".-insert"
"enote"
"s"
lts
(polar pnt2 (angle pnt1 pnt2) pnt)
snp
cnot
       ) ; End command - note insert
       (setvar "blipmode" blp) ; Restore variable
       (command "regen") ; Regen to eliminate blips
       (princ) ; Clear
       (setvar "cmdecho" cmd) ; Restore variable
       (setvar "filedia" fil) ; Restore variable
       (setvar "clayer" cla) ; Restore variable
     ) ; End progn
  ) ; End setq
  (princ) ; Clear Exit
)
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017

Anonymous

  • Guest
Angles again.
« Reply #12 on: October 18, 2004, 01:18:41 AM »
demise != surprise

SMadsen

  • Guest
Angles again.
« Reply #13 on: October 18, 2004, 07:22:48 AM »
As for the initial question, I would take advantage of multiple arguments to equality functions.

Code: [Select]
;;; Premises:
;;  If angle from user (ang1) is anywhere between 0d-22.5d
;;  or 157.5d-202.5d then set the var pnt to 0.17 times the ltscale.

;;  If the angle is between 22.5d-67.5d, 112.5d-157.5d, 202.5d-247.5d,
;;  or 292.5d-337.5d then set the var pnt to 0.11 times the letscale.


;;; With direct calculation of radians:
(setq val:multiplier
       (cond ((or (<= 0.0 ang (/ pi 8.0))
                  (>= (* 7.0 (/ pi 8.0)) ang (* 9.0 (/ pi 8.0)))
              )
              0.17
             )
             ((or (<= (/ pi 8.0) ang (* 3.0 (/ pi 8.0)))
                  (<= (* 1.6 pi) ang (* 7.0 (/ pi 8.0)))
                  (<= (* 9.0 (/ pi 8.0)) ang (* 11.0 (/ pi 8.0)))
              )
              0.11
             )
       )
)

;;; Or, with on-the-fly convertion from degrees to radians
(defun dtr (a)(/ (* pi a) 180.0))

(setq val:multiplier
       (cond ((or (<= 0.0 ang (dtr 22.5))
                  (>= (dtr 157.5) ang (dtr 202.5))
              )
              0.17
             )
             ((or (<= (dtr 22.5) ang (dtr 67.5))
                  (<= (dtr 112.5) ang (dtr 157.5))
                  (<= (dtr 202.5) ang (dtr 247.5))
              )
              0.11
             )
       )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Angles again.
« Reply #14 on: October 18, 2004, 04:58:37 PM »
rugaroo,
If the angle is always >= 0 no need to test for angle below 0.
Because the cond statement quits as soon as it find a true statement
your code can be written like this:
Code: [Select]
      (setq val:multiplier
              (cond
                ((<= ang1 0.392699) 0.17)
                ((<= ang1 1.178097) 0.11)
                ((<= ang1 1.963491) 0.09)
                ((<= ang1 2.748889) -0.11)
                ((<= ang1 3.534287) -0.17)
                ((<= ang1 4.319689) 0.11)
                ((<= ang1 5.105087) 0.09)
                ((<= ang1 5.890485) 0.11)
                (0.17)
              ) ;_ end of cond
             )
 
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.