Prompt specification
Build or customize the Three.js 3D scene "Orbital Mechanics Teaching Table" 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: Orbital Mechanics Teaching Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/orbital-mechanics-teaching-table-x3799
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a voxel orbital-mechanics table in a small museum alcove. A planet sits above a circular base, with one satellite and a visible trajectory. Add separate velocity and acceleration arrows: velocity follows the tangent, while acceleration points inward throughout a circular orbit. Let the viewer change the launch speed from a fixed position and compare trajectories under a stated two-body model. Display the model units and a compact energy indicator. Keep the planet, arrows, and orbit legible against a dark backdrop, with simple bench seating around the exhibit. Camera motion must not be confused with the satellite's physical motion.
Working Three.js Starter (orbital-mechanics-teaching-table-x3799):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Gravity Table — Voxel Orbital Mechanics Exhibit</title>
<style>
:root {
color-scheme: dark;
--bg: #070a10;
--panel: rgba(10, 15, 24, 0.86);
--panel-border: rgba(157, 205, 255, 0.18);
--text: #e8f2ff;
--muted: #93a5bb;
--cyan: #54e8ff;
--yellow: #ffd45c;
--magenta: #ff62bd;
--blue: #728cff;
--green: #7df0ae;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.panel {
position: absolute;
pointer-events: auto;
background:
linear-gradient(145deg, rgba(19, 29, 44, 0.9), rgba(7, 11, 18, 0.9));
border: 1px solid var(--panel-border);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.42),
inset 0 1px 0 rgba(255, 255, 255, 0.035);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-radius: 14px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--cyan);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 2.5vw, 38px);
line-height: 1;
letter-spacing: -0.045em;
font-weight: 760;
}
.subtitle {
margin: 9px 0 0;
max-width: 430px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
#titleCard {
top: 22px;
left: 22px;
width: min(470px, calc(100vw - 44px));
padding: 18px 20px 17px;
}
#modelCard {
top: 22px;
right: 22px;
width: 335px;
padding: 17px 18px;
}
#controlCard {
right: 22px;
bottom: 22px;
width: 360px;
padding: 17px 18px;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 0 0 11px;
font-size: 13px;
font-weight: 720;
letter-spacing: 0.01em;
}
.tag {
color: var(--muted);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.model-equation {
padding: 11px 12px;
border: 1px solid rgba(84, 232, 255, 0.16);
border-radius: 8px;
background: rgba(84, 232, 255, 0.045);
color: #d9f8ff;
font: 500 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
overflow-x: auto;
white-space: nowrap;
}
.model-details {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 10px;
}
.detail {
padding: 8px 9px;
border-radius: 7px;
background: rgba(255, 255, 255, 0.035);
}
.detail span {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.detail strong {
display: block;
margin-top: 4px;
color: #eef7ff;
font: 600 11px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.fine-print {
margin: 10px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.speed-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
}
#speedValue {
color: var(--yellow);
font: 700 19px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
white-space: nowrap;
}
#ratioValue {
color: var(--muted);
font: 500 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
input[type="range"] {
width: 100%;
margin: 13px 0 5px;
accent-color: var(--yellow);
cursor: ew-resize;
}
.range-labels {
display: flex;
justify-content: space-between;
color: #728398;
font: 500 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.preset-row,
.button-row {
display: flex;
gap: 7px;
margin-top: 11px;
}
button {
appearance: none;
flex: 1;
min-height: 31px;
padding: 7px 9px;
border: 1px solid rgba(164, 201, 239, 0.2);
border-radius: 7px;
background: rgba(255, 255, 255, 0.045);
color: #dbe9f7;
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
cursor: pointer;
transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
button:hover {
background: rgba(84, 232, 255, 0.11);
border-color: rgba(84, 232, 255, 0.45);
color: white;
}
button.primary {
border-color: rgba(84, 232, 255, 0.36);
background: rgba(84, 232, 255, 0.12);
color: #b8f5ff;
}
.divider {
height: 1px;
margin: 14px 0 12px;
background: rgba(165, 204, 240, 0.12);
}
.energy-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
font-size: 11px;
font-weight: 700;
}
#energyValue {
color: var(--green);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.energy-track {
position: relative;
height: 9px;
margin: 10px 0 7px;
overflow: hidden;
border-radius: 20px;
background:
linear-gradient(90deg,
rgba(125, 240, 174, 0.85) 0%,
rgba(125, 240, 174, 0.38) 72%,
rgba(255, 98, 189, 0.4) 100%);
border: 1px solid rgba(255, 255, 255, 0.08);
}
.energy-zero {
position: absolute;
top: -2px;
bottom: -2px;
left: 90.91%;
width: 1px;
background: rgba(255, 255, 255, 0.75);
box-shadow: 0 0 7px rgba(255, 255, 255, 0.65);
}
#energyMarker {
position: absolute;
top: 50%;
left: 45.45%;
width: 12px;
height: 12px;
border: 2px solid white;
border-radius: 50%;
background: var(--green);
transform: translate(-50%, -50%);
box-shadow: 0 0 12px currentColor;
}
.energy-scale {
display: flex;
justify-content: space-between;
color: #728398;
font: 500 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#orbitState {
margin-top: 11px;
color: var(--green);
font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#orbitDetail {
min-height: 28px;
margin-top: 4px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.compare-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 9px;
color: #c3d2e3;
font-size: 10px;
}
.compare-row label {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
}
.compare-row input {
accent-color: var(--blue);
}
#liveReadout {
color: #8093a9;
font: 500 9px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: right;
}
#legend {
position: absolute;
left: 22px;
bottom: 22px;
display: flex;
flex-direction: column;
gap: 9px;
padding: 13px 15px;
border-left: 2px solid rgba(84, 232, 255, 0.55);
background: rgba(6, 10, 16, 0.68);
backdrop-filter: blur(10px);
border-radius: 0 9px 9px 0;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #c4d4e5;
font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.swatch {
width: 19px;
height: 5px;
border-radius: 2px;
box-shadow: 0 0 10px currentColor;
}
.camera-chip {
position: absolute;
left: 50%;
bottom: 23px;
display: flex;
align-items: center;
gap: 11px;
padding: 9px 11px;
border: 1px solid rgba(165, 204, 240, 0.16);
border-radius: 10px;
background: rgba(6, 10, 16, 0.72);
color: #9db0c5;
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
transform: translateX(-50%);
backdrop-filter: blur(10px);
}
.camera-chip button {
flex: none;
min-height: 25px;
padding: 5px 8px;
font-size: 8px;
}
@media (max-width: 860px) {
#titleCard {
width: calc(100vw - 380px);
}
#modelCard {
width: 330px;
}
#controlCard {
width: 330px;
}
.camera-chip {
left: 22px;
transform: none;
}
}
@media (max-width: 650px) {
#titleCard {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
.subtitle {
display: none;
}
#modelCard {
top: 94px;
right: 10px;
width: min(310px, calc(100vw - 20px));
padding: 12px 13px;
}
#controlCard {
right: 10px;
bottom: 10px;
width: min(330px, calc(100vw - 20px));
padding: 12px 13px;
}
#legend {
left: 10px;
bottom: 10px;
max-width: 155px;
padding: 10px;
}
.camera-chip {
display: none;
}
.model-details {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel orbital mechanics exhibit"></canvas>
<div class="hud">
<section class="panel" id="titleCard">
<p class="eyebrow">Museum of Orbital Mechanics · Exhibit 02</p>
<h1>Gravity Table</h1>
<p class="subtitle">
Launch one satellite from a fixed position. Change its initial tangential
speed and compare the resulting two-body trajectory with the circular reference.
</p>
</section>
<section class="panel" id="modelCard">
<h2 class="section-title">
Two-Body Model
<span class="tag">Normalized</span>
</h2>
<div class="model-equation">
r̈ = −μ r / |r|³<br />
μ = GM = 1 tu³/day²<br />
r₀ = (1, 0) tu · dt = 0.002 day
</div>
<div class="model-details">
<div class="detail">
<span>Length unit</span>
<strong>1 tu = 1,000 km</strong>
</div>
<div class="detail">
<span>Time unit</span>
<strong>1 day = 86,400 s</strong>
</div>
<div class="detail">
<span>Launch point</span>
<strong>Fixed r₀ = 1 tu</strong>
</div>
<div class="detail">
<span>Circular speed</span>
<strong>11.57 km/s</strong>
</div>
</div>
<p class="fine-print">
Point-mass Newtonian gravity. No drag, oblateness, perturbations, or collision
correction. The table is a fixed visual scale; numerical labels use model units.
</p>
</section>
<section class="panel" id="controlCard">
<h2 class="section-title">
Launch Speed
<span class="tag">Fixed r₀</span>
</h2>
<div class="speed-row">
<span id="speedValue">11.57 km/s</span>
<span id="ratioValue">v₀ / v꜀ = 1.000</span>
</div>
<input
id="speedSlider"
type="range"
min="0.75"
max="1.45"
step="0.005"
value="1"
aria-label="Initial launch speed"
/>
<div class="range-labels">
<span>0.75 v꜀</span>
<span>1.00 v꜀</span>
<span>1.45 v꜀</span>
</div>
<div class="preset-row" aria-label="Trajectory presets">
<button data-speed="0.75">ELLIPSE</button>
<button data-speed="1" class="primary">CIRCLE</button>
<button data-speed="1.41421356">ESCAPE</button>
</div>
<div class="button-row">
<button id="pauseButton">PAUSE MOTION</button>
<button id="resetButton">RESTART LAUNCH</button>
</div>
<div class="divider"></div>
<div class="energy-heading">
<span>Specific orbital energy</span>
<span id="energyValue">E = −0.500</span>
</div>
<div class="energy-track" aria-label="Orbital energy indicator">
<div class="energy-zero"></div>
<div id="energyMarker"></div>
</div>
<div class="energy-scale">
<span>−1.0 · BOUND</span>
<span>0 · ESCAPE</span>
</div>
<div id="orbitState">CIRCULAR ORBIT</div>
<div id="orbitDetail">Equal to the circular reference speed at r₀.</div>
<div class="compare-row">
<label>
<input id="referenceToggle" type="checkbox" checked />
Show circular reference
</label>
<span id="liveReadout">r = 1.000 tu<br />t = 0.000 day</span>
</div>
</section>
<aside id="legend" aria-label="Exhibit legend">
<div class="legend-row">
<span class="swatch" style="color:#54e8ff;background:#54e8ff"></span>
CURRENT TRAJECTORY
</div>
<div class="legend-row">
<span class="swatch" style="color:#728cff;background:#728cff"></span>
CIRCULAR REFERENCE
</div>
<div class="legend-row">
<span class="swatch" style="color:#ffd45c;background:#ffd45c"></span>
VELOCITY · TANGENT
</div>
<div class="legend-row">
<span class="swatch" style="color:#ff62bd;background:#ff62bd"></span>
ACCELERATION · INWARD
</div>
</aside>
<div class="camera-chip">
<span>DRAG = CAMERA ONLY · WHEEL = ZOOM</span>
<button id="homeButton">HOME</button>
<button id="topButton">TOP</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and UI
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const speedSlider = document.querySelector("#speedSlider");
const speedValue = document.querySelector("#speedValue");
const ratioValue = document.querySelector("#ratioValue");
const energyValue = document.querySelector("#energyValue");
const energyMarker = document.querySelector("#energyMarker");
const orbitState = document.querySelector("#orbitState");
const orbitDetail = document.querySelector("#orbitDetail");
const liveReadout = document.querySelector("#liveReadout");
const pauseButton = document.querySelector("#pauseButton");
const resetButton = document.querySelector("#resetButton");
const referenceToggle = document.querySelector("#referenceToggle");
const MU = 1;
const R0 = 1;
const DT = 0.002;
const DAYS_PER_REAL_SECOND = 0.72;
const VISUAL_ORBIT_SCALE = 1.8;
const ORBIT_Y = 1.34;
const CIRCULAR_SPEED_KM_S = 11.574;
const MAX_TRAJECTORY_POINTS = 1200;
const MAX_VISUAL_RADIUS = 6.25;
let launchRatio = 1;
let simulationTime = 0;
let simulationAccumulator = 0;
let paused = false;
let lastTrailCount = -1;
let physicalState = {
x: R0,
z: 0,
vx: 0,
vz: launchRatio
};
// -------------------------------------------------------------------------
// Renderer, scene, camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x070a10);
scene.fog = new THREE.FogExp2(0x070a10, 0.036);
const camera = new THREE.PerspectiveCamera(
44,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
const cameraState = {
azimuth: 0.72,
polar: 1.02,
radius: 11.4
};
const cameraTween = {
active: false,
elapsed: 0,
duration: 0.7,
from: null,
to: null
};
function updateCameraPosition() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraTarget.x + cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.polar),
cameraTarget.z + cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraTarget);
}
updateCameraPosition();
// -------------------------------------------------------------------------
// Materials and small construction helpers
// -------------------------------------------------------------------------
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x0d121b,
roughness: 0.88,
metalness: 0.08
}),
wall: new THREE.MeshStandardMaterial({
color: 0x111824,
roughness: 0.82,
metalness: 0.08
}),
wallInset: new THREE.MeshStandardMaterial({
color: 0x080d15,
roughness: 0.92
}),
table: new THREE.MeshStandardMaterial({
color: 0x182333,
roughness: 0.54,
metalness: 0.38
}),
tableTop: new THREE.MeshStandardMaterial({
color: 0x111b29,
roughness: 0.48,
metalness: 0.44
}),
darkMetal: new THREE.MeshStandardMaterial({
color: 0x202b3a,
roughness: 0.44,
metalness: 0.64
}),
bronze: new THREE.MeshStandardMaterial({
color: 0x8c5f31,
roughness: 0.56,
metalness: 0.32
}),
bench: new THREE.MeshStandardMaterial({
color: 0x4b3021,
roughness: 0.75,
metalness: 0.05
}),
cyan: new THREE.MeshBasicMaterial({
color: 0x54e8ff,
transparent: true,
opacity: 0.42,
depthWrite: false
}),
reference: new THREE.MeshBasicMaterial({
color: 0x728cff,
transparent: true,
opacity: 0.32,
depthWrite: false
})
};
function addBox(parent, width, height, depth, material, x, y, z, cast = true, receive = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, radiusTop, radiusBottom, height, material, y, segments = 48) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
material
);
mesh.position.y = y;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTextSprite(text, color, worldWidth = 1.5, worldHeight = 0.38) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, 512, 128);
ctx.fillStyle = "rgba(5, 9, 15, 0.88)";
ctx.fillRect(5, 8, 502, 112);
ctx.strokeStyle = color;
ctx.lineWidth = 4;
ctx.strokeRect(7, 10, 498, 108);
ctx.fillStyle = color;
ctx.font = "700 46px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
// -------------------------------------------------------------------------
// Museum alcove
// -------------------------------------------------------------------------
addBox(scene, 16, 0.2, 13.5, materials.floor, 0, -0.12, -0.2);
addBox(scene, 16, 7.4, 0.3, materials.wall, 0, 3.55, -5.55);
addBox(scene, 0.3, 7.4, 10.5, materials.wall, -7.85, 3.55, -0.3);
addBox(scene, 0.45, 7.4, 0.45, materials.darkMetal, -7.58, 3.55, -5.18);
addBox(scene, 0.45, 7.4, 0.45, materials.darkMetal, -7.58, 3.55, 4.75);
addBox(scene, 15.4, 0.45, 0.45, materials.darkMetal, 0, 7.0, -5.18);
addBox(scene, 10.6, 4.9, 0.13, materials.wallInset, 0, 3.25, -5.34);
addBox(scene, 0.14, 5.1, 0.25, materials.darkMetal, -5.25, 3.25, -5.18);
addBox(scene, 0.14, 5.1, 0.25, materials.darkMetal, 5.25, 3.25, -5.18);
addBox(scene, 10.6, 0.14, 0.25, materials.darkMetal, 0, 5.78, -5.18);
// Floor tile seams.
const seamMaterial = new THREE.MeshBasicMaterial({
color: 0x29445a,
transparent: true,
opacity: 0.2
});
for (let x = -7; x <= 7; x += 0.7) {
addBox(scene, 0.018, 0.012, 10.5, seamMaterial, x, -0.011, -0.1, false, false);
}
for (let z = -5; z <= 4.8; z += 0.7) {
addBox(scene, 14.2, 0.012, 0.018, seamMaterial, 0, -0.01, z, false, false);
}
// Wall track lights and illuminated bars.
const lampMaterial = new THREE.MeshBasicMaterial({ color: 0xffd9a0 });
const lampHousingMaterial = new THREE.MeshStandardMaterial({
color: 0x171d28,
roughness: 0.4,
metalness: 0.65
});
for (const x of [-4.2, -2.1, 0, 2.1, 4.2]) {
addBox(scene, 0.5, 0.13, 0.3, lampHousingMaterial, x, 6.12, -5.22);
addBox(scene, 0.36, 0.025, 0.2, lampMaterial, x, 6.02, -5.08, false, false);
}
// Museum plaque.
const plaqueCanvas = document.createElement("canvas");
plaqueCanvas.width = 1024;
plaqueCanvas.height = 512;
const plaqueCtx = plaqueCanvas.getContext("2d");
plaqueCtx.fillStyle = "#0b111b";
plaqueCtx.fillRect(0, 0, 1024, 512);
plaqueCtx.strokeStyle = "#42607b";
plaqueCtx.lineWidth = 8;
plaqueCtx.strokeRect(18, 18, 988, 476);
plaqueCtx.fillStyle = "#65e8ff";
plaqueCtx.font = "700 52px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
plaqueCtx.fillText("GRAVITY TABLE / 02", 62, 105);
plaqueCtx.fillStyle = "#e6f1ff";
plaqueCtx.font = "600 31px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
plaqueCtx.fillText("NEWTONIAN TWO-BODY ORBIT", 62, 185);
plaqueCtx.fillStyle = "#9fb2c8";
plaqueCtx.font = "400 25px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
plaqueCtx.fillText("μ = GM = 1 tu³/day²", 62, 252);
plaqueCtx.fillText("r₀ = 1 tu dt = 0.002 day", 62, 300);
plaqueCtx.fillText("1 tu = 1,000 km", 62, 348);
plaqueCtx.fillText("NO DRAG · NO PERTURBATIONS", 62, 414);
const plaqueTexture = new THREE.CanvasTexture(plaqueCanvas);
plaqueTexture.colorSpace = THREE.SRGBColorSpace;
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(4.9, 2.45),
new THREE.MeshBasicMaterial({ map: plaqueTexture })
);
plaque.position.set(0, 3.55, -5.22);
scene.add(plaque);
// Simple voxel benches around the exhibit.
function createBench(x, z) {
const group = new THREE.Group();
for (const slat of [-0.27, 0, 0.27]) {
addBox(
group,
0.22,
0.13,
2.45,
materials.bench,
slat,
0.68,
0,
true,
true
);
}
for (const legZ of [-0.85, 0.85]) {
addBox(group, 0.75, 0.55, 0.16, materials.darkMetal, 0, 0.34, legZ);
addBox(group, 0.16, 0.48, 0.18, materials.darkMetal, -0.29, 0.31, legZ);
addBox(group, 0.16, 0.48, 0.18, materials.darkMetal, 0.29, 0.31, legZ);
}
addBox(group, 0.72, 0.14, 0.12, materials.bench, 0, 1.14, -1.02);
addBox(group, 0.12, 0.75, 0.12, materials.darkMetal, 0, 0.94, -1.02);
group.position.set(x, 0, z);
scene.add(group);
}
createBench(-4.8, -0.25);
createBench(4.8, -0.65);
// -------------------------------------------------------------------------
// Circular exhibit table
// -------------------------------------------------------------------------
addCylinder(scene, 3.3, 3.38, 0.28, materials.table, 0.16);
addCylinder(scene, 3.18, 3.18, 0.11, materials.tableTop, 0.355);
const rimMaterial = new THREE.MeshBasicMaterial({
color: 0x37546c,
transparent: true,
opacity: 0.9
});
for (let i = 0; i < 64; i++) {
const angle = (i / 64) * Math.PI * 2;
const block = addBox(
scene,
0.3,
0.075,
0.1,
rimMaterial,
Math.cos(angle) * 3.18,
0.44,
Math.sin(angle) * 3.18,
false,
false
);
block.rotation.y = -angle;
}
// Dotted concentric table markings.
function createTableDots(radius, count, color, size) {
const geometry = new THREE.BoxGeometry(size, 0.018, size);
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.45
});
const mesh = new THREE.InstancedMesh(geometry, material, count);
const dummy = new THREE.Object3D();
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2;
dummy.position.set(
Math.cos(angle) * radius,
0.422,
Math.sin(angle) * radius
);
dummy.rotation.set(0, -angle, 0);
dummy.updateMatrix();
mesh.setMatrixAt(i, dummy.matrix);
}
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
}
createTableDots(0.9, 64, 0x2d5368, 0.045);
createTableDots(1.8, 96, 0x263f57, 0.035);
createTableDots(2.7, 112, 0x263f57, 0.035);
// Voxel pedestal beneath the central body.
addBox(scene, 0.95, 0.23, 0.95, materials.darkMetal, 0, 0.53, 0);
addBox(scene, 0.68, 0.22, 0.68, materials.table, 0, 0.74, 0);
addBox(scene, 0.34, 0.14, 0.34, materials.darkMetal, 0, 0.87, 0);
// -------------------------------------------------------------------------
// Voxel planet
// -------------------------------------------------------------------------
const planetRadius = 0.49;
const voxelStep = 0.098;
const planetPositions = [];
for (let ix = -5; ix <= 5; ix++) {
for (let iy = -5; iy <= 5; iy++) {
for (let iz = -5; iz <= 5; iz++) {
const x = ix * voxelStep;
const y = iy * voxelStep;
const z = iz * voxelStep;
if (Math.sqrt(x * x + y * y + z * z) <= planetRadius) {
planetPositions.push({ x, y, z, ix, iy, iz });
}
}
}
}
const planetGeometry = new THREE.BoxGeometry(
voxelStep * 0.94,
voxelStep * 0.94,
voxelStep * 0.94
);
const planetMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0.04,
vertexColors: true
});
const planet = new THREE.InstancedMesh(
planetGeometry,
planetMaterial,
planetPositions.length
);
const planetDummy = new THREE.Object3D();
const oceanColors = [
new THREE.Color(0x24688c),
new THREE.Color(0x2b86a3),
new THREE.Color(0x174d72)
];
const landColors = [
new THREE.Color(0x7c9c72),
new THREE.Color(0xa58c62),
new THREE.Color(0x5e8664)
];
planetPositions.forEach((p, index) => {
planetDummy.position.set(p.x, ORBIT_Y + p.y, p.z);
planetDummy.rotation.set(0, 0, 0);
planetDummy.updateMatrix();
planet.setMatrixAt(index, planetDummy.matrix);
const noise =
Math.sin(p.ix * 12.9898 + p.iy * 78.233 + p.iz * 37.719) * 43758.5453;
const fraction = noise - Math.floor(noise);
const color =
fraction > 0.69
? landColors[index % landColors.length]
: oceanColors[index % oceanColors.length];
planet.setColorAt(index, color);
});
planet.instanceMatrix.needsUpdate = true;
planet.instanceColor.needsUpdate = true;
planet.castShadow = true;
planet.receiveShadow = true;
scene.add(planet);
const planetLabel = makeTextSprite("CENTRAL BODY · μ=1", "#8cecff", 1.8, 0.36);
planetLabel.position.set(0, 2.15, 0);
scene.add(planetLabel);
// -------------------------------------------------------------------------
// Circular reference trajectory
// -------------------------------------------------------------------------
const referenceGroup = new THREE.Group();
scene.add(referenceGroup);
const referenceCount = 320;
const referenceGeometry = new THREE.BoxGeometry(0.066, 0.066, 0.066);
const referenceMesh = new THREE.InstancedMesh(
referenceGeometry,
materials.reference,
referenceCount
);
const referenceDummy = new THREE.Object3D();
for (let i = 0; i < referenceCount; i++) {
const angle = (i / referenceCount) * Math.PI * 2;
referenceDummy.position.set(
Math.cos(angle) * VISUAL_ORBIT_SCALE,
ORBIT_Y - 0.018,
Math.sin(angle) * VISUAL_ORBIT_SCALE
);
referenceDummy.rotation.set(0, -angle, 0);
referenceDummy.updateMatrix();
referenceMesh.setMatrixAt(i, referenceDummy.matrix);
}
referenceMesh.instanceMatrix.needsUpdate = true;
referenceGroup.add(referenceMesh);
// -------------------------------------------------------------------------
// Satellite
// -------------------------------------------------------------------------
const satellite = new THREE.Group();
const satelliteBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xe8edf1,
roughness: 0.38,
metalness: 0.56
});
const satelliteGoldMaterial = new THREE.MeshStandardMaterial({
color: 0xf5bf4c,
roughness: 0.35,
metalness: 0.7
});
const solarMaterial = new THREE.MeshStandardMaterial({
color: 0x25578a,
roughness: 0.28,
metalness: 0.58,
emissive: 0x071d38,
emissiveIntensity: 0.6
});
addBox(satellite, 0.24, 0.22, 0.24, satelliteBodyMaterial, 0, 0, 0);
addBox(satellite, 0.08, 0.25, 0.08, satelliteGoldMaterial, 0, 0, 0.16);
addBox(satellite, 0.25, 0.055, 0.31, solarMaterial, -0.31, 0, 0);
addBox(satellite, 0.25, 0.055, 0.31, solarMaterial, 0.31, 0, 0);
addBox(satellite, 0.09, 0.09, 0.09, satelliteGoldMaterial, 0, 0.18, 0);
satellite.position.set(VISUAL_ORBIT_SCALE, ORBIT_Y, 0);
scene.add(satellite);
// Fixed launch-position marker and stem.
const launchMarkerMaterial = new THREE.MeshBasicMaterial({
color: 0xffc85b,
transparent: true,
opacity: 0.85
});
addBox(scene, 0.12, 0.025, 0.38, launchMarkerMaterial, VISUAL_ORBIT_SCALE, ORBIT_Y - 0.04, 0, false, false);
addBox(scene, 0.12, 0.025, 0.38, launchMarkerMaterial, VISUAL_ORBIT_SCALE, ORBIT_Y - 0.04, 0, false, false);
for (let y = 0.48; y < ORBIT_Y - 0.12; y += 0.14) {
addBox(
scene,
0.025,
0.08,
0.025,
launchMarkerMaterial,
VISUAL_ORBIT_SCALE,
y,
0,
false,
false
);
}
const launchLabel = makeTextSprite("FIXED LAUNCH r₀", "#ffd45c", 1.75, 0.36);
launchLabel.position.set(VISUAL_ORBIT_SCALE + 0.05, ORBIT_Y + 0.52, 0);
scene.add(launchLabel);
// -------------------------------------------------------------------------
// Voxel arrows
// -------------------------------------------------------------------------
const Z_AXIS = new THREE.Vector3(0, 0, 1);
function createVoxelArrow(color) {
const group = new THREE.Group();
const material = new THREE.MeshBasicMaterial({ color });
const shaft = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.075, 1),
material
);
group.add(shaft);
const headRoot = new THREE.Group();
group.add(headRoot);
const headLevels = [
new THREE.Mesh(new THREE.BoxGeometry(0.28, 0.28, 0.12), material),
new THREE.Mesh(new THREE.BoxGeometry(0.19, 0.19, 0.12), material),
new THREE.Mesh(new THREE.BoxGeometry(0.10, 0.10, 0.12), material)
];
headLevels[0].position.z = 0.06;
headLevels[1].position.z = 0.18;
headLevels[2].position.z = 0.30;
headLevels.forEach((part) => {
part.renderOrder = 10;
headRoot.add(part);
});
group.userData.shaft = shaft;
group.userData.headRoot = headRoot;
group.renderOrder = 10;
return group;
}
const velocityArrow = createVoxelArrow(0xffd45c);
const accelerationArrow = createVoxelArrow(0xff62bd);
scene.add(velocityArrow, accelerationArrow);
const velocityLabel = makeTextSprite("v · VELOCITY", "#ffd45c", 1.15, 0.29);
const accelerationLabel = makeTextSprite("a · INWARD", "#ff62bd", 1.15, 0.29);
scene.add(velocityLabel, accelerationLabel);
function setArrowTransform(arrow, origin, direction, length) {
const shaftLength = Math.max(0.08, length - 0.36);
arrow.position.copy(origin);
arrow.quaternion.setFromUnitVectors(Z_AXIS, direction);
arrow.userData.shaft.scale.z = shaftLength;
arrow.userData.shaft.position.z = shaftLength * 0.5;
arrow.userData.headRoot.position.z = shaftLength;
}
// -------------------------------------------------------------------------
// Two-body integration
// -------------------------------------------------------------------------
function accelerationAt(x, z) {
const radiusSquared = x * x + z * z;
const factor = -MU / Math.pow(radiusSquared, 1.5);
return { x: factor * x, z: factor * z };
}
function derivative(state) {
const acceleration = accelerationAt(state.x, state.z);
return {
x: state.vx,
z: state.vz,
vx: acceleration.x,
vz: acceleration.z
};
}
function addScaledState(state, derivativeValue, scale) {
return {
x: state.x + derivativeValue.x * scale,
z: state.z + derivativeValue.z * scale,
vx: state.vx + derivativeValue.vx * scale,
vz: state.vz + derivativeValue.vz * scale
};
}
function rk4Step(state, stepSize) {
const k1 = derivative(state);
const k2 = derivative(addScaledState(state, k1, stepSize * 0.5));
const k3 = derivative(addScaledState(state, k2, stepSize * 0.5));
const k4 = derivative(addScaledState(state, k3, stepSize));
return {
x:
state.x +
(stepSize / 6) * (k1.x + 2 * k2.x + 2 * k3.x + k4.x),
z:
state.z +
(stepSize / 6) * (k1.z + 2 * k2.z + 2 * k3.z + k4.z),
vx:
state.vx +
(stepSize / 6) * (k1.vx + 2 * k2.vx + 2 * k3.vx + k4.vx),
vz:
state.vz +
(stepSize / 6) * (k1.vz + 2 * k2.vz + 2 * k3.vz + k4.vz)
};
}
// -------------------------------------------------------------------------
// Current trajectory and traveled trail
// -------------------------------------------------------------------------
const trajectoryGroup = new THREE.Group();
scene.add(trajectoryGroup);
let trajectoryMesh = null;
let traveledMesh = null;
let trajectoryPoints = [];
function removeAndDisposeMesh(mesh) {
if (!mesh) return;
trajectoryGroup.remove(mesh);
mesh.geometry.dispose();
mesh.material.dispose();
}
function buildTrajectory() {
removeAndDisposeMesh(trajectoryMesh);
removeAndDisposeMesh(traveledMesh);
const initialEnergy = 0.5 * launchRatio * launchRatio - MU / R0;
let duration;
if (initialEnergy < 0) {
const semiMajorAxis = -MU / (2 * initialEnergy);
const period = 2 * Math.PI * Math.sqrt(
Math.pow(semiMajorAxis, 3) / MU
);
duration = Math.min(period * 1.025, 18);
} else {
duration = 9;
}
const pathState = {
x: R0,
z: 0,
vx: 0,
vz: launchRatio
};
trajectoryPoints = [];
let pathTime = 0;
let nextSampleTime = 0;
while (pathTime <= duration && trajectoryPoints.length < MAX_TRAJECTORY_POINTS) {
const visualRadius =
Math.hypot(pathState.x, pathState.z) * VISUAL_ORBIT_SCALE;
if (visualRadius > MAX_VISUAL_RADIUS) break;
if (pathTime >= nextSampleTime) {
trajectoryPoints.push({
x: pathState.x,
z: pathState.z,
t: pathTime
});
nextSampleTime += 0.025;
}
const nextState = rk4Step(pathState, DT);
pathState.x = nextState.x;
pathState.z = nextState.z;
pathState.vx = nextState.vx;
pathState.vz = nextState.vz;
pathTime += DT;
}
const pointCount = trajectoryPoints.length;
const pathGeometry = new THREE.BoxGeometry(0.074, 0.074, 0.074);
const pathMaterial = new THREE.MeshBasicMaterial({
color: 0x54e8ff,
transparent: true,
opacity: 0.34,
depthWrite: false
});
trajectoryMesh = new THREE.InstancedMesh(
pathGeometry,
pathMaterial,
pointCount
);
const trailGeometry = new THREE.BoxGeometry(0.086, 0.086, 0.086);
const trailMaterial = new THREE.MeshBasicMaterial({
color: 0x7cf3ff
});
traveledMesh = new THREE.InstancedMesh(
trailGeometry,
trailMaterial,
pointCount
);
const dummy = new THREE.Object3D();
trajectoryPoints.forEach((point, index) => {
dummy.position.set(
point.x * VISUAL_ORBIT_SCALE,
ORBIT_Y,
point.z * VISUAL_ORBIT_SCALE
);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
trajectoryMesh.setMatrixAt(index, dummy.matrix);
traveledMesh.setMatrixAt(index, dummy.matrix);
});
trajectoryMesh.instanceMatrix.needsUpdate = true;
traveledMesh.instanceMatrix.needsUpdate = true;
traveledMesh.count = 0;
trajectoryGroup.add(trajectoryMesh, traveledMesh);
lastTrailCount = -1;
}
function updateTraveledTrail() {
let count = 0;
while (
count < trajectoryPoints.length &&
trajectoryPoints[count].t <= simulationTime
) {
count++;
}
if (count !== lastTrailCount && traveledMesh) {
traveledMesh.count = count;
traveledMesh.instanceMatrix.needsUpdate = true;
lastTrailCount = count;
}
}
// -------------------------------------------------------------------------
// Simulation reset and UI
// -------------------------------------------------------------------------
function resetSimulation() {
simulationTime = 0;
simulationAccumulator = 0;
physicalState = {
x: R0,
z: 0,
vx: 0,
vz: launchRatio
};
lastTrailCount = -1;
buildTrajectory();
updateTraveledTrail();
updateOrbitReadout();
}
function updateOrbitReadout() {
const launchEnergy = 0.5 * launchRatio * launchRatio - MU / R0;
const launchSpeedKmS = launchRatio * CIRCULAR_SPEED_KM_S;
speedValue.textContent = `${launchSpeedKmS.toFixed(2)} km/s`;
ratioValue.textContent = `v₀ / v꜀ = ${launchRatio.toFixed(3)}`;
energyValue.textContent = `E = ${launchEnergy.toFixed(3)}`;
const markerPosition = THREE.MathUtils.clamp(
((launchEnergy + 1) / 1.1) * 100,
1,
99
);
energyMarker.style.left = `${markerPosition}%`;
let stateColor = "#7df0ae";
let stateText = "";
let detailText = "";
if (Math.abs(launchEnergy) < 0.0002) {
stateColor = "#ffd45c";
stateText = "PARABOLIC TRAJECTORY";
detailText = "Specific energy is zero: the parabolic escape threshold.";
} else if (launchEnergy > 0) {
stateColor = "#ff62bd";
stateText = "HYPERBOLIC · UNBOUND";
detailText = "Positive energy produces an open escape trajectory.";
} else if (Math.abs(launchRatio - 1) < 0.006) {
stateColor = "#54e8ff";
stateText = "CIRCULAR ORBIT";
detailText = "Equal to the circular reference speed at r₀.";
} else {
stateColor = "#7df0ae";
stateText = "BOUND ELLIPSE";
if (launchRatio < 1) {
detailText = "Below circular speed: the fixed launch point is apoapsis.";
} else {
detailText = "Above circular speed: the fixed launch point is periapsis.";
}
}
orbitState.textContent = stateText;
orbitState.style.color = stateColor;
orbitDetail.textContent = detailText;
energyMarker.style.background = stateColor;
energyMarker.style.color = stateColor;
}
speedSlider.addEventListener("input", () => {
launchRatio = Number(speedSlider.value);
resetSimulation();
updateOrbitReadout();
});
document.querySelectorAll("[data-speed]").forEach((button) => {
button.addEventListener("click", () => {
launchRatio = Number(button.dataset.speed);
speedSlider.value = String(launchRatio);
resetSimulation();
updateOrbitReadout();
});
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "RESUME MOTION" : "PAUSE MOTION";
});
resetButton.addEventListener("click", resetSimulation);
referenceToggle.addEventListener("change", () => {
referenceGroup.visible = referenceToggle.checked;
});
// -------------------------------------------------------------------------
// Camera controls: implemented directly, independent of simulation state
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
cameraTween.active = false;
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.azimuth = THREE.MathUtils.clamp(
cameraState.azimuth - dx * 0.0045,
-1.12,
1.12
);
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.0038,
0.18,
1.28
);
updateCameraPosition();
});
function endCameraDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endCameraDrag);
canvas.addEventListener("pointercancel", endCameraDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTween.active = false;
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.0009),
8.0,
14.5
);
updateCameraPosition();
},
{ passive: false }
);
function moveCameraTo(azimuth, polar, radius) {
cameraTween.active = true;
cameraTween.elapsed = 0;
cameraTween.from = {
azimuth: cameraState.azimuth,
polar: cameraState.polar,
radius: cameraState.radius
};
cameraTween.to = { azimuth, polar, radius };
}
document.querySelector("#homeButton").addEventListener("click", () => {
moveCameraTo(0.72, 1.02, 11.4);
});
document.querySelector("#topButton").addEventListener("click", () => {
moveCameraTo(0, 0.19, 10.8);
});
function updateCameraTween(delta) {
if (!cameraTween.active) return;
cameraTween.elapsed += delta;
const t = Math.min(cameraTween.elapsed / cameraTween.duration, 1);
const eased = t * t * (3 - 2 * t);
cameraState.azimuth = THREE.MathUtils.lerp(
cameraTween.from.azimuth,
cameraTween.to.azimuth,
eased
);
cameraState.polar = THREE.MathUtils.lerp(
cameraTween.from.polar,
cameraTween.to.polar,
eased
);
cameraState.radius = THREE.MathUtils.lerp(
cameraTween.from.radius,
cameraTween.to.radius,
eased
);
updateCameraPosition();
if (t >= 1) {
cameraTween.active = false;
}
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xb6d6ff, 0x21141c, 1.35);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe2b8, 3.1);
keyLight.position.set(4.5, 8.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x37cfff, 32, 11, 2);
cyanLight.position.set(-4, 3.2, 1.4);
scene.add(cyanLight);
const magentaLight = new THREE.PointLight(0xff4fa7, 18, 8, 2);
magentaLight.position.set(4.2, 2.7, -0.2);
scene.add(magentaLight);
const planetLight = new THREE.PointLight(0x64dfff, 7, 3.5, 2);
planetLight.position.set(0, 2.1, 0);
scene.add(planetLight);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const satelliteWorldPosition = new THREE.Vector3();
const velocityDirection = new THREE.Vector3();
const accelerationDirection = new THREE.Vector3();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updateCameraTween(delta);
if (!paused) {
const simulatedDays = delta * DAYS_PER_REAL_SECOND;
simulationTime += simulatedDays;
simulationAccumulator += simulatedDays;
while (simulationAccumulator >= DT) {
physicalState = rk4Step(physicalState, DT);
simulationAccumulator -= DT;
}
}
satelliteWorldPosition.set(
physicalState.x * VISUAL_ORBIT_SCALE,
ORBIT_Y,
physicalState.z * VISUAL_ORBIT_SCALE
);
satellite.position.copy(satelliteWorldPosition);
const speed = Math.hypot(physicalState.vx, physicalState.vz);
const radius = Math.max(Math.hypot(physicalState.x, physicalState.z), 1e-8);
velocityDirection.set(physicalState.vx, 0, physicalState.vz);
if (velocityDirection.lengthSq() > 1e-10) {
velocityDirection.normalize();
}
accelerationDirection.set(
-physicalState.x / radius,
0,
-physicalState.z / radius
);
satellite.rotation.y = Math.atan2(
physicalState.vx,
physicalState.vz
);
const velocityArrowLength = 0.72 + 0.22 * Math.min(speed / 1.45, 1.25);
const accelerationArrowLength = 0.78;
setArrowTransform(
velocityArrow,
satelliteWorldPosition,
velocityDirection,
velocityArrowLength
);
setArrowTransform(
accelerationArrow,
satelliteWorldPosition,
accelerationDirection,
accelerationArrowLength
);
velocityLabel.position
.copy(satelliteWorldPosition)
.addScaledVector(velocityDirection, velocityArrowLength + 0.3);
velocityLabel.position.y += 0.19;
accelerationLabel.position
.copy(satelliteWorldPosition)
.addScaledVector(accelerationDirection, accelerationArrowLength + 0.28);
accelerationLabel.position.y += 0.27;
updateTraveledTrail();
const currentEnergy =
0.5 * (physicalState.vx ** 2 + physicalState.vz ** 2) -
MU / radius;
liveReadout.innerHTML =
`r = ${radius.toFixed(3)} tu<br />` +
`E = ${currentEnergy.toFixed(3)} tu²/d²`;
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resetSimulation();
updateOrbitReadout();
animate();
</script>
</body>
</html>
```