Prompt specification
Build or customize the Three.js 3D scene "Conic-section exploration rig" 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: Conic-section exploration rig
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/conic-section-exploration-rig-x1688
Scene Description Prompt:
Please use Three.js from cdnjs for a low-poly scene based on this idea: conic-section exploration rig. Allow controlled plane translation and rotation through a double cone; update the intersection curve and handle degenerate cases explicitly rather than forcing every slice into a standard oval. Return one self-contained HTML file.
Working Three.js Starter (conic-section-exploration-rig-x1688):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Conic-Section Exploration Rig</title>
<style>
:root {
color-scheme: dark;
--bg: #061018;
--panel: rgba(8, 20, 30, 0.88);
--border: rgba(133, 216, 230, 0.16);
--text: #e8f5f7;
--muted: #8faeb7;
--accent: #68e6bd;
--cyan: #61d8e5;
--orange: #ffb765;
--purple: #ae91ff;
--yellow: #ffd166;
}
* { 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;
display: block;
touch-action: none;
}
.glass {
background: var(--panel);
border: 1px solid var(--border);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
#brand {
position: fixed;
top: 18px;
left: 20px;
width: min(360px, calc(100vw - 40px));
padding: 16px 18px;
border-radius: 16px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 19px;
font-weight: 720;
letter-spacing: -0.025em;
}
#brand p {
margin: 7px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#panel {
position: fixed;
top: 18px;
right: 18px;
width: 340px;
max-height: calc(100vh - 36px);
overflow: auto;
padding: 16px;
border-radius: 18px;
scrollbar-width: thin;
scrollbar-color: #315361 transparent;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin: 2px 0 11px;
color: #d9eef1;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title + .section-title {
margin-top: 18px;
padding-top: 15px;
border-top: 1px solid rgba(133, 216, 230, 0.1);
}
#status {
position: relative;
overflow: hidden;
padding: 14px;
border: 1px solid color-mix(in srgb, var(--accent) 38%, transparent);
border-radius: 13px;
background:
linear-gradient(135deg,
color-mix(in srgb, var(--accent) 12%, transparent),
rgba(255, 255, 255, 0.015));
}
#status::after {
content: "";
position: absolute;
top: 0;
left: 0;
width: 3px;
height: 100%;
background: var(--accent);
box-shadow: 0 0 18px var(--accent);
}
#status-kicker, #section-classification {
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#status-title {
margin-top: 3px;
font-size: 20px;
font-weight: 760;
letter-spacing: -0.025em;
}
#status-description {
margin-top: 6px;
color: #a9c0c6;
font-size: 11.5px;
line-height: 1.45;
}
.control {
margin-top: 13px;
}
.control label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 7px;
color: #cfe1e5;
font-size: 11px;
}
output {
color: var(--accent);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 10.5px;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
-webkit-appearance: none;
border-radius: 4px;
background: linear-gradient(90deg, #315765, #1b303a);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
-webkit-appearance: none;
border: 2px solid #d8f4f7;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px color-mix(in srgb, var(--accent) 65%, transparent);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #d8f4f7;
border-radius: 50%;
background: var(--accent);
}
.hint {
margin-top: 6px;
color: #6f8f98;
font-size: 10px;
line-height: 1.4;
}
.presets {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
}
button {
min-height: 31px;
padding: 7px 9px;
border: 1px solid rgba(133, 216, 230, 0.16);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #d7e8eb;
font: inherit;
font-size: 10.5px;
cursor: pointer;
transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
button:hover {
border-color: rgba(133, 216, 230, 0.38);
background: rgba(97, 216, 229, 0.09);
}
button:active { transform: translateY(1px); }
button.primary {
border-color: color-mix(in srgb, var(--accent) 45%, transparent);
background: color-mix(in srgb, var(--accent) 12%, transparent);
color: #eafff8;
}
button.wide { grid-column: 1 / -1; }
#plot-wrap {
position: relative;
overflow: hidden;
height: 158px;
border: 1px solid rgba(133, 216, 230, 0.12);
border-radius: 12px;
background:
radial-gradient(circle at 50% 50%, rgba(44, 100, 116, 0.11), transparent 70%),
rgba(2, 10, 15, 0.55);
}
#plot {
display: block;
width: 100%;
height: 100%;
}
#plot-label {
position: absolute;
top: 8px;
left: 9px;
color: #6d8b94;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 9px;
}
.metric {
min-height: 52px;
padding: 9px 10px;
border: 1px solid rgba(133, 216, 230, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.022);
}
.metric span {
display: block;
color: #688790;
font-size: 8.5px;
font-weight: 750;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin-top: 4px;
color: #d5e8eb;
font-size: 11px;
font-weight: 650;
line-height: 1.25;
}
.equation {
margin-top: 9px;
padding: 10px;
overflow-wrap: anywhere;
border: 1px solid rgba(133, 216, 230, 0.09);
border-radius: 10px;
color: #9eb7bd;
background: rgba(0, 0, 0, 0.13);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9.5px;
line-height: 1.5;
}
#legend {
position: fixed;
left: 20px;
bottom: 18px;
display: flex;
gap: 14px;
align-items: center;
padding: 9px 12px;
border-radius: 11px;
color: #8faeb7;
font-size: 10px;
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 14px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.swatch.plane { background: var(--purple); }
.swatch.curve { background: var(--accent); }
#camera-hint {
position: fixed;
right: 20px;
bottom: 18px;
padding: 9px 12px;
border-radius: 11px;
color: #78959e;
font-size: 10px;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
background: #061018;
color: #8fd9df;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
@media (max-width: 760px) {
#brand {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
}
#brand p { display: none; }
#panel {
top: auto;
right: 10px;
bottom: 10px;
width: calc(100vw - 20px);
max-height: 54vh;
}
#legend, #camera-hint { display: none; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="brand" class="glass">
<div class="eyebrow">Analytical geometry / interactive rig</div>
<h1>Conic-Section Explorer</h1>
<p>Translate and rotate a slicing plane through a double cone. The intersection is solved as a general quadratic conic, including singular and empty sections.</p>
</div>
<div id="panel" class="glass">
<div class="section-title">
<span>Intersection state</span>
<span id="status-kicker">Section</span>
</div>
<div id="status">
<div id="section-classification">Bounded conic</div>
<div id="status-title">Closed ellipse</div>
<div id="status-description">The plane meets one nappe in a bounded curve.</div>
</div>
<div class="section-title">
<span>Rig geometry</span>
<span>live</span>
</div>
<div class="control">
<label for="alpha">Cone half-angle <output id="alpha-out">34°</output></label>
<input id="alpha" type="range" min="24" max="42" step="0.5" value="34" />
</div>
<div class="control">
<label for="tilt">Plane tilt from cone axis <output id="tilt-out">25°</output></label>
<input id="tilt" type="range" min="0" max="90" step="0.25" value="25" />
<div class="hint">0° is perpendicular to the cone axis; 90° is parallel to it.</div>
</div>
<div class="control">
<label for="azimuth">Plane rotation / azimuth <output id="azimuth-out">0°</output></label>
<input id="azimuth" type="range" min="-180" max="180" step="0.5" value="0" />
</div>
<div class="control">
<label for="offset">Translation along plane normal <output id="offset-out">1.50</output></label>
<input id="offset" type="range" min="-4" max="4" step="0.01" value="1.5" />
</div>
<div class="section-title">
<span>Named sections</span>
<span>presets</span>
</div>
<div class="presets">
<button data-preset="circle">Circle</button>
<button data-preset="ellipse">Ellipse</button>
<button data-preset="parabola">Parabola</button>
<button data-preset="hyperbola">Hyperbola</button>
<button data-preset="tangent">Tangent line</button>
<button data-preset="apex">Two generators</button>
<button data-preset="point">Apex point</button>
<button id="sweep" class="wide">Start offset sweep</button>
</div>
<div class="section-title">
<span>Plane-coordinate plot</span>
<span id="plot-kind">conic</span>
</div>
<div id="plot-wrap">
<canvas id="plot"></canvas>
<div id="plot-label">in-plane coordinates</div>
</div>
<div class="metrics">
<div class="metric">
<span>Topology</span>
<strong id="metric-topology">Closed</strong>
</div>
<div class="metric">
<span>Nappe behavior</span>
<strong id="metric-nappe">One nappe</strong>
</div>
<div class="metric">
<span>Quadratic determinant</span>
<strong id="metric-det">0.000</strong>
</div>
<div class="metric">
<span>Center residual</span>
<strong id="metric-residual">0.000</strong>
</div>
</div>
<div id="equation" class="equation"></div>
</div>
<div id="legend" class="glass">
<div class="legend-item"><i class="swatch plane"></i>slicing plane</div>
<div class="legend-item"><i class="swatch curve"></i>intersection curve</div>
</div>
<div id="camera-hint" class="glass">Drag to orbit · Shift-drag to pan · Wheel to zoom</div>
<div id="loading">Loading analytical rig…</div>
<script type="module">
import * as THREE from 'https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js';
const $ = id => document.getElementById(id);
const sceneCanvas = $('scene');
const renderer = new THREE.WebGLRenderer({
canvas: sceneCanvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x061018);
scene.fog = new THREE.Fog(0x061018, 18, 38);
const camera = new THREE.PerspectiveCamera(43, innerWidth / innerHeight, 0.1, 100);
scene.add(new THREE.HemisphereLight(0xa9e9f1, 0x071018, 1.9));
const keyLight = new THREE.DirectionalLight(0xc8fbff, 3.0);
keyLight.position.set(7, 9, 8);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x7765ff, 2.0);
rimLight.position.set(-8, 3, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffa85b, 24, 16, 2);
warmLight.position.set(4, 1, 4);
scene.add(warmLight);
const coneGroup = new THREE.Group();
const planeGroup = new THREE.Group();
const curveGroup = new THREE.Group();
scene.add(coneGroup, planeGroup, curveGroup);
const state = {
alpha: 34,
tilt: 25,
azimuth: 0,
offset: 1.5,
sweeping: false
};
const cameraState = {
radius: 18.5,
theta: 0.72,
phi: 1.08,
target: new THREE.Vector3(0, -0.2, 0)
};
const COLORS = {
ellipse: 0x68e6bd,
circle: 0x68e6bd,
hyperbola: 0xffb765,
parabola: 0xae91ff,
degenerate: 0xffd166,
point: 0xffffff,
empty: 0x72858b
};
function disposeObject(object) {
object.traverse(child => {
if (child.geometry) child.geometry.dispose();
if (child.material) {
const materials = Array.isArray(child.material) ? child.material : [child.material];
materials.forEach(material => material.dispose());
}
});
}
function clearGroup(group) {
for (let i = group.children.length - 1; i >= 0; i--) {
const child = group.children[i];
group.remove(child);
disposeObject(child);
}
}
function cylinderBetween(a, b, radius, material, segments = 6) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(radius, radius, length, segments);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function buildRig() {
const rig = new THREE.Group();
const metal = new THREE.MeshStandardMaterial({
color: 0x18313b,
roughness: 0.58,
metalness: 0.72,
flatShading: true
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x0c1b23,
roughness: 0.68,
metalness: 0.6,
flatShading: true
});
const accentMetal = new THREE.MeshStandardMaterial({
color: 0x285c67,
roughness: 0.45,
metalness: 0.75,
flatShading: true
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(5.12, 5.35, 0.42, 12),
darkMetal
);
base.position.y = -5.2;
rig.add(base);
const baseRing = new THREE.Mesh(
new THREE.TorusGeometry(5.14, 0.095, 6, 48),
accentMetal
);
baseRing.rotation.x = Math.PI / 2;
baseRing.position.y = -4.96;
rig.add(baseRing);
const topRing = new THREE.Mesh(
new THREE.TorusGeometry(5.05, 0.075, 6, 48),
accentMetal
);
topRing.rotation.x = Math.PI / 2;
topRing.position.y = 4.82;
rig.add(topRing);
for (let i = 0; i < 4; i++) {
const angle = Math.PI / 4 + i * Math.PI / 2;
const x = Math.cos(angle) * 5.05;
const z = Math.sin(angle) * 5.05;
rig.add(cylinderBetween(
new THREE.Vector3(x, -4.95, z),
new THREE.Vector3(x, 4.82, z),
0.065,
metal,
6
));
}
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, -5.05, 0),
new THREE.Vector3(0, 5.05, 0)
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x87a8b0,
dashSize: 0.18,
gapSize: 0.14,
transparent: true,
opacity: 0.42
})
);
axis.computeLineDistances();
rig.add(axis);
scene.add(rig);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(34, 34),
new THREE.MeshStandardMaterial({
color: 0x07131b,
roughness: 0.95,
metalness: 0.08
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -5.43;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x1b5262, 0x102b36);
grid.position.y = -5.42;
grid.material.transparent = true;
grid.material.opacity = 0.38;
scene.add(grid);
}
function buildCone() {
clearGroup(coneGroup);
const alpha = THREE.MathUtils.degToRad(state.alpha);
const slope = Math.tan(alpha);
const maxY = 5.0;
const rings = 9;
const segments = 20;
const positions = [];
const indices = [];
for (const sign of [1, -1]) {
const base = positions.length / 3;
for (let j = 0; j <= rings; j++) {
const y = sign * maxY * j / rings;
const radius = slope * Math.abs(y);
for (let i = 0; i <= segments; i++) {
const angle = i / segments * Math.PI * 2;
positions.push(
radius * Math.cos(angle),
y,
radius * Math.sin(angle)
);
}
}
for (let j = 0; j < rings; j++) {
for (let i = 0; i < segments; i++) {
const a = base + j * (segments + 1) + i;
const b = a + 1;
const c = a + segments + 1;
const d = c + 1;
indices.push(a, b, d, a, d, c);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const surface = new THREE.Mesh(
geometry,
new THREE.MeshPhongMaterial({
color: 0x4ac7d0,
emissive: 0x0d3e48,
emissiveIntensity: 0.58,
transparent: true,
opacity: 0.19,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
})
);
surface.renderOrder = 1;
coneGroup.add(surface);
const wire = new THREE.LineSegments(
new THREE.WireframeGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0x70dce3,
transparent: true,
opacity: 0.19,
depthWrite: false
})
);
wire.renderOrder = 2;
coneGroup.add(wire);
for (const y of [-4.4, -3.3, -2.2, -1.1, 1.1, 2.2, 3.3, 4.4]) {
const radius = slope * Math.abs(y);
const points = [];
for (let i = 0; i < segments; i++) {
const angle = i / segments * Math.PI * 2;
points.push(new THREE.Vector3(
radius * Math.cos(angle),
y,
radius * Math.sin(angle)
));
}
const ring = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x8be7ea,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
ring.renderOrder = 3;
coneGroup.add(ring);
}
}
function planeBasis() {
const tilt = THREE.MathUtils.degToRad(state.tilt);
const azimuth = THREE.MathUtils.degToRad(state.azimuth);
const n = new THREE.Vector3(
Math.sin(tilt) * Math.cos(azimuth),
Math.cos(tilt),
Math.sin(tilt) * Math.sin(azimuth)
).normalize();
const e1 = new THREE.Vector3(
-Math.sin(azimuth),
0,
Math.cos(azimuth)
).normalize();
const e2 = new THREE.Vector3().crossVectors(n, e1).normalize();
return { n, e1, e2 };
}
function buildPlane() {
clearGroup(planeGroup);
const { n } = planeBasis();
const center = n.clone().multiplyScalar(state.offset);
const size = 10.6;
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(size, size, 8, 8),
new THREE.MeshBasicMaterial({
color: 0x9d7cff,
transparent: true,
opacity: 0.085,
side: THREE.DoubleSide,
depthWrite: false
})
);
plane.position.copy(center);
plane.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, 1), n);
plane.renderOrder = 0;
planeGroup.add(plane);
const gridPoints = [];
const divisions = 8;
const half = size / 2;
for (let i = 0; i <= divisions; i++) {
const p = -half + size * i / divisions;
gridPoints.push(
new THREE.Vector3(-half, p, 0.012),
new THREE.Vector3(half, p, 0.012),
new THREE.Vector3(p, -half, 0.012),
new THREE.Vector3(p, half, 0.012)
);
}
const grid = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(gridPoints),
new THREE.LineBasicMaterial({
color: 0xb59aff,
transparent: true,
opacity: 0.27,
depthWrite: false
})
);
grid.position.copy(center);
grid.quaternion.copy(plane.quaternion);
grid.renderOrder = 4;
planeGroup.add(grid);
const borderPoints = [
new THREE.Vector3(-half, -half, 0.018),
new THREE.Vector3(half, -half, 0.018),
new THREE.Vector3(half, half, 0.018),
new THREE.Vector3(-half, half, 0.018)
];
const border = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(borderPoints),
new THREE.LineBasicMaterial({
color: 0xc4afff,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
border.position.copy(center);
border.quaternion.copy(plane.quaternion);
border.renderOrder = 5;
planeGroup.add(border);
const handle = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 12, 8),
new THREE.MeshBasicMaterial({ color: 0xffb765 })
);
handle.position.copy(center);
planeGroup.add(handle);
const arrow = new THREE.ArrowHelper(
n,
center.clone().addScaledVector(n, 0.08),
1.55,
0xffb765,
0.34,
0.18
);
arrow.traverse(child => {
if (child.material) {
child.material.depthTest = false;
child.material.transparent = true;
child.material.opacity = 0.95;
}
});
arrow.renderOrder = 8;
planeGroup.add(arrow);
}
function dot(a, b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
function coneQuadratic(v, slope) {
return v.x * v.x + v.z * v.z - slope * slope * v.y * v.y;
}
function rotateUV(u, v, c, s) {
return {
u: c * u - s * v,
v: s * u + c * v
};
}
function uvToWorld(u, v, basis, p0) {
return new THREE.Vector3(
p0.x + basis.e1.x * u + basis.e2.x * v,
p0.y + basis.e1.y * u + basis.e2.y * v,
p0.z + basis.e1.z * u + basis.e2.z * v
);
}
function validWorld(u, v, basis, p0, limit = 16) {
const point = uvToWorld(u, v, basis, p0);
return point.lengthSq() <= limit * limit;
}
function splitSamples(samples) {
const runs = [];
let current = [];
for (const sample of samples) {
if (sample.valid) {
current.push(sample.uv);
} else {
if (current.length > 1) runs.push({ uv: current, closed: false });
current = [];
}
}
if (current.length > 1) runs.push({ uv: current, closed: false });
return runs;
}
function analyzeConic() {
const basis = planeBasis();
const slope = Math.tan(THREE.MathUtils.degToRad(state.alpha));
const p0 = basis.n.clone().multiplyScalar(state.offset);
const a = coneQuadratic(basis.e1, slope);
const b =
basis.e1.x * basis.e2.x -
slope * slope * basis.e1.y * basis.e2.y +
basis.e1.z * basis.e2.z;
const c = coneQuadratic(basis.e2, slope);
const rp1 = new THREE.Vector3(
p0.x,
-slope * slope * p0.y,
p0.z
);
const L = 2 * rp1.dot(basis.e1);
const M = 2 * rp1.dot(basis.e2);
const F = coneQuadratic(p0, slope);
const trace = a + c;
const difference = a - c;
const discriminant = Math.sqrt(difference * difference + 4 * b * b);
let lambda0 = (trace + discriminant) / 2;
let lambda1 = (trace - discriminant) / 2;
const angle = 0.5 * Math.atan2(2 * b, difference);
const co = Math.cos(angle);
const si = Math.sin(angle);
let g1 = L * co + M * si;
let g2 = -L * si + M * co;
const determinant = lambda0 * lambda1;
const matrixScale = Math.max(1, Math.abs(a) + Math.abs(c));
const rankOne = Math.abs(determinant) < 1e-8 * matrixScale;
const common = {
basis,
p0,
a,
b,
c,
L,
M,
F,
determinant
};
if (rankOne) {
if (Math.abs(lambda0) < Math.abs(lambda1)) {
[lambda0, lambda1] = [lambda1, lambda0];
g1 = -L * si + M * co;
g2 = L * co + M * si;
}
if (lambda0 < 0) {
lambda0 = -lambda0;
g1 = -g1;
g2 = -g2;
F = -F;
}
if (Math.abs(g2) > 1e-7) {
const vertexS = -g1 / (2 * lambda0);
const vertexT = -(
lambda0 * vertexS * vertexS +
g1 * vertexS +
F
) / g2;
const samples = [];
const count = 700;
for (let i = 0; i <= count; i++) {
const q = -10 + 20 * i / count;
const s = vertexS + q;
const t = -(
lambda0 * s * s +
g1 * s +
F
) / g2;
samples.push({
uv: rotateUV(s, t, co, si),
valid: validWorld(
rotateUV(s, t, co, si).u,
rotateUV(s, t, co, si).v,
basis,
p0
)
});
}
return {
...common,
kind: 'parabola',
title: 'Parabola',
kicker: 'Unbounded conic',
description: 'The plane is parallel to a cone generator, so the section opens without bound.',
topology: 'Open / unbounded',
nappe: 'One nappe',
residual: vertexT,
runs: splitSamples(samples),
color: COLORS.parabola
};
}
const rootDiscriminant = g1 * g1 - 4 * lambda0 * F;
const tolerance = 1e-8 * Math.max(1, Math.abs(F), g1 * g1);
if (rootDiscriminant < -tolerance) {
return {
...common,
kind: 'empty',
title: 'No intersection',
kicker: 'Empty section',
description: 'The plane lies outside the cone surface, so the section is empty.',
topology: 'Empty',
nappe: 'No contact',
residual: rootDiscriminant,
runs: [],
color: COLORS.empty
};
}
const roots = rootDiscriminant > tolerance
? [
(-g1 - Math.sqrt(rootDiscriminant)) / (2 * lambda0),
(-g1 + Math.sqrt(rootDiscriminant)) / (2 * lambda0)
]
: [(-g1) / (2 * lambda0)];
const runs = [];
for (const root of roots) {
const samples = [];
const count = 500;
for (let i = 0; i <= count; i++) {
const t = -20 + 40 * i / count;
const uv = rotateUV(root, t, co, si);
samples.push({ uv, valid: validWorld(uv.u, uv.v, basis, p0) });
}
runs.push(...splitSamples(samples));
}
if (roots.length === 1) {
return {
...common,
kind: 'degenerate',
title: 'Single line',
kicker: 'Degenerate conic',
description: 'The plane is tangent to the cone and contains exactly one generator.',
topology: 'One line',
nappe: 'One generator',
residual: rootDiscriminant,
runs,
color: COLORS.degenerate
};
}
return {
...common,
kind: 'degenerate',
title: 'Two parallel lines',
kicker: 'Degenerate conic',
description: 'The restricted quadratic factors into two distinct parallel lines.',
topology: 'Two lines',
nappe: 'Parallel generators',
residual: rootDiscriminant,
runs,
color: COLORS.degenerate
};
}
if (determinant > 0) {
if (lambda0 < 0) {
lambda0 = -lambda0;
lambda1 = -lambda1;
g1 = -g1;
g2 = -g2;
F = -F;
}
const centerS = -g1 / (2 * lambda0);
const centerT = -g2 / (2 * lambda1);
const residual = F -
g1 * g1 / (4 * lambda0) -
g2 * g2 / (4 * lambda1);
const tolerance = 1e-8 * Math.max(
1,
Math.abs(F),
g1 * g1,
g2 * g2
);
if (residual > tolerance) {
return {
...common,
kind: 'empty',
title: 'No intersection',
kicker: 'Empty section',
description: 'The plane lies outside the cone surface, so the section is empty.',
topology: 'Empty',
nappe: 'No contact',
residual,
runs: [],
color: COLORS.empty
};
}
if (Math.abs(residual) <= tolerance) {
const uv = rotateUV(centerS, centerT, co, si);
return {
...common,
kind: 'point',
title: 'Single point',
kicker: 'Degenerate conic',
description: 'The plane touches the cone at exactly one point.',
topology: 'One point',
nappe: 'Tangency point',
residual,
runs: [{ uv: [uv], closed: false }],
color: COLORS.point
};
}
const radiusS = Math.sqrt(-residual / lambda0);
const radiusT = Math.sqrt(-residual / lambda1);
const uv = [];
for (let i = 0; i < 240; i++) {
const angleValue = i / 240 * Math.PI * 2;
const s = centerS + radiusS * Math.cos(angleValue);
const t = centerT + radiusT * Math.sin(angleValue);
uv.push(rotateUV(s, t, co, si));
}
const isCircle = state.tilt < 0.01;
return {
...common,
kind: isCircle ? 'circle' : 'ellipse',
title: isCircle ? 'Circle' : 'Ellipse',
kicker: 'Bounded conic',
description: isCircle
? 'The plane is perpendicular to the cone axis; rotational symmetry produces a circle.'
: 'The plane meets one nappe in a bounded closed curve.',
topology: 'Closed',
nappe: 'One nappe',
residual,
runs: [{ uv, closed: true }],
color: COLORS.ellipse
};
}
const centerS = -g1 / (2 * lambda0);
const centerT = -g2 / (2 * lambda1);
const residual = F -
g1 * g1 / (4 * lambda0) -
g2 * g2 / (4 * lambda1);
const tolerance = 1e-8 * Math.max(
1,
Math.abs(F),
g1 * g1,
g2 * g2
);
if (Math.abs(residual) <= tolerance) {
const ratio = Math.sqrt(lambda0 / Math.abs(lambda1));
const runs = [];
for (const sign of [-1, 1]) {
const samples = [];
const count = 600;
for (let i = 0; i <= count; i++) {
const s = centerS - 20 + 40 * i / count;
const t = centerT + sign * ratio * (s - centerS);
const uv = rotateUV(s, t, co, si);
samples.push({ uv, valid: validWorld(uv.u, uv.v, basis, p0) });
}
runs.push(...splitSamples(samples));
}
return {
...common,
kind: 'degenerate',
title: 'Two intersecting lines',
kicker: 'Degenerate conic',
description: 'The plane passes through the apex and collapses to two generator lines.',
topology: 'Two crossing lines',
nappe: 'Both nappes',
residual,
runs,
color: COLORS.degenerate
};
}
const runs = [];
const count = 650;
if (residual < 0) {
const a = Math.sqrt(-residual / lambda0);
const b = Math.sqrt(-residual / Math.abs(lambda1));
for (const branch of [-1, 1]) {
const samples = [];
for (let i = 0; i <= count; i++) {
const q = -3.7 + 7.4 * i / count;
const s = centerS + branch * a * Math.cosh(q);
const t = centerT + b * Math.sinh(q);
const uv = rotateUV(s, t, co, si);
samples.push({ uv, valid: validWorld(uv.u, uv.v, basis, p0) });
}
runs.push(...splitSamples(samples));
}
} else {
const a = Math.sqrt(residual / lambda0);
const b = Math.sqrt(residual / Math.abs(lambda1));
for (const branch of [-1, 1]) {
const samples = [];
for (let i = 0; i <= count; i++) {
const q = -3.7 + 7.4 * i / count;
const s = centerS + a * Math.sinh(q);
const t = centerT + branch * b * Math.cosh(q);
const uv = rotateUV(s, t, co, si);
samples.push({ uv, valid: validWorld(uv.u, uv.v, basis, p0) });
}
runs.push(...splitSamples(samples));
}
}
return {
...common,
kind: 'hyperbola',
title: 'Hyperbola',
kicker: 'Unbounded conic',
description: 'The plane cuts both nappes, producing two disconnected unbounded branches.',
topology: 'Two open branches',
nappe: 'Both nappes',
residual,
runs,
color: COLORS.hyperbola
};
}
function buildCurve(result) {
clearGroup(curveGroup);
const { basis, p0 } = result;
const degenerate = result.kind === 'degenerate';
for (const run of result.runs) {
const points = run.uv.map(uv => uvToWorld(uv.u, uv.v, basis, p0));
if (points.length < 2) continue;
const material = degenerate
? new THREE.LineDashedMaterial({
color: result.color,
dashSize: 0.24,
gapSize: 0.11,
transparent: true,
opacity: 0.98,
depthTest: false
})
: new THREE.LineBasicMaterial({
color: result.color,
transparent: true,
opacity: 0.98,
depthTest: false
});
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = run.closed && points.length > 2
? new THREE.LineLoop(geometry, material)
: new THREE.Line(geometry, material);
if (degenerate) line.computeLineDistances();
line.renderOrder = 10;
curveGroup.add(line);
}
if (result.kind === 'point' && result.runs.length) {
const uv = result.runs[0].uv[0];
const point = uvToWorld(uv.u, uv.v, basis, p0);
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 16, 10),
new THREE.MeshBasicMaterial({
color: result.color,
depthTest: false
})
);
marker.position.copy(point);
marker.renderOrder = 11;
curveGroup.add(marker);
}
}
function drawPlot(result) {
const canvas = $('plot');
const rect = canvas.getBoundingClientRect();
const dpr = Math.min(devicePixelRatio, 2);
const width = Math.max(1, rect.width);
const height = Math.max(1, rect.height);
canvas.width = Math.round(width * dpr);
canvas.height = Math.round(height * dpr);
const ctx = canvas.getContext('2d');
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, width, height);
const points = result.runs.flatMap(run => run.uv);
ctx.strokeStyle = 'rgba(123, 179, 190, 0.09)';
ctx.lineWidth = 1;
for (let i = 1; i < 6; i++) {
const x = width * i / 6;
const y = height * i / 6;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, height);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, y);
ctx.lineTo(width, y);
ctx.stroke();
}
if (!points.length) {
ctx.fillStyle = '#607c85';
ctx.font = '10px system-ui';
ctx.textAlign = 'center';
ctx.fillText('empty section', width / 2, height / 2 + 3);
return;
}
let minU = Infinity, maxU = -Infinity;
let minV = Infinity, maxV = -Infinity;
for (const point of points) {
minU = Math.min(minU, point.u);
maxU = Math.max(maxU, point.u);
minV = Math.min(minV, point.v);
maxV = Math.max(maxV, point.v);
}
if (result.kind === 'point') {
minU -= 1;
maxU += 1;
minV -= 1;
maxV += 1;
}
const rangeU = Math.max(0.001, maxU - minU);
const rangeV = Math.max(0.001, maxV - minV);
const scale = Math.min((width - 28) / rangeU, (height - 28) / rangeV);
const centerU = (minU + maxU) / 2;
const centerV = (minV + maxV) / 2;
const map = point => ({
x: width / 2 + (point.u - centerU) * scale,
y: height / 2 - (point.v - centerV) * scale
});
const origin = map({ u: centerU, v: centerV });
ctx.strokeStyle = 'rgba(151, 206, 215, 0.22)';
ctx.beginPath();
ctx.moveTo(origin.x, 0);
ctx.lineTo(origin.x, height);
ctx.moveTo(0, origin.y);
ctx.lineTo(width, origin.y);
ctx.stroke();
const color = `#${result.color.toString(16).padStart(6, '0')}`;
ctx.strokeStyle = color;
ctx.lineWidth = result.kind === 'degenerate' ? 1.5 : 2;
ctx.shadowColor = color;
ctx.shadowBlur = 7;
for (const run of result.runs) {
if (run.uv.length < 2) continue;
ctx.beginPath();
run.uv.forEach((point, index) => {
const mapped = map(point);
if (index === 0) ctx.moveTo(mapped.x, mapped.y);
else ctx.lineTo(mapped.x, mapped.y);
});
if (run.closed) ctx.closePath();
ctx.stroke();
}
ctx.shadowBlur = 0;
}
function updateReadout(result) {
const panel = $('panel');
panel.style.setProperty('--accent', `#${result.color.toString(16).padStart(6, '0')}`);
$('status-kicker').textContent = result.kicker;
$('section-classification').textContent = result.kicker;
$('status-title').textContent = result.title;
$('status-description').textContent = result.description;
$('plot-kind').textContent = result.kind;
$('metric-topology').textContent = result.topology;
$('metric-nappe').textContent = result.nappe;
$('metric-det').textContent = result.determinant.toFixed(3);
$('metric-residual').textContent = result.residual.toFixed(3);
const n = result.basis.n;
const normalText = [n.x, n.y, n.z]
.map(value => (value >= 0 ? '+' : '') + value.toFixed(3))
.join(' ');
$('equation').innerHTML = `
<div>Plane: (${normalText}) · x = ${state.offset.toFixed(2)}</div>
<div>Plane coordinates: x = ${state.offset.toFixed(2)}n + u·e₁ + v·e₂</div>
<div>Conic: ${result.a.toFixed(3)}u² + ${(2 * result.b).toFixed(3)}uv +
${result.c.toFixed(3)}v² + ${result.L.toFixed(3)}u +
${result.M.toFixed(3)}v + ${result.F.toFixed(3)} = 0</div>
`;
}
function recompute(rebuildCone = false) {
if (rebuildCone) buildCone();
buildPlane();
const result = analyzeConic();
buildCurve(result);
updateReadout(result);
drawPlot(result);
}
function syncControls() {
$('alpha').value = state.alpha;
$('tilt').value = state.tilt;
$('azimuth').value = state.azimuth;
$('offset').value = state.offset;
$('alpha-out').textContent = `${Number(state.alpha).toFixed(1)}°`;
$('tilt-out').textContent = `${Number(state.tilt).toFixed(2)}°`;
$('azimuth-out').textContent = `${Number(state.azimuth).toFixed(1)}°`;
$('offset-out').textContent = Number(state.offset).toFixed(2);
}
function applyPreset(name) {
const alpha = state.alpha;
switch (name) {
case 'circle':
state.tilt = 0;
state.azimuth = 0;
state.offset = 1.5;
break;
case 'ellipse':
state.tilt = Math.max(5, (90 - alpha) * 0.43);
state.azimuth = 0;
state.offset = 1.5;
break;
case 'parabola':
state.tilt = 90 - alpha;
state.azimuth = 0;
state.offset = 1.25;
break;
case 'hyperbola':
state.tilt = Math.min(89, 90 - alpha + 18);
state.azimuth = 0;
state.offset = 1.0;
break;
case 'tangent':
state.tilt = 90 - alpha;
state.azimuth = 0;
state.offset = 0;
break;
case 'apex':
state.tilt = 90;
state.azimuth = 0;
state.offset = 0;
break;
case 'point':
state.tilt = 0;
state.azimuth = 0;
state.offset = 0;
break;
}
syncControls();
recompute(true);
}
['alpha', 'tilt', 'azimuth', 'offset'].forEach(id => {
$(id).addEventListener('input', event => {
state[id] = Number(event.target.value);
syncControls();
recompute(id === 'alpha');
});
});
document.querySelectorAll('[data-preset]').forEach(button => {
button.addEventListener('click', () => applyPreset(button.dataset.preset));
});
$('sweep').addEventListener('click', () => {
state.sweeping = !state.sweeping;
$('sweep').textContent = state.sweeping ? 'Pause offset sweep' : 'Start offset sweep';
$('sweep').classList.toggle('primary', state.sweeping);
});
function updateCamera() {
const { radius, theta, phi, target } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let shiftPressed = false;
sceneCanvas.addEventListener('pointerdown', event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
shiftPressed = event.shiftKey;
sceneCanvas.setPointerCapture(event.pointerId);
});
sceneCanvas.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (shiftPressed) {
const panScale = cameraState.radius * 0.0015;
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(up, dy * panScale);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.18,
Math.PI - 0.18
);
}
});
sceneCanvas.addEventListener('pointerup', event => {
dragging = false;
if (sceneCanvas.hasPointerCapture(event.pointerId)) {
sceneCanvas.releasePointerCapture(event.pointerId);
}
});
sceneCanvas.addEventListener('pointercancel', () => {
dragging = false;
});
sceneCanvas.addEventListener('wheel', event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
8,
34
);
}, { passive: false });
addEventListener('resize', () => {
renderer.setSize(innerWidth, innerHeight);
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
drawPlot(analyzeConic());
});
buildRig();
syncControls();
recompute(true);
updateCamera();
$('loading').style.display = 'none';
const clock = new THREE.Clock();
let sweepTime = 0;
let lastSweepUpdate = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (state.sweeping) {
sweepTime += delta;
if (performance.now() - lastSweepUpdate > 35) {
state.offset = 2.05 * Math.sin(sweepTime * 0.72);
syncControls();
recompute(false);
lastSweepUpdate = performance.now();
}
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```