Calculate the intersection area of ​​two paths

Only Raphael.pathIntersection(path1, path2) is available in Raphaël , and this method can only get intersection points from these two paths.

I need an intersection area .

As shown below, the method receives only 2 points (marked with red circles). I expect you to have 2 more points (marked with blue circles) to form the path to the intersection area.

Example Chart.

+4
source share
1 answer

Two points should be all you need. However, I'm not sure why you want to cross. Either you need to know the area (width * height), or you need to visualize the intersection. In any case, it is enough to know the two points of the rectangle. I have prepared a small example in case it will be useful to you.

 var p1 = "M100 100 L100 400 L400 400 L400 100 Z", p2 = "M200 200 L200 500 L500 500 L500 200 Z"; var paper = new Raphael(0, 0, 800, 600); paper.path(p1).attr({fill : "red", opacity : 1}); paper.path(p2).attr({fill : "blue", opacity : 0.5}); var points = Raphael.pathIntersection(p1, p2); var w = points[1].x-points[0].x, h = points[0].y-points[1].y; var group = paper.set(); group.push(paper.rect(510, 100, w, h).attr({fill: "yellow"})); group.push(paper.text(610, 150, "The intersection area\nis drawn over here.\n \nWidth: " + w + "\nHeight: " + h)); 
+3
source

Source: https://habr.com/ru/post/1439041/


All Articles