【发布时间】:2023-02-24 04:13:50
【问题描述】:
要求:- 让我们举个例子,我们有两个三角形或任何其他形状,我想要两个用一条线连接它们 -
问题:- 我正在获取 boundingRect 坐标并且线没有正确绘制。下图中的线是从第一个对象的 MR 控件绘制到第二个对象的 ML 控件并且没有接触形状的顶点。。
我想在第一张图片中获取形状的坐标,即 (x1,y1),(x2,y2),(x3,y3),(x4,y4) 。 假设在获取这些点之后我可以使用计算来找到我的目标点。 任何其他解决方案或想法将不胜感激。
面料版本 - 面料 5
const fc = new fabric.Canvas("c");
const triangle1Options = {
stroke: 'black',
strokeWidth: 2,
fill: 'red',
left: 10,
top: 10,
width: 100,
height: 100,
}
let triangle1 = new fabric.Triangle(triangle1Options);
fc.add(triangle1);
// Get coords of triangle
/* The below syntax returns => {
height: 102,
left: 10,
top: 10,
width: 102
}
This is the bounding rect of triangle. How to get actual coordinates of the triangle. */
fc.on('selection:created', event => {console.log(event.target.getBoundingRect())});
【问题讨论】: