Prompt specification
Build or customize the Three.js 3D scene "Rope Marker With Two Opposing Arrows" 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: Rope Marker With Two Opposing Arrows
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/rope-marker-with-two-opposing-arrows-x3673
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a low-poly rope with a central marker and opposing force arrows. Stretch the rope between two handles, labeling the leftward and rightward forces separately. A third indicator shows their vector sum as one force changes, including equal magnitudes with zero resultant. The central band is only a position reference, not a force sensor. Show the external supports clearly and avoid moving the marker as though its displacement directly measures force.
Working Three.js Starter (rope-marker-with-two-opposing-arrows-x3673):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rope Force Balance — Three.js</title>
<style>
:root {
color-scheme: dark;
--bg: #07111d;
--panel: rgba(12, 25, 40, 0.94);
--line: rgba(177, 207, 232, 0.16);
--text: #edf6ff;
--muted: #91a8bd;
--left: #5ddcff;
--right: #ff987a;
--net: #ffd166;
--zero: #d9e4ee;
}
* {
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;
}
#viewport {
position: fixed;
inset: 0 388px 0 0;
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, #10263a 0%, #091725 42%, #07111d 78%);
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene:active {
cursor: grabbing;
}
#worldLabels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
top: 0;
left: 0;
min-width: 122px;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-left-width: 3px;
border-radius: 9px;
background: rgba(7, 17, 29, 0.86);
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(9px);
opacity: 0;
text-align: left;
white-space: nowrap;
transition: opacity 140ms ease;
will-change: transform;
}
.world-label.visible {
opacity: 1;
}
.world-label .kicker {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
}
.world-label strong {
display: block;
font-size: 14px;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.world-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
#label-left {
border-left-color: var(--left);
}
#label-left strong {
color: var(--left);
}
#label-right {
border-left-color: var(--right);
}
#label-right strong {
color: var(--right);
}
#label-result {
border-left-color: var(--net);
}
#label-result strong {
color: var(--net);
}
#label-center {
border-left-color: #dbe7f1;
min-width: 180px;
}
#label-center strong {
font-size: 12px;
}
.support-label {
min-width: 0;
padding: 6px 9px;
border-left-color: #6f879d;
opacity: 0;
color: #c2d0dd;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.08em;
}
.support-label.visible {
opacity: 0.9;
}
.scene-heading {
position: absolute;
top: 22px;
left: 24px;
pointer-events: none;
}
.scene-heading span {
display: block;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
}
.scene-heading strong {
display: block;
margin-top: 4px;
font-size: 18px;
font-weight: 650;
letter-spacing: -0.02em;
}
.axis-key {
position: absolute;
left: 24px;
bottom: 22px;
display: flex;
align-items: center;
gap: 11px;
color: var(--muted);
font-size: 11px;
pointer-events: none;
}
.axis-key .axis {
display: flex;
align-items: center;
gap: 5px;
color: #dce9f4;
font-weight: 700;
}
.axis-key .arrow {
color: var(--net);
font-size: 20px;
line-height: 1;
}
.camera-hint {
position: absolute;
right: 20px;
bottom: 22px;
color: rgba(185, 205, 221, 0.62);
font-size: 10px;
pointer-events: none;
}
#panel {
position: fixed;
top: 16px;
right: 16px;
bottom: 16px;
width: 356px;
overflow: auto;
padding: 23px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.4),
inset 0 1px rgba(255, 255, 255, 0.03);
backdrop-filter: blur(18px);
}
.eyebrow {
color: var(--net);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
}
h1 {
margin: 8px 0 8px;
font-size: 29px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 21px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.control {
margin-top: 17px;
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.control-heading label {
font-size: 12px;
font-weight: 720;
}
.control-heading output {
font-size: 13px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
#leftOutput {
color: var(--left);
}
#rightOutput {
color: var(--right);
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 7px;
border-radius: 999px;
outline: none;
cursor: pointer;
}
#leftRange {
accent-color: var(--left);
}
#rightRange {
accent-color: var(--right);
}
.range-caption {
display: flex;
justify-content: space-between;
color: #6f879d;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
}
.equation {
display: grid;
grid-template-columns: 1fr auto 1fr auto 1fr;
align-items: center;
gap: 7px;
margin: 22px 0 12px;
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.equation div {
text-align: center;
}
.equation span {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.1em;
}
.equation b {
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.equation > span {
margin: 0;
color: #61798e;
font-size: 16px;
}
#rightEquation {
color: var(--right);
}
#leftEquation {
color: var(--left);
}
#resultEquation {
color: var(--net);
}
#resultCard {
--state-color: var(--net);
padding: 14px;
border: 1px solid color-mix(in srgb, var(--state-color) 48%, transparent);
border-radius: 13px;
background:
linear-gradient(
135deg,
color-mix(in srgb, var(--state-color) 10%, transparent),
rgba(255, 255, 255, 0.018)
);
transition: border-color 160ms ease, background 160ms ease;
}
#resultCard[data-state="zero"] {
--state-color: var(--zero);
}
#resultCard[data-state="right"] {
--state-color: var(--right);
}
#resultCard[data-state="left"] {
--state-color: var(--left);
}
.result-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.result-top span {
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
}
.result-top strong {
color: var(--state-color);
font-size: 25px;
font-variant-numeric: tabular-nums;
}
#netDirection {
display: block;
margin-top: 5px;
color: #c0ceda;
font-size: 11px;
}
.presets {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 13px;
}
.presets button {
padding: 9px 8px;
border: 1px solid var(--line);
border-radius: 9px;
color: #dbe8f3;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
font-size: 10px;
font-weight: 700;
transition: border-color 120ms ease, background 120ms ease;
}
.presets button:hover {
border-color: rgba(255, 209, 102, 0.55);
background: rgba(255, 209, 102, 0.07);
}
.presets button:focus-visible,
input:focus-visible {
outline: 2px solid var(--net);
outline-offset: 3px;
}
.reference-note {
margin-top: 18px;
padding: 12px 13px;
border-left: 3px solid #a9b9c7;
border-radius: 0 9px 9px 0;
color: #b7c6d3;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
line-height: 1.5;
}
.reference-note strong {
color: #edf6ff;
}
.model-note {
margin-top: 13px;
color: #738a9f;
font-size: 10px;
line-height: 1.5;
}
@media (max-width: 900px) {
#viewport {
inset: 0 0 47vh 0;
}
#panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
height: 45vh;
padding: 17px;
border-radius: 15px;
}
h1 {
font-size: 23px;
}
.intro {
margin-bottom: 14px;
}
.scene-heading {
top: 14px;
left: 15px;
}
.scene-heading strong {
font-size: 14px;
}
.axis-key {
left: 14px;
bottom: 13px;
}
.camera-hint {
right: 12px;
bottom: 13px;
}
.world-label {
min-width: 104px;
padding: 6px 8px;
}
.world-label .kicker {
font-size: 7px;
}
.world-label strong {
font-size: 11px;
}
.world-label small {
font-size: 8px;
}
#label-center {
min-width: 145px;
}
.support-label {
display: none;
}
}
</style>
</head>
<body>
<main id="viewport">
<canvas id="scene" aria-label="Interactive three-dimensional rope and force visualization"></canvas>
<div class="scene-heading">
<span>LOW-POLY TENSION STUDY</span>
<strong>Collinear force balance</strong>
</div>
<div id="worldLabels">
<div id="label-left" class="world-label">
<span class="kicker">LEFTWARD FORCE</span>
<strong>F<sub>←</sub> = <span id="leftWorldValue">6.0</span> N</strong>
</div>
<div id="label-right" class="world-label">
<span class="kicker">RIGHTWARD FORCE</span>
<strong>F<sub>→</sub> = <span id="rightWorldValue">6.0</span> N</strong>
</div>
<div id="label-result" class="world-label">
<span class="kicker">NET VECTOR</span>
<strong><span id="resultWorldValue">0.0</span> N</strong>
<small id="resultWorldDirection">Zero resultant</small>
</div>
<div id="label-center" class="world-label">
<span class="kicker">FIXED POSITION BAND</span>
<strong>Center marker · x = 0</strong>
<small>Position reference only — not a force sensor</small>
</div>
<div id="label-support-left" class="world-label support-label">
FIXED EXTERNAL SUPPORT
</div>
<div id="label-support-right" class="world-label support-label">
FIXED EXTERNAL SUPPORT
</div>
</div>
<div class="axis-key">
<span class="axis"><span class="arrow">→</span> +x</span>
<span>All arrows share one force scale</span>
</div>
<div class="camera-hint">Drag to orbit · wheel to zoom · double-click to reset</div>
</main>
<aside id="panel">
<div class="eyebrow">INTERACTIVE FORCE MODEL</div>
<h1>Opposing forces on a taut rope</h1>
<p class="intro">
Adjust the leftward and rightward forces. Their signed, collinear
vector sum appears separately above the rope.
</p>
<section class="control">
<div class="control-heading">
<label for="leftRange">F<sub>←</sub> Leftward force</label>
<output id="leftOutput" for="leftRange">6.0 N</output>
</div>
<input id="leftRange" type="range" min="0" max="12" step="0.1" value="6">
<div class="range-caption">
<span>0 N</span>
<span>POINTS −x</span>
<span>12 N</span>
</div>
</section>
<section class="control">
<div class="control-heading">
<label for="rightRange">F<sub>→</sub> Rightward force</label>
<output id="rightOutput" for="rightRange">6.0 N</output>
</div>
<input id="rightRange" type="range" min="0" max="12" step="0.1" value="6">
<div class="range-caption">
<span>0 N</span>
<span>POINTS +x</span>
<span>12 N</span>
</div>
</section>
<div class="equation" aria-label="Signed vector sum">
<div>
<span>RIGHT</span>
<b id="rightEquation">+6.0 N</b>
</div>
<span>+</span>
<div>
<span>LEFT</span>
<b id="leftEquation">−6.0 N</b>
</div>
<span>=</span>
<div>
<span>NET</span>
<b id="resultEquation">0.0 N</b>
</div>
</div>
<section id="resultCard" data-state="zero" aria-live="polite">
<div class="result-top">
<span>THIRD INDICATOR · VECTOR SUM</span>
<strong><span id="netValue">0.0</span> N</strong>
</div>
<small id="netDirection">Equal and opposite · zero resultant</small>
</section>
<div class="presets" aria-label="Force presets">
<button type="button" data-left="6" data-right="6">Equal → zero</button>
<button type="button" data-left="4" data-right="8">Right stronger</button>
<button type="button" data-left="8" data-right="4">Left stronger</button>
<button type="button" data-left="2" data-right="10">Large imbalance</button>
</div>
<div class="reference-note">
<strong>The center band and marker stay fixed.</strong>
They identify the rope’s zero position only. They do not move in response
to force and must not be interpreted as a load cell or strain sensor.
</div>
<p class="model-note">
Signed 1D model: R = F<sub>→</sub> − F<sub>←</sub>.
Arrow lengths encode force magnitude. The rope remains taut and
geometrically fixed while the force vectors change.
</p>
</aside>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111d);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.22, 0);
const orbit = {
theta: 0,
phi: 1.36,
radius: 12,
desiredTheta: 0,
desiredPhi: 1.36,
desiredRadius: 12,
fitRadius: 12
};
const hemi = new THREE.HemisphereLight(0xc5e4ff, 0x07101a, 1.65);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.8);
keyLight.position.set(4.5, 8, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x5ddcff, 16, 15, 2);
cyanLight.position.set(-5, 2.2, 4);
scene.add(cyanLight);
const warmLight = new THREE.PointLight(0xff987a, 14, 15, 2);
warmLight.position.set(5, 1.8, 3);
scene.add(warmLight);
const steelMaterial = new THREE.MeshStandardMaterial({
color: 0x263848,
metalness: 0.62,
roughness: 0.43,
flatShading: true
});
const darkSteelMaterial = new THREE.MeshStandardMaterial({
color: 0x142330,
metalness: 0.48,
roughness: 0.5,
flatShading: true
});
const brassMaterial = new THREE.MeshStandardMaterial({
color: 0xc69450,
metalness: 0.58,
roughness: 0.35,
flatShading: true
});
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x90a5b7,
metalness: 0.82,
roughness: 0.25
});
// Floor and grid.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x081522,
metalness: 0.08,
roughness: 0.92
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.5;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(22, 44, 0x34546b, 0x1d3548);
grid.position.y = -1.485;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
function addCylinderBetween(a, b, radius, material, radialSegments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
// Taut, segmented low-poly rope.
const ropeY = 0.65;
const ropeStart = -3.17;
const ropeEnd = 3.17;
const segmentCount = 18;
const segmentLength = (ropeEnd - ropeStart) / segmentCount;
const ropeGeometry = new THREE.CylinderGeometry(
0.095,
0.095,
segmentLength + 0.012,
7,
1,
false
);
const ropeMaterials = [
new THREE.MeshStandardMaterial({
color: 0xd39c50,
roughness: 0.83,
metalness: 0.02,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xf0bd73,
roughness: 0.78,
metalness: 0.02,
flatShading: true
})
];
for (let i = 0; i < segmentCount; i++) {
const segment = new THREE.Mesh(
ropeGeometry,
ropeMaterials[i % ropeMaterials.length]
);
segment.position.set(
ropeStart + segmentLength * (i + 0.5),
ropeY,
0
);
segment.rotation.z = -Math.PI / 2;
segment.castShadow = true;
scene.add(segment);
}
const knotGeometry = new THREE.IcosahedronGeometry(0.108, 0);
const knotMaterial = new THREE.MeshStandardMaterial({
color: 0xe1aa60,
roughness: 0.82,
flatShading: true
});
for (let i = 1; i < segmentCount; i++) {
const knot = new THREE.Mesh(knotGeometry, knotMaterial);
knot.position.set(
ropeStart + segmentLength * i,
ropeY,
0
);
knot.scale.set(1.02, 0.82, 0.82);
knot.rotation.set(i * 0.37, i * 0.23, i * 0.19);
knot.castShadow = true;
scene.add(knot);
}
// Handles and clearly visible fixed external supports.
function createSupport(side) {
const supportX = side * 4.62;
const handleX = side * 3.40;
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.92, 0.13, 0.76),
darkSteelMaterial
);
base.position.set(supportX, -1.405, 0);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 2.25, 0.48),
steelMaterial
);
post.position.set(supportX, -0.285, 0);
post.castShadow = true;
post.receiveShadow = true;
scene.add(post);
const cap = new THREE.Mesh(
new THREE.BoxGeometry(0.65, 0.17, 0.58),
darkSteelMaterial
);
cap.position.set(supportX, 0.91, 0);
cap.castShadow = true;
scene.add(cap);
const arm = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.22, 0.34),
steelMaterial
);
arm.position.set(side * 4.00, ropeY, 0);
arm.castShadow = true;
scene.add(arm);
addCylinderBetween(
new THREE.Vector3(supportX, -0.92, -0.10),
new THREE.Vector3(handleX, 0.39, -0.10),
0.055,
darkSteelMaterial,
6
);
const handle = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.74, 0.44),
darkSteelMaterial
);
handle.position.set(handleX, ropeY, 0);
handle.castShadow = true;
scene.add(handle);
const gripStripe = new THREE.Mesh(
new THREE.BoxGeometry(0.37, 0.075, 0.47),
brassMaterial
);
gripStripe.position.set(handleX, ropeY + 0.30, 0);
gripStripe.castShadow = true;
scene.add(gripStripe);
const connector = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.13, 0.19, 8),
brassMaterial
);
connector.position.set(side * 3.17, ropeY, 0);
connector.rotation.z = -Math.PI / 2;
connector.castShadow = true;
scene.add(connector);
const boltGeometry = new THREE.CylinderGeometry(
0.065,
0.065,
0.08,
8
);
for (const y of [-0.70, 0.55]) {
const bolt = new THREE.Mesh(boltGeometry, boltMaterial);
bolt.position.set(supportX, y, 0.285);
bolt.rotation.x = Math.PI / 2;
scene.add(bolt);
}
}
createSupport(-1);
createSupport(1);
// Fixed center reference band, collar, dashed line, and marker.
const centerBandMaterial = new THREE.MeshStandardMaterial({
color: 0xffedb5,
transparent: true,
opacity: 0.14,
depthWrite: false,
roughness: 0.7
});
const centerBand = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 1.18, 0.48),
centerBandMaterial
);
centerBand.position.set(0, 0.50, 0);
scene.add(centerBand);
const bandEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(centerBand.geometry),
new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.52
})
);
bandEdges.position.copy(centerBand.position);
scene.add(bandEdges);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.16, 0.20, 12, 1, true),
new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6b4b00,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0.64,
roughness: 0.42,
flatShading: true
})
);
collar.position.set(0, ropeY, 0);
collar.rotation.z = -Math.PI / 2;
scene.add(collar);
const marker = new THREE.Mesh(
new THREE.OctahedronGeometry(0.17, 0),
new THREE.MeshStandardMaterial({
color: 0xffdf82,
emissive: 0x7a5200,
emissiveIntensity: 0.45,
metalness: 0.25,
roughness: 0.28,
flatShading: true
})
);
marker.position.set(0, ropeY, 0.20);
marker.scale.set(1.05, 0.92, 0.72);
marker.castShadow = true;
scene.add(marker);
const centerLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -1.42, 0.25),
new THREE.Vector3(0, 1.25, 0.25)
]);
const centerLine = new THREE.Line(
centerLineGeometry,
new THREE.LineDashedMaterial({
color: 0xe7d9b5,
dashSize: 0.10,
gapSize: 0.075,
transparent: true,
opacity: 0.52
})
);
centerLine.computeLineDistances();
scene.add(centerLine);
// Custom low-poly arrows. Their local forward axis is +Y.
function createArrow(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({ color });
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.036, 0.036, 1, 8),
material
);
group.add(shaft);
const head = new THREE.Mesh(
new THREE.ConeGeometry(0.125, 0.28, 8),
material
);
group.add(head);
scene.add(group);
return { group, shaft, head };
}
const leftArrow = createArrow(0x5ddcff);
leftArrow.group.position.set(-3.45, 1.53, 0);
const rightArrow = createArrow(0xff987a);
rightArrow.group.position.set(3.45, 1.53, 0);
const resultArrow = createArrow(0xffd166);
resultArrow.group.position.set(0, 2.32, 0);
const yAxis = new THREE.Vector3(0, 1, 0);
function setArrow(arrow, length, direction) {
if (length <= 0.001) {
arrow.group.visible = false;
return;
}
arrow.group.visible = true;
const headLength = Math.min(0.28, length * 0.35);
const shaftLength = Math.max(0.001, length - headLength);
const radialScale = Math.min(1, length / 0.55);
arrow.shaft.scale.set(1, shaftLength, 1);
arrow.shaft.position.y = shaftLength / 2;
arrow.head.scale.set(
radialScale,
headLength / 0.28,
radialScale
);
arrow.head.position.y = shaftLength + headLength / 2;
arrow.group.quaternion.setFromUnitVectors(
yAxis,
new THREE.Vector3(direction.x, direction.y, direction.z).normalize()
);
}
function createOriginDot(position, color, radius = 0.065) {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(radius, 10, 7),
new THREE.MeshBasicMaterial({ color })
);
dot.position.copy(position);
scene.add(dot);
return dot;
}
createOriginDot(leftArrow.group.position, 0x5ddcff);
createOriginDot(rightArrow.group.position, 0xff987a);
createOriginDot(resultArrow.group.position, 0xffd166, 0.075);
// Zero-result indicator replaces the resultant arrow at equal magnitudes.
const zeroIndicator = new THREE.Group();
zeroIndicator.position.copy(resultArrow.group.position);
const zeroRing = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.026, 8, 24),
new THREE.MeshBasicMaterial({ color: 0xd9e4ee })
);
zeroIndicator.add(zeroRing);
const zeroCrossGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.095, -0.095, 0),
new THREE.Vector3(0.095, 0.095, 0),
new THREE.Vector3(-0.095, 0.095, 0),
new THREE.Vector3(0.095, -0.095, 0)
]);
const zeroCross = new THREE.LineSegments(
zeroCrossGeometry,
new THREE.LineBasicMaterial({ color: 0xd9e4ee })
);
zeroIndicator.add(zeroCross);
scene.add(zeroIndicator);
// UI elements.
const leftRange = document.getElementById("leftRange");
const rightRange = document.getElementById("rightRange");
const leftOutput = document.getElementById("leftOutput");
const rightOutput = document.getElementById("rightOutput");
const rightEquation = document.getElementById("rightEquation");
const leftEquation = document.getElementById("leftEquation");
const resultEquation = document.getElementById("resultEquation");
const resultCard = document.getElementById("resultCard");
const netValue = document.getElementById("netValue");
const netDirection = document.getElementById("netDirection");
const leftWorldValue = document.getElementById("leftWorldValue");
const rightWorldValue = document.getElementById("rightWorldValue");
const resultWorldValue = document.getElementById("resultWorldValue");
const resultWorldDirection = document.getElementById("resultWorldDirection");
// All three arrows use the same visual force scale.
const FORCE_SCALE = 0.17;
function signedNumber(value) {
if (Math.abs(value) < 0.05) return "0.0";
return `${value > 0 ? "+" : "−"}${Math.abs(value).toFixed(1)}`;
}
function updateModel() {
const left = Number(leftRange.value);
const right = Number(rightRange.value);
const net = right - left;
leftOutput.textContent = `${left.toFixed(1)} N`;
rightOutput.textContent = `${right.toFixed(1)} N`;
rightEquation.textContent = `+${right.toFixed(1)} N`;
leftEquation.textContent = `−${left.toFixed(1)} N`;
resultEquation.textContent = `${signedNumber(net)} N`;
netValue.textContent = signedNumber(net);
leftWorldValue.textContent = left.toFixed(1);
rightWorldValue.textContent = right.toFixed(1);
resultWorldValue.textContent = signedNumber(net);
setArrow(leftArrow, left * FORCE_SCALE, { x: -1, y: 0, z: 0 });
setArrow(rightArrow, right * FORCE_SCALE, { x: 1, y: 0, z: 0 });
const isZero = Math.abs(net) < 0.05;
if (isZero) {
resultArrow.group.visible = false;
zeroIndicator.visible = true;
resultCard.dataset.state = "zero";
netDirection.textContent = "Equal and opposite · zero resultant";
resultWorldDirection.textContent = "Zero resultant";
} else {
zeroIndicator.visible = false;
const direction = net > 0 ? 1 : -1;
setArrow(
resultArrow,
Math.abs(net) * FORCE_SCALE,
{ x: direction, y: 0, z: 0 }
);
resultCard.dataset.state = net > 0 ? "right" : "left";
netDirection.textContent =
net > 0
? "Resultant points right (+x)"
: "Resultant points left (−x)";
resultWorldDirection.textContent =
net > 0
? "Resultant points right"
: "Resultant points left";
}
}
leftRange.addEventListener("input", updateModel);
rightRange.addEventListener("input", updateModel);
document.querySelectorAll(".presets button").forEach((button) => {
button.addEventListener("click", () => {
leftRange.value = button.dataset.left;
rightRange.value = button.dataset.right;
updateModel();
});
});
updateModel();
// World-space HTML labels projected from fixed 3D anchor points.
const worldLabels = [
{
element: document.getElementById("label-left"),
position: new THREE.Vector3(-3.08, 2.30, 0)
},
{
element: document.getElementById("label-right"),
position: new THREE.Vector3(3.08, 2.30, 0)
},
{
element: document.getElementById("label-result"),
position: new THREE.Vector3(0, 2.93, 0)
},
{
element: document.getElementById("label-center"),
position: new THREE.Vector3(0, -0.58, 0)
},
{
element: document.getElementById("label-support-left"),
position: new THREE.Vector3(-4.62, -0.98, 0)
},
{
element: document.getElementById("label-support-right"),
position: new THREE.Vector3(4.62, -0.98, 0)
}
];
const projected = new THREE.Vector3();
function updateProjectedLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of worldLabels) {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -180 &&
x < width + 180 &&
y > -120 &&
y < height + 120;
label.element.classList.toggle("visible", visible);
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -50%)`;
}
}
// Camera orbit and zoom implemented directly without addons.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let manualZoom = false;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.desiredTheta -= dx * 0.006;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.005,
0.96,
1.50
);
});
function endDrag(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
manualZoom = true;
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius * Math.exp(event.deltaY * 0.001),
orbit.fitRadius * 0.66,
orbit.fitRadius * 1.75
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
manualZoom = false;
orbit.desiredTheta = 0;
orbit.desiredPhi = 1.36;
orbit.desiredRadius = orbit.fitRadius;
});
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = camera.aspect < 1 ? 48 : 42;
camera.updateProjectionMatrix();
// Keep both external supports visible on narrow viewports.
orbit.fitRadius = Math.max(
10.8,
6.45 / (Math.tan(THREE.MathUtils.degToRad(camera.fov / 2)) * camera.aspect)
);
if (!manualZoom) {
orbit.desiredRadius = orbit.fitRadius;
orbit.radius = orbit.fitRadius;
}
}
window.addEventListener("resize", resize);
resize();
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function animate() {
const smoothing = 0.10;
orbit.theta += (orbit.desiredTheta - orbit.theta) * smoothing;
orbit.phi += (orbit.desiredPhi - orbit.phi) * smoothing;
orbit.radius += (orbit.desiredRadius - orbit.radius) * smoothing;
spherical.set(orbit.radius, orbit.phi, orbit.theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(cameraTarget).add(cameraOffset);
camera.lookAt(cameraTarget);
renderer.render(scene, camera);
updateProjectedLabels();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```