Find the coordinates of the corners of a rotated object in fabricjs

Suppose I have an image in a fabricjs canvas. I can easily calculate the coordinates of the corners based on the image's top & left values, and its size.

How can I do so when the image is rotated by any degree?


enter image description here

EDIT: Preferably without the use of trigonometry, if there is a simpler method implemented in fabricjs itself or somewhere else.



Yes, of course.

We store those coordinates in object's oCoords, // top left corner, // top right corner, // bottom left corner, // bottom right corner

That's what gets set when you call setCoords method.

But you probably don't want to mess with those.

Since version ~1.0.4, we have getBoundingRect method on all objects, which returns { left: ..., top: ..., width: ..., height: ... }. We already had getBoundingRectWidth and getBoundingRectHeight before (now deprecated) but getBoundingRect is certainly more useful; it allows to read left/top values as well.

You can see it in action at (try rotating objects)



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.