Jump to content

Test for curve/straight line


lpseifert

Recommended Posts

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)))
           )
        )

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...