我需要了解该组所有元素的区域。有现成的解决方案吗?也许你知道不包括拼版的区域?
window.canvas = new fabric.Canvas('fabriccanvas');
var circle1 = new fabric.Circle({
radius: 50,
fill: 'red',
left: 0
});
var Rect = new fabric.Rect({
left: 50,
top: 50,
height: 20,
width: 20,
fill: 'green'
});
var circle2 = new fabric.Circle({
radius: 20,
fill: 'black',
left: 70,
top: 80
});
var group = new fabric.Group([ circle1, circle2, Rect ], {});
window.canvas.add(group);
答案 0 :(得分:0)
VINET,
没有预定义的功能,您必须自己构建。这是如何计算组中圆圈和矩形的面积的简短示例(如上所述):
var groupArea = 0;
group.forEachObject(function(o){
groupArea += calculateArea(o);
});
function calculateArea(obj){
switch (obj.type){
case 'circle':
return Math.PI*obj.radius*obj.radius;
break;
case 'rect':
return obj.width*obj.height;
break;
}
}
alert(groupArea);
这篇文章是如何计算多边形区域:Calculating Polygon Area
这篇文章适用于三角区:Calculate triangle area and circumference from user input sides
希望它会对你有帮助。