Last active
May 13, 2019 12:51
-
-
Save bobbzorzen/ddd1e805c87614617393a2343b766a7d to your computer and use it in GitHub Desktop.
Find the corner position of a rotade rectangle in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rotation variable is the rotation of the rect in radians | |
// rectWidth is the width of the rectangle in question | |
// rectX is the x position of the top left most corner of the rectangle | |
// rectY is the y position of the top left most corner of the rectangle | |
const rotatedXDelta = rectWidth * Math.cos(rotation); | |
const rotatedYDelta = rectWidth * Math.sin(rotation); | |
const rotatedX = rectX + rotatedXDelta; | |
const rotatedY = rectY + rotatedYDelta; | |
// Based on a top left most rotational origo this will give the position of the top right most corner of the rectangle |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment