Dynamic intersection of two "line2p" obbjects - mkraska/meclib GitHub Wiki
How to make a "crosshair" snap to the intersection point of two "line2p"?
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})
- Intersection is created between the line objects
- Intersection is appended to the
targets
list (objects to whom control points snap) - The control point of the crosshair is set to snap to points (default snapping is only to lines).