TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: XXL1966 on May 04, 2013, 01:12:33 PM

Hello,
i need a function that projects points on a polyline within a certain distance and determine the side of the points on the polyline.
The first step is easy by using the vlaxcurvegetClosestPointTo, next compute the distance between point and projection and compare with given distance. As for the side. Is there a ready to use function in (v)lisp to do this ? For a straight segmented polyline i could determine the segment the point is projected on (but how ?) and then compute the area of the triangle between segment and projection point (area will be + or ).
Just curious if anyone else already solved this problem or maybe knows an easy way to do this...
thanks !

Maybe this will help?
http://www.theswamp.org/index.php?topic=40416.0 (http://www.theswamp.org/index.php?topic=40416.0)

For straight segments you can also test the whether the sine of the angle between the segment and given point is positive or negative:
(sin ( (angle <segment
start
> <given
point
>) (angle <segment
start
> <segment
end
>)))
If the above is positive, the point lies to the left of the segment; if negative, to the right.

thx for the fast replies. But i still need the segment the point is projected on, this doesn't result from vlaxcurvegetClosestPointTo. Is there a VLISP function that results the segment with a given point (result of vlaxcurvegetClosestPointTo) on the curve ?

But i still need the segment the point is projected on, this doesn't result from vlaxcurvegetClosestPointTo. Is there a VLISP function that results the segment with a given point (result of vlaxcurvegetClosestPointTo) on the curve ?
Retrieving the segment is relatively easy:
(defun c:test
( / en pa pt
) )
)
)
)
)

thx !
will have a look into this VLAX functions.

Here is a quick draft of a possible program for this task:
(defun c:sidetest
( / en p1 p2 pa pt
) )
)
)
)
(alert (strcat "\nPoint is on " (whichside? pt p1 p2
) " of polyline.")) )
)
)
(defun whichside?
( givenpoint point1 point2
) "RIGHT"
"LEFT"
)
)

(entmake (list '(0 . "POINT") (cons 10 (vlaxcurvegetpointatparam en (fix pa)))))
(entmake (list '(0 . "POINT") (cons 10 (vlaxcurvegetpointatparam en (1+ (fix pa))))))
Bad programmer, bad (http://otb.manusoft.com/2013/01/quirkypolylineexposingfoolishprogrammers.htm).

ah, the master pops up everywhere ;)
with quirky polylines you mean like having identical vertices etc ?

with quirky polylines you mean like having identical vertices etc ?
Lee's code assumes that vertex parameters are (consecutive) integers, which is not guaranteed.

Actually, I think that code may have a more significant problem with edgecases involving polyines that are not parallel to the UCS XY plane.
(vlaxcurvegetParamAtPoint (vlaxcurvegetClosestPointTo (cadr (entsel "\nPick polyline: "))))
will not necessarily give the correct result if the polyline is not in the XY plane of the current UCS.
The pick point returned by (entsel) is always in the UCS XY plane, making it viewdependent, which means that it may only appear to be closer to the desired vertex in the current view projection, but can actually be closer to another vertex.
AFAIK, the correct and only completelyreliable way to acquire a vertex is via (ssget ":S") and (ssnamex)