lpseifert Posted April 1, 2010 Share Posted April 1, 2010 I'm trying to test if a segment of a polyline is a curve or a straight section using the following code. Could someone explain to me why this sometimes returns nil on a straight section? When evaluated the difference is small (e.g. 2.84217e-014) but it doesn't evaluate to zero. (zerop (- (abs (distance (vlax-curve-getPointAtParam obj (1- idx))(vlax-curve-getPointAtParam obj idx))) (abs (- (vlax-curve-getDistAtParam obj (1- idx))(vlax-curve-getDistAtParam obj idx))) ) ) Quote Link to comment Share on other sites More sharing options...
jammie Posted April 1, 2010 Share Posted April 1, 2010 Although someone may say differently I would use the vlax-curve-getSecondDeriv for this exercise A return value of 0 indicates a straight segment, anything else is a curve (angle (vlax-curve-getSecondDeriv obj idx) (list 0 0 0)) Its been a while since I've used calculus thou.. For a bit more info see http://en.wikipedia.org/wiki/Second_derivative Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 1, 2010 Share Posted April 1, 2010 Nice one Jammie Quote Link to comment Share on other sites More sharing options...
SEANT Posted April 1, 2010 Share Posted April 1, 2010 With regard to general Floating-Point Calculations 2.84217e-014 is below the tolerance level so should be considered zero. See the link attached to Post # 7 here: http://www.cadtutor.net/forum/showthread.php?t=43500 Using vlax-curve-getSecondDeriv does sound like a sensible course of action, but that result, too, may need to be compared to a tolerance if the return is not an explicit 0. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 1, 2010 Share Posted April 1, 2010 Perhaps use: (equal (angle '(0 0 0) (vlax-curve-getSecondDeriv obj idx)) 0.0 1e- Quote Link to comment Share on other sites More sharing options...
jammie Posted April 1, 2010 Share Posted April 1, 2010 Nice one Jammie Thanks Lee Quote Link to comment Share on other sites More sharing options...
SEANT Posted April 1, 2010 Share Posted April 1, 2010 Perhaps use: (equal (angle '(0 0 0) (vlax-curve-getSecondDeriv obj idx)) 0.0 1e- That looks pretty good. Quote Link to comment Share on other sites More sharing options...
lpseifert Posted April 1, 2010 Author Share Posted April 1, 2010 Thanks guys... I guess instead of (zerop I could use (equal with a fuzz factor to compare the two equations in my example. But I'll try the SecondDeriv. 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.