Prompt specification
Build or customize the Three.js 3D scene "Equator and prime-meridian rings" 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: Equator and prime-meridian rings
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/equator-and-prime-meridian-rings-x1313
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts latitude and longitude. Model a simple globe with an equator ring and one meridian. Place a marker at their intersection and distinguish angular positions from linear distances. Voxel style.
Working Three.js Starter (equator-and-prime-meridian-rings-x1313):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Latitude & Longitude</title>
<style>
:root {
--bg: #06101d;
--panel: rgba(8, 20, 35, 0.78);
--line: rgba(143, 206, 231, 0.18);
--text: #edf8ff;
--muted: #8da9ba;
--cyan: #6de4ff;
--amber: #ffc85a;
--pink: #ff4fa3;
--white: #f4fbff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 58% 44%, #153550 0%, #09192a 35%, #040a12 78%),
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,
#labels {
position: fixed;
inset: 0;
}
#stage {
z-index: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
#labels {
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.scene-label {
position: absolute;
transform: translate(-50%, -50%);
white-space: nowrap;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.08em;
text-shadow: 0 1px 5px #000, 0 0 12px #000;
transition: opacity 120ms ease;
}
.scene-label.axis {
color: rgba(220, 239, 249, 0.72);
}
.scene-label.latitude {
color: var(--cyan);
}
.scene-label.longitude {
color: var(--amber);
}
.scene-label.marker-label {
padding: 8px 10px;
border: 1px solid rgba(255, 79, 163, 0.55);
border-left: 3px solid var(--pink);
border-radius: 4px;
background: rgba(15, 12, 27, 0.84);
color: var(--pink);
letter-spacing: 0.12em;
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
}
.scene-label.marker-label strong {
display: block;
margin-top: 3px;
color: var(--white);
font-size: 11px;
letter-spacing: 0.04em;
}
.scene-label.measure {
padding: 4px 7px;
border-radius: 3px;
background: rgba(3, 10, 18, 0.78);
color: var(--white);
border: 1px solid rgba(255, 255, 255, 0.16);
letter-spacing: 0.03em;
font-size: 10px;
}
.scene-label.measure.angle {
color: #fff2b7;
border-color: rgba(255, 200, 90, 0.42);
}
.scene-label.measure.chord {
color: #cbd8df;
opacity: 0.8;
}
.panel {
z-index: 4;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.hero {
position: fixed;
z-index: 4;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 10px;
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 48px);
line-height: 0.98;
letter-spacing: -0.055em;
}
h1 span {
color: var(--amber);
}
.hero p {
max-width: 370px;
margin: 14px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.6;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 15px;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 4px;
background: rgba(7, 16, 28, 0.62);
color: #b7cbd7;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
letter-spacing: 0.08em;
}
.swatch {
width: 14px;
height: 4px;
border-radius: 1px;
background: var(--white);
box-shadow: 0 0 8px currentColor;
}
.swatch.equator {
color: var(--amber);
background: var(--amber);
}
.swatch.meridian {
color: var(--cyan);
background: var(--cyan);
}
.swatch.marker {
width: 7px;
height: 7px;
color: var(--pink);
background: var(--pink);
}
.metrics {
position: fixed;
z-index: 4;
top: 24px;
right: 24px;
width: 320px;
padding: 17px;
}
.panel-kicker {
margin-bottom: 9px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
}
.reference {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-bottom: 12px;
}
.reference-value {
padding: 9px 10px;
border: 1px solid rgba(109, 228, 255, 0.17);
border-radius: 4px;
background: rgba(109, 228, 255, 0.045);
}
.reference-value small {
display: block;
margin-bottom: 3px;
color: var(--muted);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
letter-spacing: 0.14em;
}
.reference-value strong {
color: var(--white);
font-size: 16px;
font-weight: 650;
}
.metric-note {
margin: 0 0 15px;
color: #a9bdca;
font-size: 10px;
line-height: 1.5;
}
.metric-note b {
color: var(--pink);
font-weight: 700;
}
.distance-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.distance-item {
padding: 9px 10px;
border-left: 2px solid rgba(255, 255, 255, 0.18);
background: rgba(255, 255, 255, 0.035);
}
.distance-item.lat {
border-left-color: var(--cyan);
}
.distance-item.lon {
border-left-color: var(--amber);
}
.distance-item span {
display: block;
color: var(--muted);
font-size: 8px;
line-height: 1.35;
letter-spacing: 0.04em;
}
.distance-item strong {
display: block;
margin-top: 4px;
color: var(--white);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
}
.distance-explain {
margin: 13px 0 0;
padding-top: 11px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.distance-explain b {
color: #d8e8f1;
}
.controls {
position: fixed;
z-index: 5;
bottom: 22px;
left: 50%;
width: min(790px, calc(100vw - 48px));
padding: 16px 18px;
transform: translateX(-50%);
}
.control-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin-bottom: 12px;
}
.control-top .panel-kicker {
margin: 0;
}
.reset-button {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 4px;
background: rgba(255, 255, 255, 0.045);
color: #c9dce7;
cursor: pointer;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
letter-spacing: 0.08em;
}
.reset-button:hover {
border-color: rgba(109, 228, 255, 0.5);
color: var(--cyan);
background: rgba(109, 228, 255, 0.06);
}
.measure-controls {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.range-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.range-label label {
color: #c9dbe5;
font-size: 10px;
font-weight: 650;
}
.range-label output {
color: var(--white);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 11px;
font-weight: 700;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 4px;
appearance: none;
-webkit-appearance: none;
background: linear-gradient(
90deg,
rgba(109, 228, 255, 0.72),
rgba(109, 228, 255, 0.16)
);
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
border: 2px solid #dff8ff;
border-radius: 2px;
appearance: none;
-webkit-appearance: none;
background: var(--cyan);
box-shadow: 0 0 13px rgba(109, 228, 255, 0.65);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 2px solid #dff8ff;
border-radius: 2px;
background: var(--cyan);
box-shadow: 0 0 13px rgba(109, 228, 255, 0.65);
}
#longitudeRange {
background: linear-gradient(
90deg,
rgba(255, 200, 90, 0.72),
rgba(255, 200, 90, 0.16)
);
}
#longitudeRange::-webkit-slider-thumb {
background: var(--amber);
box-shadow: 0 0 13px rgba(255, 200, 90, 0.65);
}
#longitudeRange::-moz-range-thumb {
background: var(--amber);
box-shadow: 0 0 13px rgba(255, 200, 90, 0.65);
}
.control-footer {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 12px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: #7792a2;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 8px;
letter-spacing: 0.08em;
}
@media (max-width: 800px) {
.hero {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.hero p {
display: none;
}
.legend {
margin-top: 10px;
}
.metrics {
top: 126px;
right: 14px;
left: 14px;
width: auto;
padding: 12px;
}
.metric-note,
.distance-explain {
display: none;
}
.distance-grid {
grid-template-columns: repeat(4, 1fr);
}
.distance-item {
padding: 7px;
}
.distance-item strong {
font-size: 10px;
}
.controls {
bottom: 12px;
width: calc(100vw - 28px);
padding: 13px;
}
.measure-controls {
gap: 13px;
}
.control-footer span:last-child {
display: none;
}
}
@media (max-width: 520px) {
h1 {
font-size: 28px;
}
.legend-item {
font-size: 8px;
}
.reference-value {
padding: 7px;
}
.reference-value strong {
font-size: 13px;
}
.distance-item span {
font-size: 7px;
}
.distance-item strong {
font-size: 9px;
}
.range-label label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div id="labels" aria-hidden="true"></div>
<header class="hero">
<div class="eyebrow">GEOSPATIAL STUDY / VOXEL 01</div>
<h1>Latitude <span>&</span><br />Longitude</h1>
<p>
Angular coordinates locate a direction on the globe. Kilometres describe
travel distance. The white sweeps show angular offsets; the panels separate
surface distance from straight-line chord distance.
</p>
<div class="legend">
<div class="legend-item"><i class="swatch equator"></i> EQUATOR</div>
<div class="legend-item"><i class="swatch meridian"></i> ONE MERIDIAN</div>
<div class="legend-item"><i class="swatch marker"></i> INTERSECTION</div>
</div>
</header>
<aside class="metrics panel">
<div class="panel-kicker">REFERENCE POINT</div>
<div class="reference">
<div class="reference-value">
<small>LATITUDE φ</small>
<strong>0° N</strong>
</div>
<div class="reference-value">
<small>LONGITUDE λ</small>
<strong>0° E</strong>
</div>
</div>
<p class="metric-note">
The <b>magenta marker</b> is fixed at the equator–meridian intersection.
Move the sliders to sweep away from it.
</p>
<div class="panel-kicker">LINEAR DISTANCE FROM MARKER</div>
<div class="distance-grid">
<div class="distance-item lat">
<span>LATITUDE SURFACE ARC</span>
<strong id="latArcValue">0 km</strong>
</div>
<div class="distance-item lat">
<span>LATITUDE CHORD</span>
<strong id="latChordValue">0 km</strong>
</div>
<div class="distance-item lon">
<span>LONGITUDE SURFACE ARC</span>
<strong id="lonArcValue">0 km</strong>
</div>
<div class="distance-item lon">
<span>LONGITUDE CHORD</span>
<strong id="lonChordValue">0 km</strong>
</div>
</div>
<p class="distance-explain">
<b>Arc</b> follows the globe's surface. <b>Chord</b> is the straight line
between the same points. Mean Earth radius: 6,371 km.
</p>
</aside>
<section class="controls panel">
<div class="control-top">
<div class="panel-kicker">ANGULAR SWEEPS</div>
<button id="resetButton" class="reset-button" type="button">
↺ RESET VIEW
</button>
</div>
<div class="measure-controls">
<div>
<div class="range-label">
<label for="latitudeRange">Latitude offset · Δφ</label>
<output id="latitudeValue" for="latitudeRange">+30° N</output>
</div>
<input
id="latitudeRange"
type="range"
min="-90"
max="90"
step="1"
value="30"
/>
</div>
<div>
<div class="range-label">
<label for="longitudeRange">Longitude offset · Δλ</label>
<output id="longitudeValue" for="longitudeRange">+40° E</output>
</div>
<input
id="longitudeRange"
type="range"
min="-180"
max="180"
step="1"
value="40"
/>
</div>
</div>
<div class="control-footer">
<span>DRAG TO ORBIT · SCROLL / PINCH TO ZOOM</span>
<span>ANGLES IN DEGREES / DISTANCES IN KILOMETRES</span>
</div>
</section>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const labelLayer = document.getElementById("labels");
const COLORS = {
cyan: 0x6de4ff,
amber: 0xffc85a,
pink: 0xff4fa3,
white: 0xf4fbff
};
const EARTH_RADIUS_KM = 6371.009;
const VOXEL_STEP = 0.215;
const GRID_RADIUS = 10;
const SURFACE_RADIUS = GRID_RADIUS * VOXEL_STEP;
const RING_RADIUS = 2.34;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071321, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
120
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.setClearColor(0x06101d, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
stage.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel globe showing latitude, longitude, angular arcs, and linear distances"
);
// Lighting.
scene.add(new THREE.HemisphereLight(0x91dfff, 0x06101d, 2.0));
const keyLight = new THREE.DirectionalLight(0xdaf5ff, 3.1);
keyLight.position.set(6, 8, 7);
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x2f8cff, 32, 24, 2);
rimLight.position.set(-6, 1, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffb85a, 15, 18, 2);
warmLight.position.set(4, -2, 5);
scene.add(warmLight);
// Distant pixel-like stars.
let randomSeed = 82317;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const starPositions = [];
for (let i = 0; i < 850; i++) {
const theta = random() * Math.PI * 2;
const z = random() * 2 - 1;
const radial = Math.sqrt(1 - z * z);
const radius = 24 + random() * 40;
starPositions.push(
radius * radial * Math.cos(theta),
radius * z,
radius * radial * Math.sin(theta)
);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xa7d9f0,
size: 0.055,
transparent: true,
opacity: 0.48,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(stars);
// Dark inner globe visible between the surface voxels.
const core = new THREE.Mesh(
new THREE.IcosahedronGeometry(SURFACE_RADIUS * 0.92, 4),
new THREE.MeshStandardMaterial({
color: 0x09243a,
roughness: 0.94,
metalness: 0.02,
flatShading: true
})
);
scene.add(core);
// Voxel surface: occupied cells on a Cartesian grid, rendered only where
// the cell borders the outside of the sphere.
const voxelPositions = [];
const voxelColors = [];
function isOccupied(i, j, k) {
return i * i + j * j + k * k <= 102;
}
function hash3(i, j, k) {
const value = Math.sin(i * 12.9898 + j * 78.233 + k * 37.719) * 43758.5453;
return value - Math.floor(value);
}
for (let i = -GRID_RADIUS; i <= GRID_RADIUS; i++) {
for (let j = -GRID_RADIUS; j <= GRID_RADIUS; j++) {
for (let k = -GRID_RADIUS; k <= GRID_RADIUS; k++) {
if (!isOccupied(i, j, k)) continue;
const exposed =
!isOccupied(i + 1, j, k) ||
!isOccupied(i - 1, j, k) ||
!isOccupied(i, j + 1, k) ||
!isOccupied(i, j - 1, k) ||
!isOccupied(i, j, k + 1) ||
!isOccupied(i, j, k - 1);
if (!exposed) continue;
voxelPositions.push(
new THREE.Vector3(
i * VOXEL_STEP,
j * VOXEL_STEP,
k * VOXEL_STEP
)
);
const length = Math.hypot(i, j, k);
const latitude = Math.asin(j / length);
const absLatitude = Math.abs(latitude);
let color;
if (absLatitude > 1.18) {
color = new THREE.Color(0x69bfd0);
} else if (absLatitude > 0.58) {
color = new THREE.Color(0x287d9c);
} else {
color = new THREE.Color(0x155574);
}
// Sparse bright terrain-like voxels give the abstract globe texture.
if (hash3(i, j, k) > 0.935 && absLatitude < 1.2) {
color = new THREE.Color(0x51b89d);
}
const variation = (hash3(k, i, j) - 0.5) * 0.14;
color.offsetHSL(0, 0, variation);
voxelColors.push(color);
}
}
}
const voxelGeometry = new THREE.BoxGeometry(0.198, 0.198, 0.198);
const voxelMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0.08,
flatShading: true
});
const voxels = new THREE.InstancedMesh(
voxelGeometry,
voxelMaterial,
voxelPositions.length
);
const matrix = new THREE.Matrix4();
for (let i = 0; i < voxelPositions.length; i++) {
matrix.makeTranslation(
voxelPositions[i].x,
voxelPositions[i].y,
voxelPositions[i].z
);
voxels.setMatrixAt(i, matrix);
voxels.setColorAt(i, voxelColors[i]);
}
voxels.instanceMatrix.needsUpdate = true;
voxels.instanceColor.needsUpdate = true;
scene.add(voxels);
function createBeadMesh(positions, size, color, opacity = 1) {
const geometry = new THREE.BoxGeometry(size, size, size);
const material = new THREE.MeshBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
const localMatrix = new THREE.Matrix4();
positions.forEach((position, index) => {
localMatrix.makeTranslation(position.x, position.y, position.z);
mesh.setMatrixAt(index, localMatrix);
});
mesh.instanceMatrix.needsUpdate = true;
scene.add(mesh);
return mesh;
}
// Equator: one complete voxel ring.
const equatorPositions = [];
const equatorSegments = 180;
for (let i = 0; i < equatorSegments; i++) {
const angle = (i / equatorSegments) * Math.PI * 2;
equatorPositions.push(
new THREE.Vector3(
RING_RADIUS * Math.cos(angle),
0,
RING_RADIUS * Math.sin(angle)
)
);
}
createBeadMesh(equatorPositions, 0.078, COLORS.amber);
// One prime meridian: a single pole-to-pole semicircle at longitude 0.
const meridianPositions = [];
const meridianSegments = 180;
for (let i = 0; i <= meridianSegments; i++) {
const latitude = -Math.PI / 2 + (i / meridianSegments) * Math.PI;
meridianPositions.push(
new THREE.Vector3(
RING_RADIUS * Math.cos(latitude),
RING_RADIUS * Math.sin(latitude),
0
)
);
}
createBeadMesh(meridianPositions, 0.078, COLORS.cyan);
// Small angular ticks reinforce that the guides are measured in degrees.
const tickPositions = [];
for (let latitude = -90; latitude <= 90; latitude += 15) {
const radians = THREE.MathUtils.degToRad(latitude);
tickPositions.push(
new THREE.Vector3(
RING_RADIUS * Math.cos(radians),
RING_RADIUS * Math.sin(radians),
0
)
);
}
for (let longitude = 0; longitude < 360; longitude += 30) {
const radians = THREE.MathUtils.degToRad(longitude);
tickPositions.push(
new THREE.Vector3(
RING_RADIUS * Math.cos(radians),
0,
RING_RADIUS * Math.sin(radians)
)
);
}
createBeadMesh(tickPositions, 0.095, 0xd8eef6, 0.72);
// Marker at the exact equator / meridian intersection.
const marker = new THREE.Group();
marker.position.set(RING_RADIUS, 0, 0);
const markerCore = new THREE.Mesh(
new THREE.BoxGeometry(0.23, 0.23, 0.23),
new THREE.MeshStandardMaterial({
color: COLORS.pink,
emissive: 0x7a073d,
emissiveIntensity: 1.4,
roughness: 0.42,
metalness: 0.18
})
);
const markerOutlineMaterial = new THREE.LineBasicMaterial({
color: COLORS.pink,
transparent: true,
opacity: 0.85,
depthTest: false
});
const markerOutline = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.36, 0.36, 0.36)),
markerOutlineMaterial
);
marker.add(markerCore, markerOutline);
scene.add(marker);
// Highlighted angular sweeps.
const MAX_SWEEP_SEGMENTS = 180;
const latitudeSweep = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.105, 0.105, 0.105),
new THREE.MeshBasicMaterial({ color: 0xc9f7ff }),
MAX_SWEEP_SEGMENTS
);
const longitudeSweep = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.105, 0.105, 0.105),
new THREE.MeshBasicMaterial({ color: 0xffe8a0 }),
MAX_SWEEP_SEGMENTS
);
scene.add(latitudeSweep, longitudeSweep);
// Dashed straight-line chords through the globe.
function createChord(color) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[0, 0, 0, 0, 0, 0],
3
)
);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.52,
dashSize: 0.09,
gapSize: 0.07,
depthTest: false,
depthWrite: false
})
);
line.visible = false;
line.renderOrder = 3;
scene.add(line);
return line;
}
const latitudeChord = createChord(0xbfefff);
const longitudeChord = createChord(0xffdf94);
function updateChord(line, start, end) {
const positions = line.geometry.attributes.position;
positions.setXYZ(0, start.x, start.y, start.z);
positions.setXYZ(1, end.x, end.y, end.z);
positions.needsUpdate = true;
line.geometry.computeBoundingSphere();
line.computeLineDistances();
}
// DOM labels projected from world-space positions.
const labels = [];
function addLabel(text, className, position, offset = [0, 0], html = false) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
if (html) {
element.innerHTML = text;
} else {
element.textContent = text;
}
labelLayer.appendChild(element);
const entry = {
element,
position: position.clone(),
offset,
visible: true
};
labels.push(entry);
return entry;
}
function cardinalLatitude(value) {
if (value === 0) return "0°";
return `${Math.abs(value)}° ${value > 0 ? "N" : "S"}`;
}
function cardinalLongitude(value) {
if (value === 0) return "0°";
return `${Math.abs(value)}° ${value > 0 ? "E" : "W"}`;
}
for (let latitude = -90; latitude <= 90; latitude += 30) {
if (latitude === 0) continue;
const radians = THREE.MathUtils.degToRad(latitude);
const position = new THREE.Vector3(
2.58 * Math.cos(radians),
2.58 * Math.sin(radians),
0
);
addLabel(
`φ ${cardinalLatitude(latitude)}`,
"axis latitude",
position,
[-7, 0]
);
}
for (let longitude = 0; longitude < 360; longitude += 30) {
if (longitude === 0) continue;
const radians = THREE.MathUtils.degToRad(longitude);
const position = new THREE.Vector3(
2.64 * Math.cos(radians),
0,
2.64 * Math.sin(radians)
);
addLabel(
`λ ${cardinalLongitude(longitude)}`,
"axis longitude",
position,
[0, 7]
);
}
const markerLabel = addLabel(
"MARKER / INTERSECTION<strong>0° N · 0° E</strong>",
"marker-label",
new THREE.Vector3(RING_RADIUS + 0.25, 0, 0),
[24, -30],
true
);
const latAngleLabel = addLabel(
"Δφ",
"measure angle",
new THREE.Vector3(),
[-46, -12]
);
const latArcLabel = addLabel(
"arc",
"measure",
new THREE.Vector3(),
[46, 14]
);
const latChordLabel = addLabel(
"chord",
"measure chord",
new THREE.Vector3(),
[0, 27]
);
const lonAngleLabel = addLabel(
"Δλ",
"measure angle",
new THREE.Vector3(),
[-46, -12]
);
const lonArcLabel = addLabel(
"arc",
"measure",
new THREE.Vector3(),
[46, 14]
);
const lonChordLabel = addLabel(
"chord",
"measure chord",
new THREE.Vector3(),
[0, 27]
);
const projectionVector = new THREE.Vector3();
const cameraSpaceVector = new THREE.Vector3();
function projectLabels() {
const width = innerWidth;
const height = innerHeight;
for (const label of labels) {
if (!label.visible) {
label.element.style.display = "none";
continue;
}
cameraSpaceVector
.copy(label.position)
.applyMatrix4(camera.matrixWorldInverse);
projectionVector.copy(label.position).project(camera);
const onScreen =
cameraSpaceVector.z < -0.05 &&
projectionVector.z >= -1 &&
projectionVector.z <= 1 &&
Math.abs(projectionVector.x) < 1.15 &&
Math.abs(projectionVector.y) < 1.15;
if (!onScreen) {
label.element.style.display = "none";
continue;
}
const x = (projectionVector.x * 0.5 + 0.5) * width;
const y = (-projectionVector.y * 0.5 + 0.5) * height;
label.element.style.display = "block";
label.element.style.left = `${x + label.offset[0]}px`;
label.element.style.top = `${y + label.offset[1]}px`;
}
}
// Angular distance and linear distance calculations.
const latitudeRange = document.getElementById("latitudeRange");
const longitudeRange = document.getElementById("longitudeRange");
const latitudeValue = document.getElementById("latitudeValue");
const longitudeValue = document.getElementById("longitudeValue");
const latArcValue = document.getElementById("latArcValue");
const latChordValue = document.getElementById("latChordValue");
const lonArcValue = document.getElementById("lonArcValue");
const lonChordValue = document.getElementById("lonChordValue");
const numberFormatter = new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0
});
function formatKm(value) {
return `${numberFormatter.format(value)} km`;
}
function signedDegrees(value) {
if (value > 0) return `+${value}°`;
if (value < 0) return `${value}°`;
return "0°";
}
function setSweepMesh(mesh, angleRadians, axis) {
const magnitude = Math.abs(angleRadians);
const steps = Math.min(
MAX_SWEEP_SEGMENTS,
Math.max(1, Math.ceil(THREE.MathUtils.radToDeg(magnitude) * 1.8))
);
mesh.count = magnitude > 0.0001 ? steps : 0;
const localMatrix = new THREE.Matrix4();
for (let i = 0; i < steps; i++) {
const t = (i + 0.5) / steps;
const angle = angleRadians * t;
const radius = RING_RADIUS + 0.025;
let position;
if (axis === "latitude") {
position = new THREE.Vector3(
radius * Math.cos(angle),
radius * Math.sin(angle),
0
);
} else {
position = new THREE.Vector3(
radius * Math.cos(angle),
0,
radius * Math.sin(angle)
);
}
localMatrix.makeTranslation(position.x, position.y, position.z);
mesh.setMatrixAt(i, localMatrix);
}
mesh.instanceMatrix.needsUpdate = true;
}
function updateComparison() {
const latitude = Number(latitudeRange.value);
const longitude = Number(longitudeRange.value);
const latitudeRadians = THREE.MathUtils.degToRad(latitude);
const longitudeRadians = THREE.MathUtils.degToRad(longitude);
latitudeValue.textContent = `${signedDegrees(latitude)} ${
latitude === 0 ? "" : latitude > 0 ? "N" : "S"
}`.trim();
longitudeValue.textContent = `${signedDegrees(longitude)} ${
longitude === 0 ? "" : longitude > 0 ? "E" : "W"
}`.trim();
const latitudeArc =
EARTH_RADIUS_KM * Math.abs(latitudeRadians);
const longitudeArc =
EARTH_RADIUS_KM * Math.abs(longitudeRadians);
const latitudeChordKm =
2 *
EARTH_RADIUS_KM *
Math.sin(Math.abs(latitudeRadians) / 2);
const longitudeChordKm =
2 *
EARTH_RADIUS_KM *
Math.sin(Math.abs(longitudeRadians) / 2);
latArcValue.textContent = formatKm(latitudeArc);
latChordValue.textContent = formatKm(latitudeChordKm);
lonArcValue.textContent = formatKm(longitudeArc);
lonChordValue.textContent = formatKm(longitudeChordKm);
setSweepMesh(latitudeSweep, latitudeRadians, "latitude");
setSweepMesh(longitudeSweep, longitudeRadians, "longitude");
const start = new THREE.Vector3(SURFACE_RADIUS, 0, 0);
const latitudeEnd = new THREE.Vector3(
SURFACE_RADIUS * Math.cos(latitudeRadians),
SURFACE_RADIUS * Math.sin(latitudeRadians),
0
);
const longitudeEnd = new THREE.Vector3(
SURFACE_RADIUS * Math.cos(longitudeRadians),
0,
SURFACE_RADIUS * Math.sin(longitudeRadians)
);
latitudeChord.visible = Math.abs(latitude) > 0.5;
longitudeChord.visible = Math.abs(longitude) > 0.5;
updateChord(latitudeChord, start, latitudeEnd);
updateChord(longitudeChord, start, longitudeEnd);
const latitudeVisible = Math.abs(latitude) > 0.5;
const longitudeVisible = Math.abs(longitude) > 0.5;
latAngleLabel.visible = latitudeVisible;
latArcLabel.visible = latitudeVisible;
latChordLabel.visible = latitudeVisible;
lonAngleLabel.visible = longitudeVisible;
lonArcLabel.visible = longitudeVisible;
lonChordLabel.visible = longitudeVisible;
const halfLatitude = latitudeRadians / 2;
const halfLongitude = longitudeRadians / 2;
latAngleLabel.position.set(
2.72 * Math.cos(halfLatitude),
2.72 * Math.sin(halfLatitude),
0
);
latArcLabel.position.copy(latAngleLabel.position);
latChordLabel.position
.copy(start)
.add(latitudeEnd)
.multiplyScalar(0.5);
lonAngleLabel.position.set(
2.72 * Math.cos(halfLongitude),
0,
2.72 * Math.sin(halfLongitude)
);
lonArcLabel.position.copy(lonAngleLabel.position);
lonChordLabel.position
.copy(start)
.add(longitudeEnd)
.multiplyScalar(0.5);
latAngleLabel.element.textContent = `Δφ ${signedDegrees(latitude)}`;
latArcLabel.element.textContent = `arc ${formatKm(latitudeArc)}`;
latChordLabel.element.textContent = `chord ${formatKm(latitudeChord)}`;
lonAngleLabel.element.textContent = `Δλ ${signedDegrees(longitude)}`;
lonArcLabel.element.textContent = `arc ${formatKm(longitudeArc)}`;
lonChordLabel.element.textContent = `chord ${formatKm(longitudeChord)}`;
}
latitudeRange.addEventListener("input", updateComparison);
longitudeRange.addEventListener("input", updateComparison);
updateComparison();
// Custom camera controls implemented without Three.js addons.
const cameraState = {
yaw: 0.68,
pitch: 0.38,
radius: 8.6,
targetYaw: 0.68,
targetPitch: 0.38,
targetRadius: 8.6
};
const target = new THREE.Vector3(0, 0, 0);
function updateCamera() {
camera.position.set(
target.x +
cameraState.radius *
Math.cos(cameraState.pitch) *
Math.sin(cameraState.yaw),
target.y + cameraState.radius * Math.sin(cameraState.pitch),
target.z +
cameraState.radius *
Math.cos(cameraState.pitch) *
Math.cos(cameraState.yaw)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.targetYaw = 0.68;
cameraState.targetPitch = 0.38;
cameraState.targetRadius = 8.6;
}
document.getElementById("resetButton").addEventListener("click", () => {
resetCamera();
});
const pointers = new Map();
let lastPinchDistance = null;
function getPinchDistance() {
const values = [...pointers.values()];
if (values.length < 2) return null;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 2) {
lastPinchDistance = getPinchDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = { x: event.clientX, y: event.clientY };
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const deltaX = current.x - previous.x;
const deltaY = current.y - previous.y;
cameraState.targetYaw -= deltaX * 0.006;
cameraState.targetPitch += deltaY * 0.0045;
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch,
-1.35,
1.35
);
} else if (pointers.size === 2) {
const pinchDistance = getPinchDistance();
if (lastPinchDistance && pinchDistance) {
cameraState.targetRadius *=
lastPinchDistance / pinchDistance;
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius,
5.3,
14
);
}
lastPinchDistance = pinchDistance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
lastPinchDistance = pointers.size === 2 ? getPinchDistance() : null;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("lostpointercapture", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetRadius *= Math.exp(event.deltaY * 0.001);
cameraState.targetRadius = THREE.MathUtils.clamp(
cameraState.targetRadius,
5.3,
14
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const keyStep = 0.08;
if (event.key === "ArrowLeft") {
cameraState.targetYaw += keyStep;
} else if (event.key === "ArrowRight") {
cameraState.targetYaw -= keyStep;
} else if (event.key === "ArrowUp") {
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch + keyStep,
-1.35,
1.35
);
} else if (event.key === "ArrowDown") {
cameraState.targetPitch = THREE.MathUtils.clamp(
cameraState.targetPitch - keyStep,
-1.35,
1.35
);
} else if (event.key === "+" || event.key === "=") {
cameraState.targetRadius = Math.max(
5.3,
cameraState.targetRadius - 0.35
);
} else if (event.key === "-") {
cameraState.targetRadius = Math.min(
14,
cameraState.targetRadius + 0.35
);
} else {
return;
}
event.preventDefault();
});
function onResize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
}
window.addEventListener("resize", onResize);
// Render loop.
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const smoothing = 1 - Math.exp(-clock.getDelta() * 11);
cameraState.yaw +=
(cameraState.targetYaw - cameraState.yaw) * smoothing;
cameraState.pitch +=
(cameraState.targetPitch - cameraState.pitch) * smoothing;
cameraState.radius +=
(cameraState.targetRadius - cameraState.radius) * smoothing;
updateCamera();
const elapsed = clock.elapsedTime;
const pulse = 1 + Math.sin(elapsed * 3.2) * 0.1;
markerOutline.scale.setScalar(pulse);
markerOutlineMaterial.opacity = 0.62 + Math.sin(elapsed * 3.2) * 0.2;
stars.rotation.y = elapsed * 0.008;
renderer.render(scene, camera);
projectLabels();
}
animate();
</script>
</body>
</html>
```