trimmed lines not vertical

Discussion in 'AutoCAD' started by GhettoGumby, Aug 4, 2004.

  1. GhettoGumby

    GhettoGumby Guest

    I found this problem after writing some code that relys on checking the endpoints of a line to determine if they are vertical or horizontal. If both x-components of the points are equal, its vertical. It works fine unless the line has been trimmed (or extended). Basically this is really annoying and I am wondering if anyone else has run into this and if there is a way to work around it. This is in 2005 by the way.... and trim worked fine when I tested it in R14 but extend had the same problem. Here is the code I used to test this....

    (setq pt1 (getpoint "Pick First Point: "))
    (setq pt2 (getpoint "Pick Second Point: "))

    (if (= (car pt2) (car pt1)) "VERTICAL" "NOT VERTICAL")

    P.S. Same problem when checking horizontal lines
     
    GhettoGumby, Aug 4, 2004
    #1
  2. GhettoGumby

    mataeux Guest

    when trim computes a new endpoint, the result is accurate to 8 decimal
    places you are comparing the two numbers at 16 decimal places, use (equal x1
    x2 0.00000001)






    endpoints of a line to determine if they are vertical or horizontal. If
    both x-components of the points are equal, its vertical. It works fine
    unless the line has been trimmed (or extended). Basically this is really
    annoying and I am wondering if anyone else has run into this and if there is
    a way to work around it. This is in 2005 by the way.... and trim worked
    fine when I tested it in R14 but extend had the same problem. Here is the
    code I used to test this....
     
    mataeux, Aug 4, 2004
    #2
  3. You may want to use the fuzz option of the (equal) function:

    (Defun c:cp ()
    (setq pt1 (getpoint "Pick First Point: "))
    (setq pt2 (getpoint "Pick Second Point: "))
    (if (equal (print (car pt2)) (print (car pt1)) 0.0001) "VERTICAL" "NOT VERTICAL")
    )
     
    Allen Johnson, Aug 4, 2004
    #3
  4. GhettoGumby

    GhettoGumby Guest

    Ahhhhh, thank you very much you guys. Figures it was something to do with precision.
     
    GhettoGumby, Aug 4, 2004
    #4
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.