+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 25
  1. #1
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default A little trouble with calculating points in LISP

    Registered forum members do not see this ad.

    I am trying to make my own lisp, I mean without cut / paste other routines into my own. This
    one is an example wich I will "expand" as far as I have ideas.
    Function of routine: draw a box with specified side length. Insertion point box must be
    offset a certain distance from the actual insertion point. At last it should be rotate-able.

    This is what I have got so far:

    Code:
     
    (defun c:box1 (/ len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
    (setq len (getint "\nLength1:  "))
    (setq leng (getint "\nLength2:  "))
    (setq dist (getdist "\nDistance:  "))
    (setq pt1 (getpoint "\nInsertion:  "))
    (setq pt2 (polar pt1 (* pi 0.5) dist))
    (setq pt3 (polar pt2 (* 2 (* pi 0.5)) (* len 0.5)))
    (setq pt4 (polar pt3 (* pi 0.5) leng))
    (setq pt5 (polar pt4 0.0 len))
    (setq pt6 (polar pt3 0.0 len))
    (command "pline" pt3 pt4 pt5 pt6 pt3 "") 
    (command "rotate" "l" "" pt1  pause)
    (princ)
    )
    My questions / probs:

    Code:
     
    (defun c:box1 (/ len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
    No questions, given variables after the "/" are cleared after my routine ends.

    Code:
     
    (setq len (getint "\nLength1:  "))
    (setq leng (getint "\nLength2:  "))
    I had len1 and len2 but then it got stuck, I figured len1 can not be used in combination with the (polar ...) thingy below. Thats why I took the len and leng variable.

    Code:
     
    (setq dist (getdist "\nDistance:  "))
    No probs...
    Code:
    (setq pt1 (getpoint "\nInsertion:  "))
    No probs...

    Calculations, with tears in my eyes:
    Code:
     
    (setq pt2 (polar pt1 (* pi 0.5) dist))
    Polar is meant for an angle, am I correct?
    -> (* pi 0.5) is 90 degrees I figured.
    So: calculate point 2, it is "polared" to point 1, angle 90 degrees with a distance called "dist".
    Code:
     
    (setq pt3 (polar pt2 (* 2 (* pi 0.5)) (* len 0.5)))
    (setq pt4 (polar pt3 (* pi 0.5) leng))
    (setq pt5 (polar pt4 0.0 len))
    (setq pt6 (polar pt3 0.0 len))
    THese above must contain errors / faults for it does not work properly.

    Code:
     
    (command "pline" pt3 pt4 pt5 pt6 pt3 "") 
    (command "rotate" "l" "" pt1  pause)
    (princ)
    )
    Okay...
    In short terms:
    Can someone help me understand calculating this?
    Do not give me the solution at once, let me struggle.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,590

    Default

    This will hopefully explain things a little better, without just "giving you the answer".

    Code:
    (defun c:box1  (/ len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
    
      ; Define Functions and Localise Variables
      
      (setq len  (getdist "\nLength1:  ")
            
            leng (getdist "\nLength2:  ")
    
            ; I'd be more inclined to use "getdist"
            ; so that the user can pick the distance.
            
            dist (getdist "\nDistance:  ")
            
            pt1  (getpoint "\nInsertion:  ")
            
            pt2  (polar pt1 (* pi 0.5) dist)
            
    
    ;;;                     + pt2
    ;;;                     |
    ;;;                     |
    ;;;                     + pt1
    
            
            pt3  (polar pt2 pi (* len 0.5))
            
    
    ;;;            +--------+ pt2
    ;;;           pt3       |
    ;;;                     |
    ;;;                     + pt1
             
            
            pt4  (polar pt3 (* pi 0.5) leng)
    
             
    ;;;           pt4
    ;;;            +
    ;;;            |
    ;;;            |
    ;;;            +--------+ pt2
    ;;;           pt3       |
    ;;;                     |
    ;;;                     + pt1
             
            
            pt5  (polar pt4 0.0 len)
            
    
    ;;;           pt4               pt5
    ;;;            +-----------------+
    ;;;            |
    ;;;            |       pt2
    ;;;            +--------+--------+
    ;;;           pt3       |       pt6
    ;;;                     |
    ;;;                     + pt1
            
            
            pt6  (polar pt3 0.0 len)
    
            )  ; End Setq
      
      (command "_.pline" pt3 pt4 pt5 pt6 pt3 "")
    
      ; Remember to use "_." prefix to make it
      ; compatible for all language versions.
      
      (command "_.rotate" (entlast) "" pt1 pause)
    
      ; Use "entlast" to detect last entity
      ; added to database (hence created).
      
      (princ)
    
      ; Exit Cleanly
      
      ) ; End box1
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default

    This will hopefully explain things a little better, without just "giving you the answer".
    Yes thank you Lee.

    So the variable "pi" is like 180 degrees, for (* pi 0.5) gives 90 degrees. Using only pi gives the 180 degree angle, using 0.0 stays on 0 degrees. Makes sense.

    I like the way you put the setq in the routine: this way i can see in an easy way if i have the right amount parenthesises.. -> ().

    _. prefix tu use always, as a prefix in any command? Is that better?
    Like (command "_.ddatte" etc..?

    Strange thing is: when i open a clean new drawing an i try the command it sometimes draws "not okay". I mean, it looks like there is a variable not calculated right. That cannot be for it works sometimes.

    See the images, can you place this? The left is gooed, the right image shows the #$%@ up one.
    Attached Images

  4. #4
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default

    I thought it might have something to do with the _.pline function so I took a rectangle to do the job.

    Now it stays "in shap" but the dimension is not correct. ie. I create a box 1500 x 200 dist 100...
    I get a box 1423 x 261 dist 100.

    Aaargh...

  5. #5
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,590

    Default

    Quote Originally Posted by MarcoW View Post
    So the variable "pi" is like 180 degrees, for (* pi 0.5) gives 90 degrees. Using only pi gives the 180 degree angle, using 0.0 stays on 0 degrees. Makes sense.
    "pi" is a recognised symbol in LISP, and the "polar" function take a angle argument in radians, hence fractions of 2*pi.

    Quote Originally Posted by MarcoW View Post
    _. prefix tu use always, as a prefix in any command? Is that better?
    Like (command "_.ddatte" etc..?
    It is good coding practice to include this prefix, as it will account for versions in other languages.

    Quote Originally Posted by MarcoW View Post
    Strange thing is: when i open a clean new drawing an i try the command it sometimes draws "not okay". I mean, it looks like there is a variable not calculated right. That cannot be for it works sometimes.

    See the images, can you place this? The left is gooed, the right image shows the #$%@ up one.
    This will be the OSnaps coming into play when you use the "_.pline" command.

    You will need to turn them off and back on again to make this routine consistent.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,590

    Default

    This will help you in turning off the OSNAPs, but if you want complete "security" in this routine, you will need to add an Error Handler to switch the OSNAPs back on if the user hits Esc.

    Code:
    (defun c:box1  (/ oldos len leng dist pt1 pt2 pt3 pt4 pt5 pt6)
    
      (setq oldos (getvar "OSMODE")  ; Collect Old OSMODE setting
    
      ; Define Functions and Localise Variables
    
            len  (getdist "\nLength1:  ")
            
            leng (getdist "\nLength2:  ")
    
            ; I'd be more inclined to use "getdist"
            ; so that the user can pick the distance.
            
            dist (getdist "\nDistance:  ")
            
            pt1  (getpoint "\nInsertion:  ")
            
            pt2  (polar pt1 (* pi 0.5) dist)
            
    
    ;;;                     + pt2
    ;;;                     |
    ;;;                     |
    ;;;                     + pt1
    
            
            pt3  (polar pt2 pi (* len 0.5))
            
    
    ;;;            +--------+ pt2
    ;;;           pt3       |
    ;;;                     |
    ;;;                     + pt1
             
            
            pt4  (polar pt3 (* pi 0.5) leng)
    
             
    ;;;           pt4
    ;;;            +
    ;;;            |
    ;;;            |
    ;;;            +--------+ pt2
    ;;;           pt3       |
    ;;;                     |
    ;;;                     + pt1
             
            
            pt5  (polar pt4 0.0 len)
            
    
    ;;;           pt4               pt5
    ;;;            +-----------------+
    ;;;            |
    ;;;            |       pt2
    ;;;            +--------+--------+
    ;;;           pt3       |       pt6
    ;;;                     |
    ;;;                     + pt1
            
            
            pt6  (polar pt3 0.0 len)
    
            )  ; End Setq
    
      (setvar "OSMODE" 0)  ; Turn off the OSnaps!
      
      (command "_.pline" pt3 pt4 pt5 pt6 pt3 "")
    
      ; Remember to use "_." prefix to make it
      ; compatible for all language versions.
      
      (command "_.rotate" (entlast) "" pt1 pause)
    
      ; Use "entlast" to detect last entity
      ; added to database (hence created).
    
      (setvar "OSMODE" oldos)  ; Turn OSMODE back on
      
      (princ)
    
      ; Exit Cleanly
      
      ) ; End box1
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Super Member MarcoW's Avatar
    Computer Details
    MarcoW's Computer Details
    Operating System:
    Microsoft Windows 7 Pro 64-bit
    Computer:
    A black one
    CPU:
    Intel Xeon E5520 Quad Core
    RAM:
    8 GB
    Graphics:
    NVIDIA Quadro FX 580 - 512MB
    Primary Storage:
    300 GB 10000 RPM
    Using
    AutoCAD 2011
    Join Date
    Apr 2009
    Location
    The Netherlands
    Posts
    599

    Default

    Lee,

    All has to be learned. I read you were only 9 months programming lisp... It surprises me, fast learner! Thank you for your help.

    My next step will bring up new questions :-) so i will speak to you soon.
    Ps.: when's your exam?

  8. #8
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,590

    Default

    Quote Originally Posted by MarcoW View Post
    Lee,

    All has to be learned. I read you were only 9 months programming lisp... It surprises me, fast learner! Thank you for your help.

    My next step will bring up new questions :-) so i will speak to you soon.
    Ps.: when's your exam?
    Thanks Marco

    My exams start this Friday - I have 7 exams spread over 10 days...
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  9. #9
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,023

    Default

    1 thing that I always found interesting in radians:

    ( this from wikipedia )
    An angle of 1 radian results in an arc with an equal length to the radius of the circle.
    Attached Images
    R12 (Dos) - A2K

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,590

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by David Bethel View Post
    1 thing that I always found interesting in radians:

    ( this from wikipedia )
    Excellent point David, which explains nicely why there are 2*pi to a full circle - as the circumference is 2*pi*r.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Lisp for calculating the sum of blocks
    By sophie in forum AutoCAD Drawing Management & Output
    Replies: 18
    Last Post: 23rd Dec 2011, 02:02 pm
  2. points of a polyline lisp routine
    By Emily_83 in forum AutoLISP, Visual LISP & DCL
    Replies: 10
    Last Post: 10th Nov 2010, 02:23 pm
  3. Boundary Points - Lisp(need help)
    By oliver in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 20th Apr 2009, 01:10 pm
  4. Lisp For Break Points
    By JONTHEPOPE in forum AutoLISP, Visual LISP & DCL
    Replies: 9
    Last Post: 21st Jun 2008, 05:18 pm
  5. Need points to new layer lisp
    By grinder in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 12th Mar 2007, 03:19 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts