Skip to content

Instantly share code, notes, and snippets.

@trurl-master
Created November 20, 2021 18:04
Show Gist options
  • Save trurl-master/9bf947716c950683f42347ede66f0215 to your computer and use it in GitHub Desktop.
Save trurl-master/9bf947716c950683f42347ede66f0215 to your computer and use it in GitHub Desktop.
Calculate rotated bounding box size
export function rotateSize(width: number, height: number, rotation: number): { width: number, height: number } {
const rotRad = (rotation * Math.PI) / 180
return {
width: Math.abs(Math.cos(rotRad) * width) + Math.abs(Math.sin(rotRad) * height),
height: Math.abs(Math.sin(rotRad) * width) + Math.abs(Math.cos(rotRad) * height),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment