How to get the topmost point of a rotated object? #9402
Replies: 2 comments 4 replies
-
This is a plain JS problem, oCoords are all in canvas html coordinates. const allCoordsEntries = Object.entries(obj.oCoords);
const allYValues = allCoordsEntries.map(([key, point]) => point.y));
const smallerY = Math.min(...allYValues);
const indexOfSmallerY = allYValues.indexOf(smallerY);
const controls = allCoordsEntries[indexOfSmallerY] // in format [key ,value] You repeat at will for the farthest in any direction and once you have 2 points how to calculate the distance is either with one of the available point methods or by doing the point distance alghoritm yourself that you can google anywhere |
Beta Was this translation helpful? Give feedback.
-
yes this make it clear, this is called the xy problem: So to your particular issue i think you can use the object.getBoundingRect That will give you an axis aligned box for the object, with top,left,width and height. In the case of vertical distribution i think you can take all the height and top, and run this kind of logic: the first box is top: 10, height: 50, it makes 60. the second box is top : 40 height : 80, it needs to go to 60 + 80, so add 20 to that oject.top. now you are at at total of 140 and you move with the third box and so on. It should be really that simple. |
Beta Was this translation helpful? Give feedback.
-
Hi,
First of all, I'm working on FabricJS 5.3.1.
I'm trying to get the following things, taking into account the object rotation (angle):
Could u point me in the right direction?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions