Dev Helpers
← Back

Rotated bounding box

Import and render <RotatedBoundingBox /> in a React project.

Open this example in the interactive library

Live preview

Source code

// components/RotatedBoundingBox.tsx

import { useState } from "react";

export default function RotatedBoundingBox({
  width = 12,
  height = 8,
}: { width?: number; height?: number } = {}) {
  const [a, set] = useState(0);
  const r = (a * Math.PI) / 180;
  return (
    <label>
      Angle
      <input type="range" max={90} value={a} onChange={(e) => set(+e.target.value)} />
      <output>
        {(width * Math.cos(r) + height * Math.sin(r)).toFixed(1)} ×{" "}
        {(width * Math.sin(r) + height * Math.cos(r)).toFixed(1)}
      </output>
    </label>
  );
}