Angle discrepencies

Discussion in 'AutoCAD' started by Ken Alexander, Jul 19, 2004.

  1. In the snip below you select a segment of a closed polygon. Pick a
    point inside of the polygon. Draws a line from the picked point to a
    point that makes the line perpendicular to the segment. Should also
    set dwl_ang to the same angle as the line. I only want the angle but
    I put the (command "line" .......) in just to test. The line never
    fails to be perp. to the segment, but the variable dwl_ang is
    sometimes wrong, but not all the time. I can't pin point when and why
    I get a bogus angle. Is there something wrong here that anyone can
    see?

    (while (not
    (and
    (setq ent (entsel "\nSelect milling edge: "))
    (setq endpnts (segmentpts ent))
    )
    )
    )
    (setvar "osmode" 0)
    (initget 1)
    (setq inside_pnt (getpoint "\nPick point inside board edges: "))
    (command "line" inside_pnt (osnap (car (cdr ent)) "perp") "")
    (setq dwl_ang (angle inside_pnt (osnap (car (cdr ent)) "perp")))

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 19, 2004
    #1
  2. Jason,

    I didn't include it because all it does is find the endpoints of the
    segment selected. That function doesn't redefine ent.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 19, 2004
    #2
  3. I figured that, but for the sake of testing
    posted code.....
     
    Jason Piercey, Jul 19, 2004
    #3
  4. Gottcha. That line should be commented out. My tests have been done
    without running that function.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 19, 2004
    #4
  5. (I just commented that line out....)

    I couldn't get it to fail, tried several variations
    of picking segments. Don't see anything that
    jumps out at me.
     
    Jason Piercey, Jul 19, 2004
    #5
  6. Ken Alexander

    Doug Broad Guest

    Ken,
    Compare this to the code you posted. After you draw
    the line, osnap may perform differently since it has a new
    entity to work with (ie the line). Does this work better?

    (while (not
    ; (and
    (setq ent (entsel "\nSelect milling edge: "))
    ; (setq endpnts (segmentpts ent))
    ; )
    )
    )
    (setvar "osmode" 0)
    (initget 1)
    (setq inside_pnt (getpoint "\nPick point inside board edges: "))
    (setq per_pnt (osnap (cadr ent) "perp"))
    (command "line" inside_pnt per_pnt "")
    (setq dwl_ang (angle inside_pnt per_pnt))
     
    Doug Broad, Jul 20, 2004
    #6
  7. Ken Alexander

    John Uhden Guest

    Hi, Ken.

    My guess is that the second (osnap (car (cdr ent)) "perp") may be picking up the
    line just drawn.
    How about (setq p2 (osnap (car (cdr ent)) "perp")) and then (setq dwl_ang (angle
    inside_pnt p2))?

    You also have to watch out for using (osnap) with pick points and objects of
    different or varying elevations.
    Hmm, maybe also change that to "quick,perp".
     
    John Uhden, Jul 20, 2004
    #7
  8. Ken Alexander

    Doug Broad Guest

    Hi John,
    Beat ya!
     
    Doug Broad, Jul 20, 2004
    #8
  9. Perpendicular and Tangent OSNAP are dependent on more than
    just a 'pick point'. They use the value of LASTPOINT to compute
    the result. Hence, you should *always* set LASTPOINT to the
    point you want to compute a perpendicular direction _from_.

    Sometimes, the last use of (getpoint) does this for you, but
    it would be unwise to depend on it.

    Also, using OSNAP is somewhat unpredictable, because it uses
    the (entsel) type object selection to identify the entity that is
    involved in the operation. If you can compute the desired point
    more directly (e.g., inters, polar, etc.), that's a safer tactic.
     
    Tony Tanzillo, Jul 20, 2004
    #9
  10. Huh? Drawing a line, just to set the LASTPOINT?

    Looks like you beat yourself :)
     
    Tony Tanzillo, Jul 20, 2004
    #10
  11. Let me correct myself:
    Actually, it is the last point passed to the (command) function
    that sometimes does this for you (as is the case in Doug's code),
    not the last response to (getpoint).
     
    Tony Tanzillo, Jul 20, 2004
    #11
  12. Ken Alexander

    Doug Broad Guest

    Good points Tony! This might work better.

    (defun C:TEST ()
    (while (not

    (setq ENT (entsel "\nSelect milling edge: "))
    )
    )
    (setvar "osmode" 0)
    (initget 1)
    (setvar "lastpoint"
    (setq INSIDE_PNT (getpoint "\nPick point inside board edges: ")))
    (setq PER_PNT (osnap (cadr ENT) "perp"))
    (command "line" "non" INSIDE_PNT "non" PER_PNT "") ;for visibility only
    (setq DWL_ANG (angle INSIDE_PNT PER_PNT)))
     
    Doug Broad, Jul 20, 2004
    #12
  13. Finally the internet is back up.

    I need to clarify the line. I'm trying to get the angle that is perp.
    to the segment going towards the inside of the polygon. My use of the
    line was simply a test. Remove the (command "line"...) and just try
    to get the angle, it doesn't always come up with the correct angle. I
    would rather not use osnaps to come up with this, but at this point I
    haven't been able to come up with another method.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #13
  14. Doug,

    Seems to work fine this way. I like Tony's suggestion of not using
    osnaps but can't come up with anything yet. I need a
    vlax-curve-getclosestpointtoparam type function. Thanks

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #14
  15. Thanks Tony, I'm going to work on your last suggestion a little bit
    more.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #15
  16. BTW (cadr ENT) looks a little better too. <g>

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #16
  17. John,

    Thanks for the input and the SegmentPts function.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #17
  18. Putting together some trig. I'll post it for expert review.

    --
    Ken Alexander
    Acad2004
    Windows XP

    "We can't solve problems by using the same kind
    of thinking we used when we created them."
    --Albert Einstein
     
    Ken Alexander, Jul 20, 2004
    #18
  19. Ken Alexander

    Joe Burke Guest

    Ken,

    Does this help?

    ;; sp1 - first segment point
    ;; sp2 - second segment point
    ;; pkpt - point picked inside pline
    ;; return a point such that a line
    ;; from pkpt to return point is
    ;; perpendicular to segment

    (defun PerPt ( sp1 sp2 pkpt / segang pkang ang h d )
    (setq segang (angle sp1 sp2)
    pkang (angle sp1 pkpt)
    ang (abs (- segang pkang))
    h (distance sp1 pkpt)
    d (* h (cos ang))
    )
    (polar sp1 segang d)
    )

    Joe Burke
     
    Joe Burke, Jul 20, 2004
    #19
  20. Ken Alexander

    Joe Burke Guest

    Ken,

    I didn't notice your other thread unitl now. Basically the same solution...

    Joe Burke
     
    Joe Burke, Jul 21, 2004
    #20
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.