Skip to content

Instantly share code, notes, and snippets.

@bobbzorzen
Last active May 13, 2019 12:51
Show Gist options
  • Save bobbzorzen/ddd1e805c87614617393a2343b766a7d to your computer and use it in GitHub Desktop.
Save bobbzorzen/ddd1e805c87614617393a2343b766a7d to your computer and use it in GitHub Desktop.
Find the corner position of a rotade rectangle in javascript
// 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