import React, { useState } from "react"; const CompositeSolidsWidget: React.FC = () => { const [isMerged, setIsMerged] = useState(false); const [w, setW] = useState(60); const [h, setH] = useState(80); const [d, setD] = useState(60); // Surface Area Calcs const singleSA = 2 * (w * h + w * d + h * d); const hiddenFaceArea = d * h; const totalSeparateSA = singleSA * 2; const mergedSA = totalSeparateSA - 2 * hiddenFaceArea; // Helper to generate a face style const getFaceStyle = ( width: number, height: number, transform: string, color: string, ) => ({ width: `${width}px`, height: `${height}px`, position: "absolute" as const, left: "50%", top: "50%", marginLeft: `-${width / 2}px`, marginTop: `-${height / 2}px`, transform: transform, backgroundColor: color, border: "1px solid rgba(255,255,255,0.3)", display: "flex", alignItems: "center", justifyContent: "center", backfaceVisibility: "hidden" as const, // Hide backfaces for cleaner look if opaque transition: "all 0.5s", }); // Prism Component const Prism = ({ positionX, baseHue, highlightSide, // 'left' or 'right' indicates the face to highlight red }: { positionX: number; baseHue: "indigo" | "sky"; highlightSide?: "left" | "right"; }) => { // Define shades based on hue // Lighting: Top is lightest, Front is base, Side is darkest const colors = baseHue === "indigo" ? { top: "#818cf8", front: "#6366f1", side: "#4f46e5" } // Indigo 400, 500, 600 : { top: "#38bdf8", front: "#0ea5e9", side: "#0284c7" }; // Sky 400, 500, 600 const hiddenColor = "#f43f5e"; // Rose 500 return (
{/* Front (w x h) */}
{/* Back (w x h) - usually hidden but good for completeness */}
{/* Right (d x h) */}
{highlightSide === "right" && ( FACE )}
{/* Left (d x h) */}
{highlightSide === "left" && ( FACE )}
{/* Top (w x d) */}
{/* Bottom (w x d) */}
); }; // Gap Logic const gap = isMerged ? 0 : 40; const posLeft = -(w / 2 + gap / 2); const posRight = w / 2 + gap / 2; return (

The "Hidden Face" Trap

{/* 3D Scene */}
{/* Container rotated for Isometric-ish view */}
{/* Left Prism (Indigo) - Right face hidden */} {/* Right Prism (Sky) - Left face hidden */}

Dimensions

Width (w) {w}
setW(parseInt(e.target.value))} className="w-full h-1 bg-slate-200 rounded-lg appearance-none cursor-pointer accent-indigo-600" />
Height (h) {h}
setH(parseInt(e.target.value))} className="w-full h-1 bg-slate-200 rounded-lg appearance-none cursor-pointer accent-indigo-600" />
Depth (d) {d}
setD(parseInt(e.target.value))} className="w-full h-1 bg-slate-200 rounded-lg appearance-none cursor-pointer accent-indigo-600" />
Total Surface Area
{isMerged ? mergedSA : totalSeparateSA}
{isMerged ? "⬇ Area decreased (Faces Hidden)" : "Sum of 2 separated prisms"}
Hidden Area Calculation
2 × ({d}×{h})
= {2 * hiddenFaceArea} lost
); }; export default CompositeSolidsWidget;