我有一个 Path 与另一个 Path 相交。 Paper.js可以给我这些路径的交点。接下来,我需要从一个交叉点到另一个交叉点获得一条路径。图片示例:
如何使用paper.js获取它?
答案 0 :(得分:1)
您可以使用Path.Line构造函数在2点之间创建一条线。
这是Sketch,在2个圆交点之间画一条线。
// draw 2 circles
// one red
var redCircle = new Path.Circle({
center : view.center,
radius : 50,
strokeColor: 'red'
});
// one blue
var blueCircle = redCircle.clone();
blueCircle.strokeColor = 'blue';
blueCircle.position += [ 50, 0 ];
// get intersection points
var intersections = redCircle.getIntersections(blueCircle);
var point1 = intersections[ 0 ].point;
var point2 = intersections[ 1 ].point;
// draw a black circle at both intersections
var intersection1Circle = new Path.Circle({
center : point1,
radius : 5,
strokeColor: 'black'
});
var intersection2Circle = intersection1Circle.clone();
intersection2Circle.position = point2;
// draw a line between intersections
var intersectionsJoinLine = new Path.Line({
from : point1,
to : point2,
strokeColor: 'black'
});