Prompt specification
Build or customize the Three.js 3D scene "Support-reaction equilibrium solver" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Support-reaction equilibrium solver
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/support-reaction-equilibrium-solver-x1436
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows static equilibrium of forces and torques. Let users move a load along a simply supported beam; update reaction arrows analytically and clearly mark configurations outside the chosen model's valid support conditions. Low-poly.
Working Three.js Starter (support-reaction-equilibrium-solver-x1436):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Static Equilibrium Lab — Simply Supported Beam</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(9, 20, 34, 0.88);
--panel-strong: rgba(13, 29, 47, 0.96);
--line: rgba(163, 197, 226, 0.16);
--text: #edf6ff;
--muted: #91a8bc;
--cyan: #42d7bd;
--blue: #72a7ff;
--orange: #ffb454;
--red: #ff6174;
--gold: #f8d477;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 15%, rgba(42, 86, 132, 0.28), transparent 38%),
radial-gradient(circle at 20% 80%, rgba(26, 104, 95, 0.17), transparent 42%),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid rgba(173, 207, 236, 0.22);
border-radius: 7px;
background: rgba(6, 15, 27, 0.84);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.22);
color: #eaf5ff;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.025em;
white-space: nowrap;
backdrop-filter: blur(8px);
}
.glass {
border: 1px solid var(--line);
background: linear-gradient(145deg, var(--panel-strong), var(--panel));
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.30),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px) saturate(120%);
}
.brand {
position: fixed;
top: 18px;
left: 18px;
z-index: 10;
width: min(380px, calc(100vw - 36px));
padding: 16px 18px;
border-radius: 14px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 18px;
height: 2px;
background: currentColor;
content: "";
}
h1 {
margin: 0;
font-size: clamp(22px, 2.3vw, 32px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.panel {
position: fixed;
z-index: 10;
border-radius: 15px;
}
.controls {
bottom: 18px;
left: 18px;
width: 340px;
padding: 16px;
}
.balance {
top: 18px;
right: 18px;
width: 375px;
padding: 16px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 13px;
}
.panel-title h2 {
margin: 0;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.mini-button {
padding: 6px 9px;
border: 1px solid rgba(160, 198, 230, 0.18);
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
color: #cfe1f1;
cursor: pointer;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.mini-button:hover {
border-color: rgba(114, 167, 255, 0.52);
background: rgba(114, 167, 255, 0.10);
}
.control-group {
margin-top: 15px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
color: #dceaf6;
font-size: 12px;
font-weight: 650;
}
output {
color: var(--gold);
font-variant-numeric: tabular-nums;
font-weight: 800;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 5px 0 0;
border-radius: 10px;
outline: none;
appearance: none;
background:
linear-gradient(
90deg,
var(--cyan) 0 var(--fill),
rgba(153, 184, 211, 0.18) var(--fill) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid #102238;
border-radius: 50%;
appearance: none;
background: #dff8ff;
box-shadow: 0 0 0 1px rgba(114, 167, 255, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid #102238;
border-radius: 50%;
background: #dff8ff;
box-shadow: 0 0 0 1px rgba(114, 167, 255, 0.55);
}
.range-notes {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #738da3;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
select {
width: 100%;
padding: 9px 11px;
border: 1px solid rgba(161, 195, 224, 0.20);
border-radius: 8px;
outline: none;
background: #11243a;
color: #eaf5ff;
font-size: 12px;
}
select:focus {
border-color: var(--blue);
}
.segmented {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.segmented button {
padding: 9px;
border: 1px solid rgba(159, 193, 221, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.025);
color: #9db3c7;
cursor: pointer;
font-size: 11px;
font-weight: 750;
}
.segmented button.active {
border-color: rgba(248, 212, 119, 0.62);
background: rgba(248, 212, 119, 0.10);
color: var(--gold);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 10px;
}
.button-row button {
padding: 8px;
border: 1px solid rgba(159, 193, 221, 0.18);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
color: #c4d7e7;
cursor: pointer;
font-size: 11px;
font-weight: 700;
}
.button-row button:hover {
background: rgba(114, 167, 255, 0.09);
}
.arc-legend {
display: flex;
gap: 15px;
margin-top: 14px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #94aabd;
font-size: 10px;
}
.arc-legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend-dot {
width: 16px;
height: 3px;
border-radius: 4px;
}
.help {
margin: 11px 1px 0;
color: #7f98ac;
font-size: 10px;
line-height: 1.55;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(66, 215, 189, 0.30);
border-radius: 999px;
background: rgba(66, 215, 189, 0.09);
color: var(--cyan);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
content: "";
}
.status.invalid {
border-color: rgba(255, 97, 116, 0.38);
background: rgba(255, 97, 116, 0.10);
color: var(--red);
}
.status.held {
border-color: rgba(114, 167, 255, 0.38);
background: rgba(114, 167, 255, 0.10);
color: var(--blue);
}
.status-detail {
min-height: 38px;
margin: 10px 0 13px;
color: #9eb3c6;
font-size: 11px;
line-height: 1.45;
}
.reaction-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.reaction-card {
padding: 10px;
border: 1px solid rgba(159, 193, 221, 0.14);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
}
.reaction-head {
display: flex;
align-items: center;
gap: 7px;
color: #d9e9f7;
font-size: 11px;
font-weight: 800;
}
.reaction-head i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
}
.reaction-card.b .reaction-head i {
background: var(--blue);
}
.reaction-value {
margin-top: 7px;
color: #fff;
font-size: 19px;
font-weight: 800;
font-variant-numeric: tabular-nums;
letter-spacing: -0.03em;
}
.reaction-formula {
margin-top: 3px;
color: #758fa5;
font-size: 9px;
font-variant-numeric: tabular-nums;
}
.equations {
margin-top: 13px;
overflow: hidden;
border: 1px solid rgba(159, 193, 221, 0.14);
border-radius: 10px;
}
.equation {
padding: 9px 10px;
border-bottom: 1px solid rgba(159, 193, 221, 0.11);
color: #b8cad9;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-variant-numeric: tabular-nums;
transition: background 160ms ease;
}
.equation:last-child {
border-bottom: 0;
}
.equation.active {
background: rgba(248, 212, 119, 0.075);
color: #f5e7bd;
}
.moment-view {
margin-top: 11px;
padding: 10px;
border-left: 2px solid var(--gold);
border-radius: 0 7px 7px 0;
background: rgba(248, 212, 119, 0.055);
color: #b7c7d5;
font-size: 10px;
line-height: 1.5;
}
.model-rule {
margin-top: 11px;
padding-top: 11px;
border-top: 1px solid var(--line);
color: #7f98ad;
font-size: 10px;
line-height: 1.5;
}
.balance-badge {
color: #79cdb9;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
@media (max-width: 820px) {
.brand {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 12px 14px;
}
.subtitle {
display: none;
}
.balance {
top: 105px;
right: 10px;
width: min(350px, calc(100vw - 20px));
max-height: 40vh;
overflow: auto;
}
.controls {
bottom: 10px;
left: 10px;
width: min(340px, calc(100vw - 20px));
max-height: 46vh;
overflow: auto;
}
}
@media (max-width: 520px) {
.balance {
max-height: 34vh;
}
.controls {
max-height: 43vh;
}
.reaction-value {
font-size: 16px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive three-dimensional simply supported beam"></div>
<div id="labels" aria-hidden="true">
<div id="supportA" class="scene-label">A · PIN</div>
<div id="supportB" class="scene-label">B · ROLLER</div>
<div id="loadLabel" class="scene-label">P = 100 N</div>
<div id="raLabel" class="scene-label">R_A</div>
<div id="rbLabel" class="scene-label">R_B</div>
<div id="lengthLabel" class="scene-label">L = 10.00 m</div>
</div>
<header class="brand glass">
<div class="eyebrow">Static Lab / Equilibrium 01</div>
<h1>Simply Supported Beam</h1>
<p class="subtitle">
Move the point load, inspect signed support reactions, and compare the
force and torque balances about either support.
</p>
</header>
<section class="panel controls glass" aria-label="Beam controls">
<div class="panel-title">
<h2>Control Deck</h2>
<button id="resetView" class="mini-button" type="button">Reset view</button>
</div>
<div class="control-group">
<label class="control-label" for="position">
Load position from A
<output id="positionOut" for="position">5.00 m</output>
</label>
<input id="position" type="range" min="-3" max="13" step="0.01" value="5">
<div class="range-notes">
<span>−3 m</span>
<span>A = 0 m</span>
<span>B = 10 m</span>
<span>13 m</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="load">
Point load P
<output id="loadOut" for="load">100 N</output>
</label>
<input id="load" type="range" min="25" max="250" step="1" value="100">
<div class="range-notes">
<span>25 N</span>
<span>Downward</span>
<span>250 N</span>
</div>
</div>
<div class="control-group">
<label class="control-label" for="supportModel">Support idealization</label>
<select id="supportModel">
<option value="contact">Contact-only supports — uplift invalid</option>
<option value="bilateral">Hold-down capable — bilateral reactions</option>
</select>
</div>
<div class="control-group">
<div class="control-label">Moment / torque reference</div>
<div class="segmented" role="group" aria-label="Moment reference support">
<button id="pivotA" class="active" type="button">About A</button>
<button id="pivotB" type="button">About B</button>
</div>
</div>
<div class="button-row">
<button id="centerLoad" type="button">Center load</button>
<button id="moveLeft" type="button">Move outside left</button>
</div>
<div class="arc-legend">
<span>
<i class="legend-dot" style="background:#72a7ff"></i>
Reaction moment
</span>
<span>
<i class="legend-dot" style="background:#ffb454"></i>
Load moment
</span>
</div>
<p class="help">
Drag the load directly in the scene. Drag elsewhere to orbit, scroll to
zoom, and double-click to reset the camera.<br>
Model: rigid, massless beam; point load; pin and roller; no support moments.
</p>
</section>
<section class="panel balance glass" aria-label="Equilibrium analysis">
<div class="panel-title">
<h2>Free-Body Balance</h2>
<span id="balanceBadge" class="balance-badge">MATHEMATICALLY BALANCED</span>
</div>
<div id="status" class="status">Valid support state</div>
<p id="statusDetail" class="status-detail" aria-live="polite"></p>
<div class="reaction-grid">
<div class="reaction-card">
<div class="reaction-head"><i></i>Reaction at A</div>
<div id="raValue" class="reaction-value">50.0 N</div>
<div id="raFormula" class="reaction-formula">P(L − a) / L</div>
</div>
<div class="reaction-card b">
<div class="reaction-head"><i></i>Reaction at B</div>
<div id="rbValue" class="reaction-value">50.0 N</div>
<div id="rbFormula" class="reaction-formula">Pa / L</div>
</div>
</div>
<div class="equations" aria-label="Equilibrium equations">
<div id="eqFy" class="equation">ΣF_y = 0</div>
<div id="eqMA" class="equation active">ΣM_A = 0</div>
<div id="eqMB" class="equation">ΣM_B = 0</div>
</div>
<div id="momentView" class="moment-view"></div>
<div id="modelRule" class="model-rule"></div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Model and constants
// -------------------------------------------------------------------------
const L = 10; // Support span, meters
const BEAM_LENGTH = 16; // Includes visible overhangs
const BEAM_Y = 2.35;
const BEAM_HEIGHT = 0.46;
const BEAM_TOP = BEAM_Y + BEAM_HEIGHT / 2;
const LEFT_SUPPORT = -L / 2;
const RIGHT_SUPPORT = L / 2;
const LOAD_BODY_HEIGHT = 0.94;
const LOAD_TOP = BEAM_TOP + 1.04;
const FORCE_SCALE = 0.012; // World units per newton
const COLORS = {
cyan: 0x42d7bd,
blue: 0x72a7ff,
orange: 0xffb454,
red: 0xff6174,
gold: 0xf8d477,
beam: 0xc99045,
floor: 0x091827
};
const ui = {
position: document.querySelector("#position"),
load: document.querySelector("#load"),
positionOut: document.querySelector("#positionOut"),
loadOut: document.querySelector("#loadOut"),
supportModel: document.querySelector("#supportModel"),
pivotA: document.querySelector("#pivotA"),
pivotB: document.querySelector("#pivotB"),
centerLoad: document.querySelector("#centerLoad"),
moveLeft: document.querySelector("#moveLeft"),
resetView: document.querySelector("#resetView"),
status: document.querySelector("#status"),
statusDetail: document.querySelector("#statusDetail"),
balanceBadge: document.querySelector("#balanceBadge"),
raValue: document.querySelector("#raValue"),
rbValue: document.querySelector("#rbValue"),
raFormula: document.querySelector("#raFormula"),
rbFormula: document.querySelector("#rbFormula"),
eqFy: document.querySelector("#eqFy"),
eqMA: document.querySelector("#eqMA"),
eqMB: document.querySelector("#eqMB"),
momentView: document.querySelector("#momentView"),
modelRule: document.querySelector("#modelRule"),
supportA: document.querySelector("#supportA"),
supportB: document.querySelector("#supportB"),
loadLabel: document.querySelector("#loadLabel"),
raLabel: document.querySelector("#raLabel"),
rbLabel: document.querySelector("#rbLabel"),
lengthLabel: document.querySelector("#lengthLabel")
};
const state = {
a: 5,
P: 100,
model: "contact",
pivot: "A"
};
let RA = 50;
let RB = 50;
let loadArrowLength = 1.2;
let loadArrowTailY = LOAD_TOP + loadArrowLength;
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(COLORS.floor, 27, 58);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 1.65, 0);
const spherical = new THREE.Spherical(24, 1.08, 0.42);
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.30, 1.46);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 12, 34);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetCamera() {
spherical.set(24, 1.08, 0.42);
updateCamera();
}
updateCamera();
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
} catch (error) {
document.body.innerHTML = `
<div style="padding:40px;font:16px system-ui;color:white">
WebGL could not be initialized. Please use a browser with WebGL enabled.
</div>`;
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Three-dimensional beam equilibrium scene");
renderer.domElement.style.cursor = "grab";
document.querySelector("#scene").appendChild(renderer.domElement);
scene.add(new THREE.HemisphereLight(0xc9e5ff, 0x102031, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff0d9, 3.1);
keyLight.position.set(8, 15, 11);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -15;
keyLight.shadow.camera.right = 15;
keyLight.shadow.camera.top = 15;
keyLight.shadow.camera.bottom = -15;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x6fa9ff, 1.7);
rimLight.position.set(-10, 7, -9);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Environment and beam
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: COLORS.floor,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.025;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(44, 44, 0x284258, 0x172c3f);
grid.position.y = -0.015;
grid.material.transparent = true;
grid.material.opacity = 0.45;
scene.add(grid);
const beam = new THREE.Mesh(
new THREE.BoxGeometry(BEAM_LENGTH, BEAM_HEIGHT, 0.84, 8, 1, 1),
new THREE.MeshStandardMaterial({
color: COLORS.beam,
roughness: 0.55,
metalness: 0.22,
flatShading: true
})
);
beam.position.y = BEAM_Y;
beam.castShadow = true;
beam.receiveShadow = true;
scene.add(beam);
// A thin top strip makes the beam silhouette clearer.
const beamTopStrip = new THREE.Mesh(
new THREE.BoxGeometry(BEAM_LENGTH, 0.035, 0.88),
new THREE.MeshStandardMaterial({
color: 0xe0b96b,
roughness: 0.52,
metalness: 0.15
})
);
beamTopStrip.position.y = BEAM_TOP + 0.005;
scene.add(beamTopStrip);
// -------------------------------------------------------------------------
// Low-poly supports
// -------------------------------------------------------------------------
function createWedgeGeometry(width, height, depth) {
const w = width / 2;
const d = depth / 2;
const positions = [
-w, 0, -d, w, 0, -d, 0, height, -d,
-w, 0, d, w, 0, d, 0, height, d
];
const indices = [
3, 4, 5,
0, 2, 1,
0, 3, 5, 0, 5, 2,
1, 2, 5, 1, 5, 4,
0, 1, 4, 0, 4, 3
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createSupport(x, color, roller = false) {
const group = new THREE.Group();
group.position.x = x;
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.46,
metalness: 0.38,
flatShading: true
});
const wedge = new THREE.Mesh(
createWedgeGeometry(1.25, 1.62, 1.02),
material
);
wedge.position.y = 0.16;
wedge.castShadow = true;
wedge.receiveShadow = true;
group.add(wedge);
const base = new THREE.Mesh(
new THREE.BoxGeometry(1.75, 0.16, 1.38),
new THREE.MeshStandardMaterial({
color: 0x355069,
roughness: 0.72,
metalness: 0.28
})
);
base.position.y = 0.08;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
if (roller) {
for (const dx of [-0.38, 0.38]) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.38, 10),
new THREE.MeshStandardMaterial({
color: 0x9fb4c8,
roughness: 0.28,
metalness: 0.72,
flatShading: true
})
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(dx, 1.94, 0);
wheel.castShadow = true;
group.add(wheel);
}
} else {
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.16, 1.12, 10),
new THREE.MeshStandardMaterial({
color: 0xc8d8e6,
roughness: 0.24,
metalness: 0.78,
flatShading: true
})
);
pin.rotation.x = Math.PI / 2;
pin.position.y = 1.96;
pin.castShadow = true;
group.add(pin);
}
scene.add(group);
return { group, material, baseColor: color };
}
const supportA = createSupport(LEFT_SUPPORT, COLORS.cyan, false);
const supportB = createSupport(RIGHT_SUPPORT, COLORS.blue, true);
// -------------------------------------------------------------------------
// Movable load
// -------------------------------------------------------------------------
const loadGroup = new THREE.Group();
loadGroup.position.y = BEAM_TOP;
scene.add(loadGroup);
const loadHitMeshes = [];
const loadBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.50, 0.50, LOAD_BODY_HEIGHT, 6),
new THREE.MeshStandardMaterial({
color: COLORS.orange,
roughness: 0.44,
metalness: 0.18,
flatShading: true
})
);
loadBody.position.y = LOAD_BODY_HEIGHT / 2;
loadBody.castShadow = true;
loadGroup.add(loadBody);
loadHitMeshes.push(loadBody);
const loadCap = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.34, 0.12, 6),
new THREE.MeshStandardMaterial({
color: 0x273a4f,
roughness: 0.42,
metalness: 0.58,
flatShading: true
})
);
loadCap.position.y = LOAD_BODY_HEIGHT + 0.055;
loadCap.castShadow = true;
loadGroup.add(loadCap);
loadHitMeshes.push(loadCap);
const loadRing = new THREE.Mesh(
new THREE.TorusGeometry(0.55, 0.025, 6, 24),
new THREE.MeshBasicMaterial({
color: COLORS.orange,
transparent: true,
opacity: 0.65
})
);
loadRing.rotation.x = Math.PI / 2;
loadRing.position.y = 0.025;
loadGroup.add(loadRing);
const weightBarMaterial = new THREE.MeshStandardMaterial({
color: 0x1b2b3d,
roughness: 0.72,
metalness: 0.08
});
for (const dx of [-0.19, 0, 0.19]) {
const bar = new THREE.Mesh(
new THREE.BoxGeometry(0.065, 0.55, 0.035),
weightBarMaterial
);
bar.position.set(dx, 0.50, 0.505);
loadGroup.add(bar);
loadHitMeshes.push(bar);
}
// -------------------------------------------------------------------------
// Force arrows
// -------------------------------------------------------------------------
function createArrow() {
const group = new THREE.Group();
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 1, 8),
new THREE.MeshStandardMaterial({
color: COLORS.cyan,
roughness: 0.34,
metalness: 0.25
})
);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.15, 0.34, 8),
new THREE.MeshStandardMaterial({
color: COLORS.cyan,
roughness: 0.34,
metalness: 0.25,
flatShading: true
})
);
group.add(shaft, head);
scene.add(group);
return { group, shaft, head };
}
const loadArrow = createArrow();
const reactionArrowA = createArrow();
const reactionArrowB = createArrow();
const UP = new THREE.Vector3(0, 1, 0);
const DOWN = new THREE.Vector3(0, -1, 0);
function setArrow(arrow, start, direction, length, color) {
arrow.group.visible = length > 0.0001;
if (!arrow.group.visible) return;
const headLength = Math.min(0.34, Math.max(0.10, length * 0.28));
const shaftLength = Math.max(0.001, length - headLength);
arrow.shaft.scale.y = shaftLength;
arrow.shaft.position.y = shaftLength / 2;
arrow.head.scale.y = headLength / 0.34;
arrow.head.position.y = shaftLength + headLength / 2;
arrow.shaft.material.color.set(color);
arrow.head.material.color.set(color);
arrow.group.position.copy(start);
arrow.group.quaternion.setFromUnitVectors(
UP,
direction.clone().normalize()
);
}
// -------------------------------------------------------------------------
// Dimension line
// -------------------------------------------------------------------------
const dimensionMaterial = new THREE.LineBasicMaterial({
color: 0x6c8ca5,
transparent: true,
opacity: 0.72
});
const dimensionPoints = [
new THREE.Vector3(LEFT_SUPPORT, 0.55, 1.25),
new THREE.Vector3(RIGHT_SUPPORT, 0.55, 1.25)
];
const dimensionLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(dimensionPoints),
dimensionMaterial
);
scene.add(dimensionLine);
for (const x of [LEFT_SUPPORT, RIGHT_SUPPORT]) {
const tick = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(x, 0.38, 1.25),
new THREE.Vector3(x, 0.72, 1.25)
]),
dimensionMaterial
);
scene.add(tick);
}
// -------------------------------------------------------------------------
// Support-state indicators
// -------------------------------------------------------------------------
const invalidZone = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.52, 0.94),
new THREE.MeshBasicMaterial({
color: COLORS.red,
transparent: true,
opacity: 0.12,
depthWrite: false
})
);
invalidZone.position.y = BEAM_Y;
invalidZone.visible = false;
scene.add(invalidZone);
function createUpliftRing(x) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.39, 0.035, 6, 24),
new THREE.MeshBasicMaterial({
color: COLORS.red,
transparent: true,
opacity: 0.8,
depthTest: false
})
);
ring.position.set(x, 1.30, 1.12);
ring.visible = false;
ring.renderOrder = 9;
scene.add(ring);
return ring;
}
const upliftRingA = createUpliftRing(LEFT_SUPPORT);
const upliftRingB = createUpliftRing(RIGHT_SUPPORT);
const pivotMarker = new THREE.Mesh(
new THREE.TorusGeometry(0.48, 0.022, 6, 28),
new THREE.MeshBasicMaterial({
color: COLORS.gold,
transparent: true,
opacity: 0.72,
depthTest: false
})
);
pivotMarker.position.z = 1.15;
pivotMarker.renderOrder = 8;
scene.add(pivotMarker);
// -------------------------------------------------------------------------
// Moment/torque arcs
// -------------------------------------------------------------------------
const momentGroup = new THREE.Group();
scene.add(momentGroup);
function clearMomentGroup() {
while (momentGroup.children.length) {
const child = momentGroup.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => material.dispose());
}
});
}
}
function addMomentArc(sign, radius, color) {
if (Math.abs(sign) < 1e-9) return;
const pivotX = state.pivot === "A" ? LEFT_SUPPORT : RIGHT_SUPPORT;
const centerY = 1.28;
const z = 1.18;
const counterClockwise = sign > 0;
const start = counterClockwise ? -0.23 * Math.PI : 0.23 * Math.PI;
const end =
start + (counterClockwise ? 1 : -1) * 1.43 * Math.PI;
const points = [];
const segments = 48;
for (let i = 0; i <= segments; i++) {
const t = start + (end - start) * (i / segments);
points.push(
new THREE.Vector3(
pivotX + Math.cos(t) * radius,
centerY + Math.sin(t) * radius,
z
)
);
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
line.renderOrder = 10;
momentGroup.add(line);
const tangent = new THREE.Vector3(
-Math.sin(end),
Math.cos(end),
0
).multiplyScalar(counterClockwise ? 1 : -1).normalize();
const arrowHead = new THREE.Mesh(
new THREE.ConeGeometry(0.115, 0.31, 6),
new THREE.MeshBasicMaterial({
color,
depthTest: false
})
);
arrowHead.position.copy(points[points.length - 1]);
arrowHead.quaternion.setFromUnitVectors(UP, tangent);
arrowHead.renderOrder = 11;
momentGroup.add(arrowHead);
}
function updateMoments() {
clearMomentGroup();
let reactionMoment;
let loadMoment;
let reactionName;
let loadName;
if (state.pivot === "A") {
reactionMoment = RB * L;
loadMoment = -state.P * state.a;
reactionName = "R_B · L";
loadName = "P · a";
} else {
reactionMoment = -RA * L;
loadMoment = state.P * (L - state.a);
reactionName = "R_A · L";
loadName = "P · (L − a)";
}
addMomentArc(reactionMoment, 0.72, COLORS.blue);
addMomentArc(loadMoment, 1.00, COLORS.orange);
pivotMarker.position.x =
state.pivot === "A" ? LEFT_SUPPORT : RIGHT_SUPPORT;
}
// -------------------------------------------------------------------------
// Analytical update
// -------------------------------------------------------------------------
function formatForce(value) {
if (Math.abs(value) < 0.05) return "0";
return value < 0 ? `(${value.toFixed(1)})` : value.toFixed(1);
}
function formatSignedForce(value) {
if (Math.abs(value) < 0.05) return "0.0";
return value.toFixed(1);
}
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateSupportAppearance(negativeA, negativeB) {
const contactOnly = state.model === "contact";
const configure = (support, negative) => {
support.material.color.set(
negative
? (contactOnly ? COLORS.red : COLORS.blue)
: support.baseColor
);
support.material.emissive.set(
negative
? (contactOnly ? COLORS.red : COLORS.blue)
: 0x000000
);
support.material.emissiveIntensity = negative ? 0.24 : 0;
};
configure(supportA, negativeA);
configure(supportB, negativeB);
upliftRingA.visible = negativeA;
upliftRingB.visible = negativeB;
upliftRingA.material.color.set(contactOnly ? COLORS.red : COLORS.blue);
upliftRingB.material.color.set(contactOnly ? COLORS.red : COLORS.blue);
}
function updateAll() {
state.a = Number(ui.position.value);
state.P = Number(ui.load.value);
state.model = ui.supportModel.value;
// Exact analytic reactions for a point load on a simply supported span.
RA = state.P * (L - state.a) / L;
RB = state.P * state.a / L;
const negativeA = RA < -1e-7;
const negativeB = RB < -1e-7;
const outsideContactRange = negativeA || negativeB;
const contactOnly = state.model === "contact";
const loadX = LEFT_SUPPORT + state.a;
loadGroup.position.x = loadX;
// Point-load arrow.
loadArrowLength = state.P * FORCE_SCALE;
loadArrowTailY = LOAD_TOP + 0.04 + loadArrowLength;
setArrow(
loadArrow,
new THREE.Vector3(loadX, loadArrowTailY, 0.52),
DOWN,
loadArrowLength,
COLORS.orange
);
// Support reaction arrows.
const lengthA = Math.abs(RA) * FORCE_SCALE;
const lengthB = Math.abs(RB) * FORCE_SCALE;
setArrow(
reactionArrowA,
new THREE.Vector3(LEFT_SUPPORT, BEAM_TOP + 0.03, 0.78),
RA >= 0 ? UP : DOWN,
lengthA,
negativeA && contactOnly ? COLORS.red : COLORS.cyan
);
setArrow(
reactionArrowB,
new THREE.Vector3(RIGHT_SUPPORT, BEAM_TOP + 0.03, 0.78),
RB >= 0 ? UP : DOWN,
lengthB,
negativeB && contactOnly ? COLORS.red : COLORS.blue
);
// Red overlay on the unsupported overhang when the chosen model is invalid.
invalidZone.visible = contactOnly && outsideContactRange;
if (invalidZone.visible) {
let zoneLength;
let midpoint;
if (state.a < 0) {
zoneLength = -state.a;
midpoint = (loadX + LEFT_SUPPORT) / 2;
} else {
zoneLength = state.a - L;
midpoint = (loadX + RIGHT_SUPPORT) / 2;
}
invalidZone.scale.x = Math.max(0.001, zoneLength);
invalidZone.position.x = midpoint;
}
updateSupportAppearance(negativeA, negativeB);
updateMoments();
// UI values.
ui.positionOut.textContent = `${state.a.toFixed(2)} m`;
ui.loadOut.textContent = `${state.P.toFixed(0)} N`;
ui.raValue.textContent = `${formatSignedForce(RA)} N`;
ui.rbValue.textContent = `${formatSignedForce(RB)} N`;
ui.raFormula.textContent = `P(${L.toFixed(1)} − ${state.a.toFixed(2)}) / ${L.toFixed(1)}`;
ui.rbFormula.textContent = `P(${state.a.toFixed(2)}) / ${L.toFixed(1)}`;
ui.eqFy.textContent =
`ΣF_y = ${formatForce(RA)} + ${formatForce(RB)} − ${formatForce(state.P)} = 0 N`;
ui.eqMA.textContent =
`ΣM_A = R_B L − P a = ${formatForce(RB * L)} − ${formatForce(state.P * state.a)} = 0 N·m`;
ui.eqMB.textContent =
`ΣM_B = P(L − a) − R_A L = ${formatForce(state.P * (L - state.a))} − ${formatForce(RA * L)} = 0 N·m`;
ui.eqMA.classList.toggle("active", state.pivot === "A");
ui.eqMB.classList.toggle("active", state.pivot === "B");
if (state.pivot === "A") {
ui.momentView.textContent =
`About A: R_B·L = ${formatForce(RB * L)} N·m and ` +
`P·a = ${formatForce(state.P * state.a)} N·m act in opposite senses.`;
} else {
ui.momentView.textContent =
`About B: R_A·L = ${formatForce(RA * L)} N·m and ` +
`P·(L − a) = ${formatForce(state.P * (L - state.a))} N·m act in opposite senses.`;
}
// Model-dependent validity.
ui.status.className = "status";
if (contactOnly && outsideContactRange) {
const supportName = negativeA ? "A (pin)" : "B (roller)";
const negativeReaction = negativeA ? RA : RB;
ui.status.classList.add("invalid");
ui.status.textContent = "Outside chosen model";
ui.statusDetail.textContent =
`R = ${Math.abs(negativeReaction).toFixed(1)} N downward at support ` +
`${supportName}. A contact-only support would lift, so this configuration ` +
`is not physically valid for the selected model.`;
ui.balanceBadge.textContent = "MODEL EXCEEDED";
} else if (!contactOnly && outsideContactRange) {
const supportName = negativeA ? "A" : "B";
ui.status.classList.add("held");
ui.status.textContent = "Valid · hold-down required";
ui.statusDetail.textContent =
`The load is outside the ordinary contact span and produces a negative ` +
`reaction at ${supportName}. The selected bilateral model allows this ` +
`only because the support is capable of resisting uplift.`;
ui.balanceBadge.textContent = "MATHEMATICALLY BALANCED";
} else {
ui.status.textContent = "Valid support state";
ui.statusDetail.textContent =
`Both reactions are compressive. The point load is between the ` +
`supports, so the selected support idealization remains valid.`;
ui.balanceBadge.textContent = "MATHEMATICALLY BALANCED";
}
if (contactOnly) {
ui.modelRule.textContent =
`Validity rule: R_A ≥ 0 and R_B ≥ 0. For this massless-beam point-load ` +
`model, the valid range is 0.00 m ≤ a ≤ ${L.toFixed(2)} m. ` +
`The red beam region marks the invalid overhang configuration.`;
} else {
ui.modelRule.textContent =
`Validity rule: both supports are bilateral, so signed vertical ` +
`reactions are allowed. Support moments remain zero. Outside the span, ` +
`a hold-down is required at the support with the negative reaction.`;
}
// Scene labels.
ui.loadLabel.textContent =
`P = ${state.P.toFixed(0)} N ↓ · a = ${state.a.toFixed(2)} m`;
ui.raLabel.textContent =
`R_A = ${formatSignedForce(RA)} N ${RA >= 0 ? "↑" : "↓"}`;
ui.rbLabel.textContent =
`R_B = ${formatSignedForce(RB)} N ${RB >= 0 ? "↑" : "↓"}`;
ui.supportA.textContent =
negativeA
? (contactOnly ? "A · PIN · LIFT" : "A · PIN · TIED")
: "A · PIN";
ui.supportB.textContent =
negativeB
? (contactOnly ? "B · ROLLER · LIFT" : "B · ROLLER · TIED")
: "B · ROLLER";
ui.supportA.style.color =
negativeA
? (contactOnly ? "#ff6174" : "#72a7ff")
: "#42d7bd";
ui.supportB.style.color =
negativeB
? (contactOnly ? "#ff6174" : "#72a7ff")
: "#72a7ff";
ui.raLabel.style.color =
negativeA && contactOnly ? "#ff6174" : "#42d7bd";
ui.rbLabel.style.color =
negativeB && contactOnly ? "#ff6174" : "#72a7ff";
ui.pivotA.classList.toggle("active", state.pivot === "A");
ui.pivotB.classList.toggle("active", state.pivot === "B");
updateRangeFill(ui.position);
updateRangeFill(ui.load);
}
// -------------------------------------------------------------------------
// DOM projection for labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, visible = true) {
if (!visible) {
element.style.display = "none";
return;
}
projected.copy(worldPosition).project(camera);
if (
projected.z < -1 ||
projected.z > 1 ||
Math.abs(projected.x) > 1.25 ||
Math.abs(projected.y) > 1.25
) {
element.style.display = "none";
return;
}
const rect = renderer.domElement.getBoundingClientRect();
const x = rect.left + (projected.x * 0.5 + 0.5) * rect.width;
const y = rect.top + (-projected.y * 0.5 + 0.5) * rect.height;
element.style.display = "block";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
const loadX = LEFT_SUPPORT + state.a;
const signA = RA >= 0 ? 1 : -1;
const signB = RB >= 0 ? 1 : -1;
const lengthA = Math.abs(RA) * FORCE_SCALE;
const lengthB = Math.abs(RB) * FORCE_SCALE;
placeLabel(
ui.supportA,
new THREE.Vector3(LEFT_SUPPORT, 0.28, 1.08)
);
placeLabel(
ui.supportB,
new THREE.Vector3(RIGHT_SUPPORT, 0.28, 1.08)
);
placeLabel(
ui.loadLabel,
new THREE.Vector3(loadX, loadArrowTailY + 0.34, 0.75)
);
placeLabel(
ui.raLabel,
new THREE.Vector3(
LEFT_SUPPORT,
BEAM_TOP + signA * lengthA + 0.34,
0.95
)
);
placeLabel(
ui.rbLabel,
new THREE.Vector3(
RIGHT_SUPPORT,
BEAM_TOP + signB * lengthB + 0.34,
0.95
)
);
placeLabel(
ui.lengthLabel,
new THREE.Vector3(0, 0.52, 1.35)
);
}
// -------------------------------------------------------------------------
// Direct manipulation: load dragging and custom orbit controls
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
const dragPoint = new THREE.Vector3();
let draggingLoad = false;
let orbiting = false;
let dragOffset = 0;
let previousX = 0;
let previousY = 0;
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
updatePointer(event);
const hit = raycaster.intersectObjects(loadHitMeshes, false)[0];
if (hit) {
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
draggingLoad = true;
dragOffset = (LEFT_SUPPORT + state.a) - dragPoint.x;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "ew-resize";
}
} else {
orbiting = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (draggingLoad) {
updatePointer(event);
if (raycaster.ray.intersectPlane(dragPlane, dragPoint)) {
const newX = dragPoint.x + dragOffset;
const newA = THREE.MathUtils.clamp(
newX - LEFT_SUPPORT,
-3,
13
);
ui.position.value = newA.toFixed(2);
updateAll();
}
return;
}
if (orbiting) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
return;
}
updatePointer(event);
const hoveringLoad =
raycaster.intersectObjects(loadHitMeshes, false).length > 0;
renderer.domElement.style.cursor = hoveringLoad ? "ew-resize" : "grab";
});
function endPointer(event) {
draggingLoad = false;
orbiting = false;
renderer.domElement.style.cursor = "grab";
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
// -------------------------------------------------------------------------
// UI events
// -------------------------------------------------------------------------
ui.position.addEventListener("input", updateAll);
ui.load.addEventListener("input", updateAll);
ui.supportModel.addEventListener("change", updateAll);
ui.pivotA.addEventListener("click", () => {
state.pivot = "A";
updateAll();
});
ui.pivotB.addEventListener("click", () => {
state.pivot = "B";
updateAll();
});
ui.centerLoad.addEventListener("click", () => {
ui.position.value = (L / 2).toFixed(2);
updateAll();
});
ui.moveLeft.addEventListener("click", () => {
ui.position.value = "-2.25";
updateAll();
});
ui.resetView.addEventListener("click", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate(time) {
requestAnimationFrame(animate);
const pulse = 0.5 + 0.5 * Math.sin(time * 0.004);
if (invalidZone.visible) {
invalidZone.material.opacity = 0.08 + pulse * 0.11;
}
if (upliftRingA.visible) {
upliftRingA.scale.setScalar(1 + pulse * 0.10);
upliftRingA.material.opacity = 0.65 + pulse * 0.30;
}
if (upliftRingB.visible) {
upliftRingB.scale.setScalar(1 + pulse * 0.10);
upliftRingB.material.opacity = 0.65 + pulse * 0.30;
}
updateLabels();
renderer.render(scene, camera);
}
updateAll();
requestAnimationFrame(animate);
</script>
</body>
</html>
```