Dynamic intersection of two "line2p" obbjects - mkraska/meclib GitHub Wiki

How to make a "crosshair" snap to the intersection point of two "line2p"?

image

This is the object specification:

[
    [ "grid", "","", -1,5,-1,4, 40, [1,1], [2,2] ],
    ["line2p","1",[3,0],[2,0],"n1"],
    ["line2p","2",[1,2],[1.5,0], "n2"],
    [ "crosshair", "", [1,1] ]
]

Add the following at the end of the meclib code:

const sectStyle = {fillOpacity:0, withLabel:false}
targets.push(board.create('intersection', [objects[1].g, objects[2].g, 0], sectStyle));
targets.push(board.create('intersection', [objects[1].n, objects[2].g, 0], sectStyle));
targets.push(board.create('intersection', [objects[1].g, objects[2].n, 0], sectStyle));
targets.push(board.create('intersection', [objects[1].n, objects[2].n, 0], sectStyle));
objects[3].p.setAttribute({snapToPoints:true})
  1. Intersection is created between the line objects
  2. Intersection is appended to the targets list (objects to whom control points snap)
  3. The control point of the crosshair is set to snap to points (default snapping is only to lines).