【问题标题】:How can I get a segment of a Path between two points using paper.js?如何使用 paper.js 获得两点之间的一段路径?
【发布时间】:2018-06-27 08:58:25
【问题描述】:

我有一个 Path 与另一个 Path 相交。 Paper.js 可以给我这些路径的交点。接下来,我需要从一个交叉点到另一个交叉点获取一条路径的一段。图片上的例子:

如何使用 paper.js 获得它?

【问题讨论】:

  • 不是直接解决这个问题,但是this way可以帮忙

标签: javascript drawing paperjs


【解决方案1】:

您可以使用Path.Line 构造函数在两点之间创建一条线。

这是Sketch 在两个圆的交点之间画一条线。

// 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'
});

【讨论】:

    猜你喜欢
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 2013-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多