How can I get four corners coordinates from the transformation matrix? #2260
Replies: 3 comments 13 replies
-
Same question |
Beta Was this translation helpful? Give feedback.
-
there is a mapPoint in Matrix.ts that will give you those coordinates. I believe we use it in this example: https://github.com/Shopify/react-native-skia/tree/main/example/src/Examples/FrostedCard |
Beta Was this translation helpful? Give feedback.
-
@milindsakhare100 @xiaoosnggao If you guys mean getting the xy position of each corner relative to the canvas it's drawn on then it's pretty simple actually:
type Vector = {x: number, y: number};
const rotate2d = (distance: Vector, angle: number): Vector => {
return {
x: distance.x * Math.cos(angle) - distance.y * Math.sin(angle),
y: distance.x * Math.sin(angle) + distance.y * Math.cos(angle)
}
}
Pretty much this how you determine the position of a rotated point in space, actually you can follow any glsl tutorial on rotation and it's the same technique. |
Beta Was this translation helpful? Give feedback.
-
I want to extract 4 corners and center coordinates of the matrix. The bounding box is made up of a transformation matrix using reanimated3 and same used in skia. For reference please look Stickers example of skia.
Beta Was this translation helpful? Give feedback.
All reactions