Prompt specification
Build or customize the Three.js 3D scene "Force-balanced but rotating pair" 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: Force-balanced but rotating pair
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/force-balanced-but-rotating-pair-x1434
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows static equilibrium of forces and torques. Compare a centered push-pull arrangement with equal opposite forces applied at separated points; show zero resultant force but a nonzero couple in the latter. Stylized solid forms.
Working Three.js Starter (force-balanced-but-rotating-pair-x1434):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Static Equilibrium — Force & Torque</title>
<style>
:root {
--bg: #07111f;
--panel: rgba(12, 24, 40, 0.82);
--panel-border: rgba(157, 190, 222, 0.16);
--text: #edf6ff;
--muted: #91a7bd;
--orange: #ffb454;
--cyan: #55d6ca;
--green: #83efaa;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#stage canvas:active {
cursor: grabbing;
}
.overlay {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.masthead {
position: absolute;
top: 30px;
left: 34px;
width: min(570px, 52vw);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 13px;
color: #a8bdd0;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 2px;
background: var(--cyan);
border-radius: 10px;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 58px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 760;
}
h1 span {
color: var(--orange);
}
.intro {
max-width: 490px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.legend {
position: absolute;
top: 30px;
left: 50%;
display: flex;
gap: 18px;
transform: translateX(-50%);
color: #b6c7d7;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
box-shadow: 0 0 14px currentColor;
}
.dot.orange {
color: var(--orange);
background: var(--orange);
}
.dot.cyan {
color: var(--cyan);
background: var(--cyan);
}
.dot.green {
color: var(--green);
background: var(--green);
}
.controls {
position: absolute;
top: 28px;
right: 28px;
width: 272px;
padding: 17px 18px 16px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(16px);
pointer-events: auto;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
}
.control-heading strong {
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#reset {
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 8px;
padding: 6px 9px;
color: #d7e6f3;
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
#reset:hover {
color: white;
background: rgba(255, 255, 255, 0.11);
}
.control-row + .control-row {
margin-top: 14px;
}
.control-label {
display: flex;
justify-content: space-between;
margin-bottom: 8px;
color: #b9cada;
font-size: 12px;
}
.control-label output {
color: white;
font-weight: 760;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
border-radius: 10px;
appearance: none;
background: linear-gradient(
90deg,
var(--cyan) 0%,
var(--cyan) var(--fill, 50%),
rgba(255, 255, 255, 0.12) var(--fill, 50%),
rgba(255, 255, 255, 0.12) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 3px solid #102031;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(85, 214, 202, 0.55);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #102031;
border-radius: 50%;
background: var(--cyan);
}
.control-note {
margin-top: 13px;
color: #758ca2;
font-size: 10px;
line-height: 1.5;
}
.case-card {
position: absolute;
bottom: 25px;
width: min(390px, 39vw);
padding: 18px 19px 17px;
overflow: hidden;
border: 1px solid var(--panel-border);
border-radius: 17px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(17px);
}
.case-card::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 4px;
height: 100%;
background: var(--green);
}
.case-card.right::after {
background: var(--orange);
}
.case-card.left {
left: 28px;
}
.case-card.right {
right: 28px;
}
.case-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 14px;
}
.case-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 13px;
font-weight: 800;
letter-spacing: 0.035em;
}
.case-letter {
display: grid;
width: 25px;
height: 25px;
place-items: center;
border-radius: 7px;
color: #092015;
background: var(--green);
font-size: 12px;
font-weight: 900;
}
.right .case-letter {
color: #2a1704;
background: var(--orange);
}
.status {
padding: 5px 7px;
border: 1px solid rgba(131, 239, 170, 0.22);
border-radius: 999px;
color: var(--green);
background: rgba(131, 239, 170, 0.07);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.right .status {
border-color: rgba(255, 180, 84, 0.25);
color: var(--orange);
background: rgba(255, 180, 84, 0.07);
}
.equations {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 12px;
}
.equation {
padding: 11px 12px;
border: 1px solid rgba(255, 255, 255, 0.075);
border-radius: 10px;
background: rgba(0, 0, 0, 0.12);
}
.equation small {
display: block;
margin-bottom: 5px;
color: #7890a6;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.equation strong {
font-size: 17px;
letter-spacing: -0.02em;
}
.equation .zero {
color: var(--green);
}
.equation .moment {
color: var(--orange);
}
.case-copy {
margin: 0;
color: #91a7bb;
font-size: 11px;
line-height: 1.55;
}
.case-copy strong {
color: #dce9f4;
font-weight: 700;
}
.hint {
position: absolute;
bottom: 28px;
left: 50%;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
color: #71879a;
background: rgba(7, 17, 31, 0.65);
transform: translateX(-50%);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.vector-label {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 7px;
color: white;
background: rgba(7, 17, 31, 0.86);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
transform: translate(-50%, -50%);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.02em;
pointer-events: none;
white-space: nowrap;
}
.vector-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.vector-label.orange {
color: var(--orange);
}
.vector-label.cyan {
color: var(--cyan);
}
.vector-label.green {
color: var(--green);
}
.vector-label.dim {
padding: 4px 7px;
color: #b6c9d9;
font-size: 9px;
}
@media (max-width: 1050px) {
.legend {
display: none;
}
.masthead {
width: calc(100vw - 350px);
}
.hint {
display: none;
}
}
@media (max-width: 720px) {
.masthead {
top: 18px;
left: 18px;
width: calc(100vw - 220px);
}
.eyebrow {
margin-bottom: 8px;
font-size: 8px;
}
h1 {
font-size: clamp(24px, 6vw, 35px);
}
.intro {
display: none;
}
.controls {
top: 16px;
right: 14px;
width: 185px;
padding: 12px;
border-radius: 12px;
}
.control-heading {
margin-bottom: 10px;
}
.control-heading strong {
font-size: 9px;
}
.control-label {
font-size: 10px;
}
.control-note {
display: none;
}
.case-card {
bottom: 12px;
width: calc(50% - 18px);
padding: 12px;
border-radius: 12px;
}
.case-card.left {
left: 12px;
}
.case-card.right {
right: 12px;
}
.case-top {
align-items: flex-start;
margin-bottom: 9px;
}
.case-title {
font-size: 10px;
}
.case-letter {
width: 21px;
height: 21px;
font-size: 10px;
}
.status {
display: none;
}
.equations {
gap: 5px;
margin-bottom: 7px;
}
.equation {
padding: 8px;
}
.equation strong {
font-size: 13px;
}
.case-copy {
display: none;
}
.vector-label {
padding: 4px 6px;
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="overlay">
<header class="masthead">
<div class="eyebrow">Static mechanics / force & torque</div>
<h1>Same net force.<br /><span>Different torque.</span></h1>
<p class="intro">
Two equal and opposite force pairs produce zero resultant force.
Their point of application determines whether the net moment is also zero.
</p>
</header>
<div class="legend" aria-hidden="true">
<div class="legend-item"><i class="dot orange"></i> +F</div>
<div class="legend-item"><i class="dot cyan"></i> −F</div>
<div class="legend-item"><i class="dot green"></i> equilibrium</div>
</div>
<section class="controls" aria-label="Simulation parameters">
<div class="control-heading">
<strong>Load controls</strong>
<button id="reset" type="button">Reset view</button>
</div>
<div class="control-row">
<label class="control-label" for="force">
<span>Force magnitude</span>
<output id="forceOutput">100 N</output>
</label>
<input id="force" type="range" min="40" max="160" value="100" step="5" />
</div>
<div class="control-row">
<label class="control-label" for="separation">
<span>Force separation</span>
<output id="separationOutput">1.60 m</output>
</label>
<input
id="separation"
type="range"
min="0.80"
max="2.40"
value="1.60"
step="0.05"
/>
</div>
<div class="control-note">
The scene is a static snapshot. Changing the force or arm updates the
vector lengths and the resulting couple.
</div>
</section>
<article class="case-card left">
<div class="case-top">
<div class="case-title">
<span class="case-letter">A</span>
Centered push–pull
</div>
<div class="status">Full equilibrium</div>
</div>
<div class="equations">
<div class="equation">
<small>Resultant force</small>
<strong class="zero">ΣF = 0 N</strong>
</div>
<div class="equation">
<small>Resultant moment</small>
<strong class="zero">ΣM = 0</strong>
</div>
</div>
<p class="case-copy">
Equal and opposite forces share the <strong>same point of application</strong>
and line of action. The moments cancel completely.
</p>
</article>
<article class="case-card right">
<div class="case-top">
<div class="case-title">
<span class="case-letter">B</span>
Separated force pair
</div>
<div class="status">Torque unbalanced</div>
</div>
<div class="equations">
<div class="equation">
<small>Resultant force</small>
<strong class="zero">ΣF = 0 N</strong>
</div>
<div class="equation">
<small>Couple moment</small>
<strong class="moment" id="momentValue">ΣM = 160 N·m</strong>
</div>
</div>
<p class="case-copy">
The forces are still equal and opposite, but their <strong>parallel lines
of action are separated</strong>. Their moments add to a nonzero couple.
</p>
</article>
<div class="hint">Drag to orbit · scroll to zoom · double-click to reset</div>
</div>
<div id="labels" aria-hidden="true">
<div id="leftPlus" class="vector-label orange">+F = 100 N</div>
<div id="leftMinus" class="vector-label cyan">−F = 100 N</div>
<div id="rightPlus" class="vector-label orange">+F = 100 N</div>
<div id="rightMinus" class="vector-label cyan">−F = 100 N</div>
<div id="momentLabel" class="vector-label orange">M = Fd</div>
<div id="separationLabel" class="vector-label dim">d = 1.60 m</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of centered and separated force pairs"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.026);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraState = {
theta: 0.25,
phi: 1.12,
radius: 15.5,
target: new THREE.Vector3(0, 1.15, 0),
dragging: false,
lastX: 0,
lastY: 0
};
function fittedRadius() {
const aspect = window.innerWidth / window.innerHeight;
return 15.5 * Math.max(1, 1.08 / aspect);
}
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.theta = 0.25;
cameraState.phi = 1.12;
cameraState.radius = fittedRadius();
updateCamera();
}
resetCamera();
// -------------------------------------------------------------------------
// Lighting and materials
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xa9d8ff, 0x0b1420, 1.5));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-4, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x49d9d0, 1.8);
rimLight.position.set(7, 4, -7);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffaa55, 22, 20, 2);
warmLight.position.set(5, 4, 6);
scene.add(warmLight);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x081421,
roughness: 0.88,
metalness: 0.08
}),
platform: new THREE.MeshStandardMaterial({
color: 0x102131,
roughness: 0.5,
metalness: 0.38
}),
platformTop: new THREE.MeshStandardMaterial({
color: 0x142b3e,
roughness: 0.42,
metalness: 0.28
}),
body: new THREE.MeshStandardMaterial({
color: 0x294a65,
roughness: 0.38,
metalness: 0.28
}),
bodyDark: new THREE.MeshStandardMaterial({
color: 0x12283a,
roughness: 0.58,
metalness: 0.2
}),
stem: new THREE.MeshStandardMaterial({
color: 0x1c394f,
roughness: 0.4,
metalness: 0.5
}),
orange: new THREE.MeshStandardMaterial({
color: 0xffb454,
emissive: 0xff8a20,
emissiveIntensity: 0.16,
roughness: 0.3,
metalness: 0.22
}),
cyan: new THREE.MeshStandardMaterial({
color: 0x55d6ca,
emissive: 0x1a8f88,
emissiveIntensity: 0.16,
roughness: 0.3,
metalness: 0.22
}),
green: new THREE.MeshStandardMaterial({
color: 0x83efaa,
emissive: 0x2baa61,
emissiveIntensity: 0.16,
roughness: 0.3,
metalness: 0.2
}),
neutral: new THREE.MeshStandardMaterial({
color: 0x7890a3,
roughness: 0.5,
metalness: 0.25
}),
edge: new THREE.LineBasicMaterial({
color: 0x9fc3df,
transparent: true,
opacity: 0.23
})
};
// -------------------------------------------------------------------------
// Ground and pedestals
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 26),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.07;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x214059, 0x132a3c);
grid.position.y = -0.055;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
const leftRig = new THREE.Group();
const rightRig = new THREE.Group();
leftRig.position.x = -4.15;
rightRig.position.x = 4.15;
scene.add(leftRig, rightRig);
function createPedestal(parent, accentMaterial) {
const base = new THREE.Mesh(
new THREE.CylinderGeometry(2.72, 2.82, 0.18, 64),
materials.platform
);
base.position.y = 0.02;
base.receiveShadow = true;
base.castShadow = true;
parent.add(base);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(2.52, 2.62, 0.08, 64),
materials.platformTop
);
top.position.y = 0.15;
top.receiveShadow = true;
parent.add(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(2.58, 0.025, 10, 96),
accentMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.205;
parent.add(ring);
}
createPedestal(leftRig, materials.green);
createPedestal(rightRig, materials.orange);
// -------------------------------------------------------------------------
// Left apparatus: a solid body with a centered, collinear force pair
// -------------------------------------------------------------------------
const leftBody = new THREE.Group();
leftRig.add(leftBody);
const leftStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.28, 0.38, 0.42, 32),
materials.stem
);
leftStem.position.y = 0.39;
leftStem.castShadow = true;
leftBody.add(leftStem);
const leftBlockGeometry = new THREE.BoxGeometry(2.15, 1.58, 1.22);
const leftBlock = new THREE.Mesh(leftBlockGeometry, materials.body);
leftBlock.position.y = 1.31;
leftBlock.castShadow = true;
leftBlock.receiveShadow = true;
leftBody.add(leftBlock);
const leftEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(leftBlockGeometry),
materials.edge
);
leftEdges.position.copy(leftBlock.position);
leftBody.add(leftEdges);
const leftFace = new THREE.Mesh(
new THREE.BoxGeometry(1.68, 1.14, 0.055),
materials.bodyDark
);
leftFace.position.set(0, 1.31, 0.635);
leftBody.add(leftFace);
const centerMarker = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.25, 0.07, 40),
materials.green
);
centerMarker.rotation.x = Math.PI / 2;
centerMarker.position.set(0, 1.31, 0.69);
leftBody.add(centerMarker);
const centerRing = new THREE.Mesh(
new THREE.TorusGeometry(0.31, 0.025, 12, 48),
materials.green
);
centerRing.position.set(0, 1.31, 0.735);
leftBody.add(centerRing);
const leftForces = new THREE.Group();
leftRig.add(leftForces);
// -------------------------------------------------------------------------
// Dynamic right apparatus
// -------------------------------------------------------------------------
const rightDynamic = new THREE.Group();
rightRig.add(rightDynamic);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function clearGeometry(group) {
while (group.children.length) {
const child = group.children[0];
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
});
group.remove(child);
}
}
function createForceArrow(direction, length, material, origin) {
const arrow = new THREE.Group();
arrow.position.copy(origin);
if (direction < 0) {
arrow.rotation.y = Math.PI;
}
const headLength = Math.min(0.42, length * 0.2);
const shaftLength = length - headLength;
const shaftGeometry = new THREE.CylinderGeometry(
0.065,
0.065,
shaftLength,
20
);
shaftGeometry.rotateZ(-Math.PI / 2);
const shaft = new THREE.Mesh(shaftGeometry, material);
shaft.position.x = shaftLength * 0.5;
shaft.castShadow = true;
arrow.add(shaft);
const headGeometry = new THREE.ConeGeometry(0.19, headLength, 24);
headGeometry.rotateZ(-Math.PI / 2);
const head = new THREE.Mesh(headGeometry, material);
head.position.x = shaftLength + headLength * 0.5;
head.castShadow = true;
arrow.add(head);
const collarGeometry = new THREE.TorusGeometry(0.09, 0.022, 10, 24);
const collar = new THREE.Mesh(collarGeometry, material);
collar.rotation.y = Math.PI / 2;
collar.position.x = 0.025;
arrow.add(collar);
const tip = new THREE.Object3D();
tip.position.x = length;
arrow.add(tip);
arrow.userData.tip = tip;
return arrow;
}
function createTorqueArc(centerY, radius) {
const group = new THREE.Group();
const points = [];
const start = 2.05;
const end = -2.05;
for (let i = 0; i <= 64; i++) {
const t = i / 64;
const angle = THREE.MathUtils.lerp(start, end, t);
points.push(
new THREE.Vector3(
Math.cos(angle) * radius,
centerY + Math.sin(angle) * radius,
1.08
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const tube = new THREE.Mesh(
new THREE.TubeGeometry(curve, 90, 0.028, 10, false),
materials.orange
);
tube.castShadow = true;
group.add(tube);
const endAngle = end;
const tangent = new THREE.Vector3(
Math.sin(endAngle),
-Math.cos(endAngle),
0
).normalize();
const headLength = 0.34;
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.145, headLength, 22),
materials.orange
);
head.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
head.position
.copy(points[points.length - 1])
.addScaledVector(tangent, -headLength * 0.34);
head.castShadow = true;
group.add(head);
const labelAnchor = new THREE.Object3D();
labelAnchor.position.set(radius + 0.16, centerY + 0.18, 1.1);
group.add(labelAnchor);
group.userData.labelAnchor = labelAnchor;
return group;
}
// -------------------------------------------------------------------------
// Parameters and assembly rebuilding
// -------------------------------------------------------------------------
let forceValue = 100;
let separationValue = 1.6;
const anchors = {
leftPlus: null,
leftMinus: null,
rightPlus: null,
rightMinus: null,
moment: null,
separation: null
};
function arrowLength() {
return 2.05 + ((forceValue - 40) / 120) * 0.5;
}
function rebuildLeftForces() {
clearGeometry(leftForces);
const length = arrowLength();
const origin = new THREE.Vector3(0, 1.31, 0.78);
const plus = createForceArrow(1, length, materials.orange, origin);
const minus = createForceArrow(-1, length, materials.cyan, origin);
leftForces.add(plus, minus);
anchors.leftPlus = plus.userData.tip;
anchors.leftMinus = minus.userData.tip;
}
function rebuildRightAssembly() {
clearGeometry(rightDynamic);
const separationWorld = separationValue * 1.18;
const bodyHeight = separationWorld + 1.02;
const centerY = 1.52;
const topY = centerY + separationWorld * 0.5;
const bottomY = centerY - separationWorld * 0.5;
const length = arrowLength();
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.3, 0.4, 0.4, 32),
materials.stem
);
stem.position.y = 0.38;
stem.castShadow = true;
rightDynamic.add(stem);
const bodyGeometry = new THREE.BoxGeometry(1.38, bodyHeight, 1.14);
const body = new THREE.Mesh(bodyGeometry, materials.body);
body.position.y = centerY;
body.castShadow = true;
body.receiveShadow = true;
rightDynamic.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(bodyGeometry),
materials.edge
);
edges.position.y = centerY;
rightDynamic.add(edges);
const face = new THREE.Mesh(
new THREE.BoxGeometry(1.02, bodyHeight * 0.76, 0.05),
materials.bodyDark
);
face.position.set(0, centerY, 0.59);
rightDynamic.add(face);
const topPad = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.2, 0.07, 32),
materials.orange
);
topPad.rotation.x = Math.PI / 2;
topPad.position.set(0, topY, 0.65);
rightDynamic.add(topPad);
const bottomPad = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.2, 0.07, 32),
materials.cyan
);
bottomPad.rotation.x = Math.PI / 2;
bottomPad.position.set(0, bottomY, 0.65);
rightDynamic.add(bottomPad);
const topArrow = createForceArrow(
1,
length,
materials.orange,
new THREE.Vector3(0, topY, 0.73)
);
const bottomArrow = createForceArrow(
-1,
length,
materials.cyan,
new THREE.Vector3(0, bottomY, 0.73)
);
rightDynamic.add(topArrow, bottomArrow);
anchors.rightPlus = topArrow.userData.tip;
anchors.rightMinus = bottomArrow.userData.tip;
// Dimension line showing the perpendicular separation d.
const dimensionX = 1.02;
const dimensionZ = 1.18;
const dimension = new THREE.Mesh(
new THREE.CylinderGeometry(
0.012,
0.012,
separationWorld,
10
),
materials.neutral
);
dimension.position.set(dimensionX, centerY, dimensionZ);
rightDynamic.add(dimension);
const tickGeometry = new THREE.BoxGeometry(0.22, 0.018, 0.018);
const topTick = new THREE.Mesh(tickGeometry, materials.neutral);
topTick.position.set(dimensionX, topY, dimensionZ);
const bottomTick = new THREE.Mesh(tickGeometry, materials.neutral);
bottomTick.position.set(dimensionX, bottomY, dimensionZ);
rightDynamic.add(topTick, bottomTick);
const separationAnchor = new THREE.Object3D();
separationAnchor.position.set(dimensionX + 0.1, centerY, dimensionZ);
rightDynamic.add(separationAnchor);
anchors.separation = separationAnchor;
const torque = createTorqueArc(
centerY,
Math.max(1.08, separationWorld * 0.61)
);
rightDynamic.add(torque);
anchors.moment = torque.userData.labelAnchor;
}
// -------------------------------------------------------------------------
// DOM synchronization
// -------------------------------------------------------------------------
const forceInput = document.getElementById("force");
const separationInput = document.getElementById("separation");
const forceOutput = document.getElementById("forceOutput");
const separationOutput = document.getElementById("separationOutput");
const momentValue = document.getElementById("momentValue");
const labels = {
leftPlus: document.getElementById("leftPlus"),
leftMinus: document.getElementById("leftMinus"),
rightPlus: document.getElementById("rightPlus"),
rightMinus: document.getElementById("rightMinus"),
moment: document.getElementById("momentLabel"),
separation: document.getElementById("separationLabel")
};
function setRangeFill(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 updateReadouts() {
const moment = forceValue * separationValue;
forceOutput.textContent = `${forceValue.toFixed(0)} N`;
separationOutput.textContent = `${separationValue.toFixed(2)} m`;
momentValue.textContent = `ΣM = ${moment.toFixed(0)} N·m`;
const forceText = `${forceValue.toFixed(0)} N`;
labels.leftPlus.textContent = `+F = ${forceText}`;
labels.leftMinus.textContent = `−F = ${forceText}`;
labels.rightPlus.textContent = `+F = ${forceText}`;
labels.rightMinus.textContent = `−F = ${forceText}`;
labels.moment.textContent = `M = Fd = ${moment.toFixed(0)} N·m`;
labels.separation.textContent = `d = ${separationValue.toFixed(2)} m`;
}
function updateParameters() {
forceValue = Number(forceInput.value);
separationValue = Number(separationInput.value);
setRangeFill(forceInput);
setRangeFill(separationInput);
updateReadouts();
rebuildLeftForces();
rebuildRightAssembly();
}
forceInput.addEventListener("input", updateParameters);
separationInput.addEventListener("input", updateParameters);
setRangeFill(forceInput);
setRangeFill(separationInput);
rebuildLeftForces();
rebuildRightAssembly();
updateReadouts();
// -------------------------------------------------------------------------
// Custom camera controls — no external control modules
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
cameraState.dragging = true;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.lastX;
const dy = event.clientY - cameraState.lastY;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.35,
1.42
);
updateCamera();
});
function endDrag(event) {
cameraState.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.012,
8.5,
45
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Projected DOM labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function positionLabel(element, anchor, offsetX = 0, offsetY = 0) {
if (!anchor) {
element.style.display = "none";
return;
}
anchor.getWorldPosition(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateLabels() {
positionLabel(labels.leftPlus, anchors.leftPlus, 0, -12);
positionLabel(labels.leftMinus, anchors.leftMinus, 0, -12);
positionLabel(labels.rightPlus, anchors.rightPlus, 0, -14);
positionLabel(labels.rightMinus, anchors.rightMinus, 0, -14);
positionLabel(labels.moment, anchors.moment, 22, 0);
positionLabel(labels.separation, anchors.separation, 30, 0);
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
const oldFit = Math.max(1, 1.08 / (window.innerWidth / window.innerHeight));
const newFit = Math.max(1, 1.08 / (window.innerWidth / window.innerHeight));
cameraState.radius *= newFit / oldFit;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```