Home › Forums › Problems and solutions in GDL › Object design › Detecting Line Intersection › Reply To: Detecting Line Intersection
March 21, 2019 at 09:31
#4618
Keymaster
Hi,
There is a call (gosub) to “LineLineIntersection” in the 3D script. The input variables are set up before the call.
vx, vy is computed from two points (_intersectEdge[1] and _intersectEdge[2]) on the line, divided by the distance of the two points:
! line 1
vx1 = (_intersectEdge[2][1] - _intersectEdge[1][1]) / _intersectEdgeLength
vy1 = (_intersectEdge[2][2] - _intersectEdge[1][2]) / _intersectEdgeLength
px, py is any point on the line:
px1 = _intersectEdge[1][1]
py1 = _intersectEdge[1][2]
This is done again for the second line:
! line 2
vx2 = (_intersectEdgeLeft[2][1] - _intersectEdgeLeft[1][1]) / _intersectEdgeLeftLength
vy2 = (_intersectEdgeLeft[2][2] - _intersectEdgeLeft[1][2]) / _intersectEdgeLeftLength
px2 = _intersectEdgeLeft[1][1]
py2 = _intersectEdgeLeft[1][2]
The result intersection is ipx, ipy, when state = 1 (otherwise the lines are parallel):
gosub "LineLineIntersection" ! returns ipx, ipy, state
if state <> 0 then
_intersectPtLeft[1] = ipx
_intersectPtLeft[2] = ipy
endif
Péter Baksa
Library Platform, Software Engineer
GRAPHISOFT SE