How to get a point from an angle and distance

Discussion in 'AutoCAD' started by JJC, Feb 19, 2004.

  1. JJC

    JJC Guest

    This is part of a routine I am working on, and am stumped. How do I get my
    second break point to be calculated from the first pick point by using the
    angle of a second pick point and using a preset distance? I want this
    routine to be just two pick, but have a preset break distance based on the
    scale routine. The second pick is to get angle between pt1 and pt2 so that
    the break works in that direction.

    ;converts radians to degrees
    (defun rtd (r)
    (* 180.0 (/ r pi))
    )
    ;
    (setq sc (getvar "userr1"))
    (setq sc2 (* 24.0 sc))
    (print sc2)
    (setq os (getvar "osmode"))
    (command "osmode" "512")
    (setq pt1 (getpoint "\nInsertion Point: "))
    (print pt1)
    (setq obj pt1)
    (setq pt2 (getpoint "\nSecond Point: "))
    (print pt2)
    (setq ang (rtd (angle pt1 pt2)))
    ;=================== this is the problem line below=============
    (print ang) <-I get error here, cant seem to make it work
    (setq pt3 (strcat sc2 "<" ang))
    (print pt3)
    (command "BREAK" obj pt1 (strcat sc2 "<" ang))

    How can i get the angle and distance to be like 24<45 where 24 is the
    distance, and 45 is the angle.

    This will then allow me to break any line at any angle and scale a
    predetermined distance. I will then insert text, which is the second aspect
    of this, and I have most of that already. I already have this routine for
    horizontal or verticle breaks and inserting text, just wanting to change it
    so it can be at any angle.

    Thanks
     
    JJC, Feb 19, 2004
    #1
  2. JJC

    Mark Propst Guest

    this line doesn't look like it should error, print will print a value even
    though it's not a string
    this is an obvious problem
    since sc2 is a real, strcat will choke on it, and if it didn't it would
    choke on ang which is also a real.

    to get pt3, use polar function
    for your example of 24<45 ,

    (setq dist 24)
    (setq ang (* pi 0.25));45 degrees in radians

    (setq pt3 (polar pt1 ang dist))


    hth
    Mark
     
    Mark Propst, Feb 19, 2004
    #2
  3. JJC

    JJC Guest

    THANKS, Tho I am aware of the polar command, but how do I use it when the
    angle can be literaly anything?

    (setq ang (* pi 0.25));45 degrees in radians

    if say the angles at 33 degrees? or even 32.8592 degrees

    If .25 is 1/4 of 180 degrees, then

    (setq ang (rtd (angle pt1 pt2)))
    (setq ang2 (* pi (* ang 180)));

    Will this work? I will try it but dont know yet.

    You see, angle is an unknown and not a constant.

    Thanks.
     
    JJC, Feb 19, 2004
    #3
  4. JJC

    CAB2k Guest

    This may help you. Makes pt3 a point relative to pt1

    ;=================== this is the problem line below=============
    (print ang)
    (setq pt3 (polar pt1 ang sc2))
    (print pt3)
    (command "BREAK" obj pt1 pt3)
     
    CAB2k, Feb 19, 2004
    #4
  5. JJC

    JJC Guest

    Here what I got, I used both your ideas, and neither work. Here is more of
    what it is doing. It breaks at the first point, but thats it. below is the
    autocad text window. the last set of numbers in ( ) should be the pt3, when
    I id where the pt3 is, its not even close. yet, the distance (24) and angle
    (17.2143) and the pt1 and pt2 are all correct. Is there a setting I need to
    do. Below that is the routine.

    ****************
    Command: gastest
    24.0
    Insertion Point: _endp of
    (236.882 330.809 0.0)
    Second Point:
    (296.366 349.239 0.0)
    17.2143
    9734.44
    (231.71 354.245 0.0)
    Command: id
    Specify point: X = 259.81 Y = 337.91 Z = 0.00
    **************************


    ;converts radians to degrees
    (defun rtd (r)
    (* 180.0 (/ r pi))
    )
    ;
    (setq sc (getvar "userr1"))
    (setq sc2 (* 24.0 sc))
    (print sc2)
    (setq os (getvar "osmode"))
    (command "osmode" "512")
    (setq pt1 (getpoint "\nInsertion Point: "))
    (print pt1)
    (setq obj pt1)
    (setq pt2 (getpoint "\nSecond Point: "))
    (print pt2)
    (setq ang (rtd (angle pt1 pt2)))
    (print ang)
    (setq ang2 (* pi (* ang 180)))
    (print ang2)
    ; (setq pt3 (polar pt1 ang sc2))
    ;(print pt3)
    (setq pt3 (polar pt1 ang2 sc2))
    (print pt3)
    (command "BREAK" obj pt1 pt3)
     
    JJC, Feb 19, 2004
    #5
  6. JJC

    JJC Guest

    Well, got it done, here is the final product, thank you for all your help.
    This is what got it done:

    (setq ang (rtd (angle pt1 pt2)))
    (setq ang2 (* pi (/ ang 180)))

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Custom commands by John Crocco
    ;breaks line and inserts an X for fencing, exploded for editing if desired.
    (DEFUN C:GASTEST (/ pt1 pt2 pt3 sc sc2 ang ang2 len os *Error*)
    ;;;;;;;;; Application error handler
    (defun *Error* (Msg)
    (command "._Undo" "_End") ; end undo group
    (cond
    ((not Msg)) ; no error, do nothing
    ((member (strcase Msg T) ; cancel, do undo
    '("console break"
    "function cancelled"
    "quit / exit abort"))
    (command "._U")
    (setvar "cmdecho" cecho)
    (command "osmode" os);UNDO COMMANDS HERE
    ;
    ;
    ;
    );END OF MEMBER
    ((princ (strcat "\nError: " Msg)))
    ) ; END OF COND
    (princ)
    ); END OF DEFUN ERROR
    (setq cecho (getvar "cmdecho"))
    (setvar "CmdEcho" 0) ; turn echo off
    (command "._Undo" "_End") ; close any open group
    (command "._Undo" "_BEgin") ; start new group
    ;;;;;;;;;;;;;;;;;;;;;;
    ;converts radians to degrees
    (defun rtd (r)
    (* 180.0 (/ r pi))
    )
    ;
    (setq sc (getvar "userr1"))
    (setq sc2 (* 24.0 sc))
    ;(print sc2); for debugging
    (setq os (getvar "osmode"))
    (command "osmode" "512")
    (setq pt1 (getpoint "\nInsertion Point: "))
    ;(print pt1); for debugging
    (setq obj pt1)
    (setq pt2 (getpoint "\nSecond Point: "))
    ;(print pt2); for debugging
    (setq ang (rtd (angle pt1 pt2)))
    ;(print ang); for debugging
    (setq ang2 (* pi (/ ang 180)))
    ;(print ang2); for debugging
    (setq pt3 (polar pt1 ang2 sc2))
    ;(print pt3); for debugging
    ;(command "line" pt1 pt3 ""); for debugging
    (command "BREAK" obj "f" pt1 pt3)
    (command "INSERT" "xblock" pt1 sc sc pt3)
    (command "explode" (entlast))
    (command "osmode" os)
    (setvar "cmdecho" cecho)
    (*Error* nil) ;call error handler w/no error
    )
     
    JJC, Feb 19, 2004
    #6
  7. JJC

    Jim Claypool Guest

    Why not just (setq ang2 (angle pt1 pt2)) instead of converting from radians
    to degrees and back?
     
    Jim Claypool, Feb 19, 2004
    #7
  8. JJC

    Mark Propst Guest

    why convert from radians to degrees and then back to radians?
    (setq ang(angle pt1 pt2))
     
    Mark Propst, Feb 19, 2004
    #8
  9. JJC

    CAB2k Guest

    Yes, as I posted previously.

    (setq ang (angle pt1 pt2))

    You do not need degrees!!!!!!!!!!!!!!!!!!
     
    CAB2k, Feb 19, 2004
    #9
  10. JJC

    John Crocco Guest

    I couldnt get it to work, thats why I went this way. How would you suppose
    it to be writen then and work? I believe I tried. I am willing to learn,
    thanks . . .
     
    John Crocco, Feb 19, 2004
    #10
  11. JJC

    urugx Guest

    BTW, you're using "userr1" in (setq sc (getvar "userr1")).
    Have you assigned any value to this variable. On a new
    drawing, it might be 0.0, so your succeeding points
    calculation for pt3 may come out to be the same as pt2
    (sc2 equates to 0.0 if sc is 0.0).
     
    urugx, Feb 19, 2004
    #11
  12. JJC

    John Crocco Guest

    Yes, thats all worked out, I use userr1 for my scale routine setup, and
    EVERYTHING inserted is scaled based on that value. New drawings are
    assigned a value in my startup routine, and then are set durring my scale
    routine of the drawing. Been using this for years, works great! Thanks
    tho.
     
    John Crocco, Feb 19, 2004
    #12
  13. JJC

    CAB2k Guest

    Good point urgx.

    Use somethinh like this.

    ;; Range check 1 to 30 is valid
    (if (or (<(setq sc (getvar "userr1")) 1)
    (> sc 30))
    (setq sc 25) ; default
    )
     
    CAB2k, Feb 19, 2004
    #13
  14. JJC

    CAB2k Guest

    Just tried this & it works fine.
    No degrees required.


    (defun c:test ()
    (setq sc2 24) ; debug

    (if (setq pt1 (getpoint "\nInsertion Point: "))
    (progn
    (command "point" pt1) ; for debugging
    (setq obj pt1)
    (if (setq pt2 (getpoint "\nSecond Point: "))
    (progn
    (command "point" pt2) ; for debugging
    (setq ang (angle pt1 pt2))
    ;;(print ang); for debugging
    (setq pt3 (polar pt1 ang sc2))
    (command "point" pt3) ; for debugging
    ;;(command "line" pt1 pt3 ""); for debugging
    (command "BREAK" obj "f" pt1 pt3)
    )
    )
    )
    )
    ) ; end fefun test
     
    CAB2k, Feb 19, 2004
    #14
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.