Bill Tillman Posted June 25, 2017 Share Posted June 25, 2017 I'm using some selected points to do some LISP programming. But I seem to keep running into inaccuracies with the code. If you check the attached drawing you'll see that the white line at the bottom will return (cadr pt1) and (cadr pt2) are equal. But if you check the blue line right below it (cadr pt1) and (cadr pt2) are not equal...even though AutoCAD is reporting they are. pt1 is the left endpoint of the lines and pt2 is the right endpoint of the lines. When I examine the variance between the points on the lowest (blue) line, it's very small, like -6.76792e-013. ??? LinePropIssue.dwg Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 25, 2017 Share Posted June 25, 2017 Interesting that other points are not exact when looking at the co-ords 24.4999999 not 24.50000000 its like a creeping error. How are you doing your polar angles are you using say (/ pi 2.0) v's a 1.57....... Quote Link to comment Share on other sites More sharing options...
Bill Tillman Posted June 25, 2017 Author Share Posted June 25, 2017 Hey BIGAL, nice to hear from you. This is one which I cannot pin down. I created the line as part of a template file I'm using for handrails. How I did it is not recalled as it happened several weeks ago but I'm willing to wager at least a few bucks that I just drew it using the mouse with ORTHO on. I have tested this several times using this same method as well as using "@12 Okay, now let me expand on that LISP code and see if that explains things more clearly. The client I've written this for builds handrails which sometimes are horizontal and sometimes on stairs where they are sloped. The code asks the user to click on two points, which are the intersection of the vertical posts with horizontal rails which support the pickets. Getting this correct with the minimum quantity of pickets evenly spaced along this length is the goal. So when I ask for the inputs I check to see of the 'Y' coordinates are the same. If they are, I execute the code for horizontal spacing. If they are not equal I execute the code for sloped spacing which uses a little trigonometry to work things out. So as you can see, when I compare (cadr pt1) with (cadr pt2) and there's a variance, even on a horizontal line, the wrong code executes. What I see is that sometimes the variance is less than 0, a negative number, and sometimes it's greater than zero, a positive number. But it's always a very small number which AutoCAD uses exponential format to represent, like -6.76792e-013. So if I just check if the difference is not equal to 0 will not suffice. And if I check if the difference is greater than 0 it could still choose the wrong code to execute. Same thing for less than 0. So I'm thinking maybe checking if (RTOS) is not "0" or contains anything but all "0"s. I should also note that when I set the UNITS precision for angles to 8 decimal places, the angle of these squeeky lines indicates 0.00000000, which is obviously not correct and what's making the problem not so easily resolvable. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 26, 2017 Share Posted June 26, 2017 Look at (abs 123.55) (abs -123.55) need only one check then when taking pt1 Y - pt2 Y thats its less than 0.0000001 etc Quote Link to comment Share on other sites More sharing options...
CyberAngel Posted June 26, 2017 Share Posted June 26, 2017 I'd say this falls under the programming category of validating input. The code as written depends on the user drawing perfectly horizontal lines, which (as you've found) doesn't always happen. You could round off the Y coordinate of both points, or you could find the angle and round that off. Using fix(0.5 + Y) gives you the nearest integer. Getting more-precise answers is left as an exercise for the reader. Quote Link to comment Share on other sites More sharing options...
lrm Posted June 26, 2017 Share Posted June 26, 2017 Look at (abs 123.55) (abs -123.55) need only one check then when taking pt1 Y - pt2 Y thats its less than 0.0000001 etc Rather than use an absolute number for the error tolerance I suggest using a percent. E.g., abs((pt1 Y - pt2 Y)/pt1 Y) Also, note that 0.1, 0.01, etc, are irrational numbers in binary which can cause a problem if you are looking to do an exact comparison. Quote Link to comment Share on other sites More sharing options...
Patrick Hughes Posted June 30, 2017 Share Posted June 30, 2017 Rather than using the "=" conditional look into using "EQUAL" which allows you to pass in an accuracy parameter" (if (equal x1 x2 0.00001)) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 30, 2017 Share Posted June 30, 2017 The other option may be to take the line work and round up the end points then update the line co-ords. Do a global over all the dwg or an area. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.