View Full Version : fix function help
rken.laws
2008-12-18, 08:28 PM
I have 3 lines that are drawn on the same angle and the enpoints connect. They are created by a lisp command so I know they are exact. When I get the XYZ values from the start points and end points they show up the same. For example two of the lines may have the same start Z point of 28.83 which is a real number. When I use an "if" function with "=" it returns nil. I reluctantly worked around that using the "fix" function and they both return an integer of 28 and are now equal. In another circumstance dealing with the angles of two lines one returns a real of 0.0 and the other returns a real of 180.0 which would be ok because if its equal to or greater than 180 I reduce it by 180 so it doesnt matter which way the line starts and ends, but the real that is 180.0 returns 179 when the "fix" function is applied. None of this makes sense. Can anybody explain it to me?
rkmcswain
2008-12-18, 08:44 PM
In your case, forget about (fix) and (=), use the (equal) function and apply a small fuzz factor.
rken.laws
2008-12-18, 08:58 PM
How do you apply a fuzz factor?
rkmcswain
2008-12-18, 10:34 PM
Read up on the (equal) function in the HELP file.
From memory, I think it goes something like this:
;; This compares 1.0 to 1.000001
;; normally this would be FALSE
;; but with a fuzz factor of 0.00001
;; if will equal T
(equal 1.0 1.000001 0.00001)
CAB2k
2008-12-20, 04:05 PM
Another way:
(< (distance pt1 pt2) fuzz)
irneb
2009-01-08, 12:22 PM
I have 3 lines that are drawn on the same angle and the enpoints connect. They are created by a lisp command so I know they are exact.Not necessarily ... how does the lisp function create these? Through entmake or command? If the later you have stuff like osnaps that could cause problems, or also if you specify polar angles instead of exact coordinates inaccuracies can crop up.
Then also if you've rotated / mirrored / etc ... even doing the 3 lines together ... this could cause inaccuracies. AutoCAD doesn't handle angles very well if it comes to "absolute" accuracy ... that's because of its use of Double Precision Floating point values. And there's a known inaccuracy issue using polar tracking.
Try finding the difference between the 2 endpoints, e.g.:;; Say pt1 and pt2 contains the 3d points of each
(setq diff (- (caddr pt1) (caddr pt2))) ;Calculate difference of Z values
(princ (rtos diff 2 16)) ;Print out at 16 decimal placesIf this shows somehing extremely small (e.g. 0.0000000000000001) then there's a floating point error involved and you need to use one of the fuzzy comparison methods described in previous posts. If the error is quite large (e.g. 0.0100000..) then there's something else going on.
rken.laws
2009-01-08, 01:35 PM
Good to know. I do use "command" "rotate" and "mirror" in the lisp routine. The inaccuracy is fine for the drawing but the fuzz is needed in almost every case. Thanks guys.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.