Reputation: 879
I have a Path that intersects with another Path. Paper.js can give me points of intersection of these paths. Next, I need to get a segment of one path from one point of intersection to another. Example on the picture:
How can I get it using paper.js?
Upvotes: 2
Views: 1863
Reputation: 4650
You can use Path.Line constructor to create a line between 2 points.
Here is a Sketch drawing a line between 2 circles intersections.
// 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'
});
Upvotes: 1