Jump to content
Developer Wiki and Function Reference Links Read more... ×
Sign in to follow this  

Divide a polyline by a line

Recommended Posts

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;


polyHandle: handle;

lineHandle: handle;

punto :Point;

function intersectionLinePoly(lineH, polyH: Handle): Point;


tmpPolyH, tmpLineH : handle;

begPt : point;

endPt: point;

resultHandle, temp_h: handle;


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






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



Is there a more reliable way to get this?

Thank you in advance for your help.

Share this post

Link to post

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.



Share this post

Link to post

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.

Share this post

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114


© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.