Paolo Posted July 20, 2009 Share Posted July 20, 2009 I need to get the first intersection point (if any) of a polyline with a given line (extended if needed) via VectorScript. I have tried to use the Split2DObjectByLine procedure, but it seems not reliable. Here's the script. To test it, draw a polyline, then a line, run the script and select first the poly then the line. A point should be placed at their intersection. Not always it works. Sometimes it even crashes VectorWorks : procedure lineToPoly; VAR polyHandle: handle; lineHandle: handle; punto :Point; function intersectionLinePoly(lineH, polyH: Handle): Point; VAR tmpPolyH, tmpLineH : handle; begPt : point; endPt: point; resultHandle, temp_h: handle; BEGIN {faccio copia della linea} tmpPolyH := CreateDuplicateObject(polyH, NIL); tmpLineH := CreateDuplicateObject(lineH, NIL); GetSegPt1(tmpLineH, begPt.x, begPt.y); HScale2D(tmpLineH, begPt.x, begPt.y, 10,10,false); GetSegPt2(tmpLineH, endPt.x, endPt.y); Split2DObjectByLine(tmpPolyH, begPt.x, begPt.y, endPt.x, endPt.y, resultHandle); IF resultHandle <> NIL THEN BEGIN GetPolyPt(resultHandle, getVertNum(resultHandle), intersectionLinePoly.x, intersectionLinePoly.y); END; delObject(tmpLineH); delObject(tmpPolyH); END; begin GetPt(punto.x, punto.y); polyHandle:= PickObject(punto.x, punto.y); GetPt(punto.x, punto.y); lineHandle:= PickObject(punto.x, punto.y); punto := intersectionLinePoly(lineHandle, polyHandle); if not ((punto.x = 0) and (punto.y = 0)) then locus(punto.x, punto.y); end; run(lineToPoly); Is there a more reliable way to get this? Thank you in advance for your help. Quote Link to comment
MullinRJ Posted July 21, 2009 Share Posted July 21, 2009 Ciao Paolo, ???I noticed you are scaling your temp_Line from SegPt1 (begPt). If you don't draw the line correctly it will scale away from your polyline. Try scaling from the center point of the line. You also might need a bigger scale factor, 20x or 100x, to make sure your line and poly cross. ???GetSegPt1(tmpLineH, begPt.x, begPt.y); ???GetSegPt2(tmpLineH, endPt.x, endPt.y); ???P := (BegPt + EndPt) / 2;??????{ save midpoint of temp_Line in temp_point P } ???HScale2D(tmpLineH, P.x, P.y, 10, 10, false); ???GetSegPt1(tmpLineH, begPt.x, begPt.y);?????{ get new begPt } ???GetSegPt2(tmpLineH, endPt.x, endPt.y);?????{ get new endPt } You could also use procedure LineLineIntersection in a loop with each segment of the poly if you want to catch all intersections. Use the "intOnLines" boolean value that is returned by the procedure to test for an intersection. HTH, Raymond Quote Link to comment
Paolo Posted July 21, 2009 Author Share Posted July 21, 2009 Thank for your answer, Raymond, Ok to scale the line from midpoint, but the problem is elsewhere. LineLineIntersection is good for polygons, not for polyline with curved strokes, as far as I know, Split2DObjectByLine is the natural way, but it sometimes fails ( read here in the VectorScript Function Reference, annotated version) . Paolo Quote Link to comment
Miguel Barrera Posted July 21, 2009 Share Posted July 21, 2009 With polylines I would convert it first to a polygon with a 64 resolution or higher. Depending on how accurate you need to be, this setting has given me acceptable results. I would then use the LineLineIntersection as Raymond stated to find the intersection with each poly segment. Quote Link to comment
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.