Jump to content
Developer Wiki and Function Reference Links ×

Divide a polyline by a line


Paolo

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;

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.

Link to comment

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

Link to comment

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