PDA

View Full Version : How to check if a polyline is composed by tangent elements


rudi_favoriti
2009-04-10, 07:08 PM
Hi All,

I need to check if a 2D Polyline is composed by tangents elements.

It may be very useful an Autolisp function that:
1) Cycles trough the Polyline elements
2) Calculates the tangent of every element (when i found an arc, I need to find the tangent at Start Point and at the End Point)
3) Compares the End's tangent of current element with the Start's tangent of the next element
4) Check if the difference of two consecutive tangent is minus of an Epsilon
5) If not, it may be useful to draw a visible point, or circle where the tangent is missed, to help to fix the problem

For now, I'm unable to retrive the Start angle and the End angle of an Arc, useful to find the tangents.

Your helps are much appreciated.
Thanks in advance.

P.S. I'm trying to do it by myself but I'm a Lisp newby.

rudi_favoriti
2009-04-11, 12:40 AM
I'm trying some code founded elsewhere to try to understand:

(defun c:TANPOLY ( / Poly Vl-Obj #Vertex Index Dist )
(setq Poly (entsel "Seletc the polyline : " ) )
(vl-load-com)
(setq Vl-Obj (vlax-ename->vla-object (car Poly )) )
(setq #Vertex (fix (vlax-curve-getEndParam Vl-Obj )) )
(setq Index 0 )
(repeat #Vertex
(setq
FDCurr (vlax-curve-getFirstDeriv Vl-Obj Index)
SDCurr (vlax-curve-getSecondDeriv Vl-Obj Index)
)
(setq ang3 (angle '(0 0 0) FDCurr))
(setq ang4 (angle '(0 0 0) SDCurr))

(princ (strcat "\n N° " (itoa Index) " angFD (" (angtos ang3 0) ")"))
(princ (strcat "\n N° " (itoa Index) " angSD (" (angtos ang4 0) ")"))

(setq Index (1+ Index ) )
)
(princ)
)

When the Index points to a line, the getFirstDeriv coincides to line's tangent, when the Index points to an Arc I am unable to find the Tangent at Start of the Arc and at end of the Arc.

Please, What kind of code I have to call ??

Thanks!!!!!!!

'gile'
2009-04-11, 09:49 AM
Hi,

You can compare the FirstDeriv before and after (but very closed to) each vertex:

(equal (angle '(0 0 0) (vlax-curve-getFirstDeriv poly (+ index 1e-014)))
(angle '(0 0 0) (vlax-curve-getFirstDeriv poly (- index 1e-014)))
1e-013
)

rudi_favoriti
2009-04-11, 11:09 AM
Thanks a lot, you are a lifesaver!!

Tom Beauford
2009-04-14, 11:26 PM
Try attached routine. LQ is the command. Lists survey type information. Curve information for lwpolylines includes tangent bearings in and out which you can compair to the segments before and after.

It's an old routine, but still useful.

rudi_favoriti
2009-04-16, 01:39 AM
Thanks to all, folks.

I'm quite satisfaied about my first lisp code, so I'm sharing it.

Tom Beauford
2009-04-16, 01:23 PM
Thanks to all, folks.

I'm quite satisfaied about my first lisp code, so I'm sharing it.
You should be nicely done. I modified it to use the TEXTSIZE variable for my preference and added it to my colection. Nothing worse than getting halfway through a project and realizing the alignment is buggy.