Prompt specification
Build or customize the Three.js 3D scene "Cone intersected by a movable plane" 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: Cone intersected by a movable plane
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cone-intersected-by-a-movable-plane-x1685
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing conic sections made by intersecting a cone and plane. Build a transparent double cone and a clearly visible slicing plane; display the intersection curve with labels that depend on the chosen plane orientation. Low-poly.
Working Three.js Starter (cone-intersected-by-a-movable-plane-x1685):
```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 Explorer</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(10, 22, 39, 0.88);
--border: rgba(155, 213, 255, 0.16);
--text: #eaf6ff;
--muted: #91abc2;
--cyan: #58d8ff;
--orange: #ffb347;
--green: #78f0b1;
}
* {
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;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#panel {
position: absolute;
top: 18px;
left: 18px;
width: min(340px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 22px 60px rgba(0, 0, 0, 0.38),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(16px);
z-index: 10;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.1;
letter-spacing: -0.03em;
}
.subtitle {
margin: 8px 0 18px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.section-title {
margin: 17px 0 10px;
color: #b8d3e8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 7px;
}
button {
appearance: none;
border: 1px solid rgba(148, 205, 244, 0.18);
border-radius: 10px;
padding: 9px 10px;
background: rgba(86, 139, 179, 0.11);
color: #d8edfb;
font: inherit;
font-size: 12px;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(88, 216, 255, 0.16);
border-color: rgba(88, 216, 255, 0.5);
transform: translateY(-1px);
}
button.active {
color: #061421;
background: var(--cyan);
border-color: var(--cyan);
font-weight: 750;
}
.control {
margin: 14px 0;
}
.control-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
}
.control-row output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
font-weight: 750;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(
90deg,
rgba(88, 216, 255, 0.9),
rgba(88, 216, 255, 0.18)
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 2px solid #dff7ff;
border-radius: 50%;
background: #2ebce8;
box-shadow: 0 0 0 4px rgba(88, 216, 255, 0.12);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 2px solid #dff7ff;
border-radius: 50%;
background: #2ebce8;
}
.result {
margin-top: 18px;
padding: 14px;
border: 1px solid rgba(255, 179, 71, 0.3);
border-radius: 13px;
background:
radial-gradient(circle at top right, rgba(255, 179, 71, 0.12), transparent 60%),
rgba(255, 179, 71, 0.045);
}
.result-kicker {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#conicName {
margin-top: 3px;
color: var(--orange);
font-size: 24px;
font-weight: 850;
letter-spacing: -0.035em;
}
#description {
min-height: 36px;
margin-top: 6px;
color: #bdd2e3;
font-size: 11px;
line-height: 1.45;
}
.equation {
margin-top: 10px;
padding: 9px 10px;
border-radius: 9px;
background: rgba(0, 0, 0, 0.24);
color: #cfe9fa;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
font-size: 11px;
line-height: 1.55;
overflow-wrap: anywhere;
}
.legend {
display: grid;
gap: 8px;
margin-top: 15px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 17px;
height: 4px;
border-radius: 9px;
flex: 0 0 auto;
}
.swatch.cone {
background: #9ad7ff;
opacity: 0.65;
}
.swatch.plane {
background: var(--cyan);
}
.swatch.curve {
background: var(--orange);
box-shadow: 0 0 8px rgba(255, 179, 71, 0.55);
}
#hint {
position: absolute;
right: 18px;
bottom: 16px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(7, 17, 31, 0.68);
color: #9cb7cd;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(10px);
z-index: 5;
}
@media (max-width: 650px) {
#panel {
top: auto;
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
max-height: 45vh;
padding: 16px;
}
h1 {
font-size: 20px;
}
#hint {
top: 12px;
right: 12px;
bottom: auto;
}
}
</style>
</head>
<body>
<div id="panel">
<h1>Conic Section Explorer</h1>
<div class="subtitle">
Intersect a low-poly double cone with a movable plane.
The intersection label and classification update in real time.
</div>
<div class="section-title">Preset cuts</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>
</div>
<div class="section-title">Plane orientation</div>
<div class="control">
<div class="control-row">
<label for="tilt">Tilt from horizontal</label>
<output id="tiltValue">38°</output>
</div>
<input id="tilt" type="range" min="0" max="80" step="0.25" value="38" />
</div>
<div class="control">
<div class="control-row">
<label for="spin">Azimuth</label>
<output id="spinValue">20°</output>
</div>
<input id="spin" type="range" min="0" max="360" step="1" value="20" />
</div>
<div class="control">
<div class="control-row">
<label for="offset">Signed plane offset</label>
<output id="offsetValue">0.90</output>
</div>
<input id="offset" type="range" min="-1.5" max="1.5" step="0.01" value="0.9" />
</div>
<div class="result">
<div class="result-kicker">Intersection curve</div>
<div id="conicName">Ellipse</div>
<div id="description"></div>
<div id="equation" class="equation"></div>
</div>
<div class="section-title">Scene legend</div>
<div class="legend">
<div class="legend-item">
<span class="swatch cone"></span>
Transparent 16-sided double cone
</div>
<div class="legend-item">
<span class="swatch plane"></span>
Slicing plane
</div>
<div class="legend-item">
<span class="swatch curve"></span>
Cone–plane intersection
</div>
</div>
<div class="section-title">Camera</div>
<button id="resetCamera" style="width: 100%">Reset camera</button>
</div>
<div id="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance",
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.035);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
yaw: 0.64,
pitch: 0.36,
radius: 9.3,
target: new THREE.Vector3(0, 0, 0),
};
function updateCamera() {
const { yaw, pitch, radius, target } = cameraState;
const horizontal = Math.cos(pitch) * radius;
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + Math.sin(pitch) * radius,
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xb8e7ff, 0x162033, 2.2));
const keyLight = new THREE.DirectionalLight(0xffffff, 2.4);
keyLight.position.set(4, 6, 5);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x42c8ff, 1.5);
rimLight.position.set(-5, 1, -4);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Constants and low-poly double cone
// ---------------------------------------------------------------------
const CONE_HALF_ANGLE = THREE.MathUtils.degToRad(28);
const CONE_HEIGHT = 3.2;
const CONE_RADIUS = Math.tan(CONE_HALF_ANGLE) * CONE_HEIGHT;
const PARABOLA_TILT = THREE.MathUtils.degToRad(90) - CONE_HALF_ANGLE;
const RADIAL_SEGMENTS = 16;
const PLANE_SIZE = 8;
function createDoubleCone() {
const group = new THREE.Group();
const surfacePositions = [];
const wirePositions = [];
for (const sign of [1, -1]) {
const ring = [];
for (let i = 0; i < RADIAL_SEGMENTS; i++) {
const angle = (i / RADIAL_SEGMENTS) * Math.PI * 2;
ring.push(
new THREE.Vector3(
Math.cos(angle) * CONE_RADIUS,
Math.sin(angle) * CONE_RADIUS,
sign * CONE_HEIGHT
)
);
}
// Independent triangles preserve the intended faceted appearance.
for (let i = 0; i < RADIAL_SEGMENTS; i++) {
const p1 = ring[i];
const p2 = ring[(i + 1) % RADIAL_SEGMENTS];
const apex = new THREE.Vector3(0, 0, 0);
surfacePositions.push(
apex.x, apex.y, apex.z,
p1.x, p1.y, p1.z,
p2.x, p2.y, p2.z
);
}
// Generator edges and polygonal end rim.
for (let i = 0; i < RADIAL_SEGMENTS; i++) {
const p1 = ring[i];
const p2 = ring[(i + 1) % RADIAL_SEGMENTS];
wirePositions.push(0, 0, 0, p1.x, p1.y, p1.z);
wirePositions.push(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
}
}
const surfaceGeometry = new THREE.BufferGeometry();
surfaceGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(surfacePositions, 3)
);
surfaceGeometry.computeVertexNormals();
const surfaceMaterial = new THREE.MeshPhongMaterial({
color: 0x9ad7ff,
transparent: true,
opacity: 0.15,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true,
shininess: 45,
specular: 0x8edfff,
});
const surface = new THREE.Mesh(surfaceGeometry, surfaceMaterial);
surface.renderOrder = 2;
group.add(surface);
const wireGeometry = new THREE.BufferGeometry();
wireGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(wirePositions, 3)
);
const wireMaterial = new THREE.LineBasicMaterial({
color: 0xb9e9ff,
transparent: true,
opacity: 0.31,
depthWrite: false,
});
const wire = new THREE.LineSegments(wireGeometry, wireMaterial);
wire.renderOrder = 3;
group.add(wire);
return group;
}
scene.add(createDoubleCone());
// Cone axis.
const axisGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0, -CONE_HEIGHT - 0.35),
new THREE.Vector3(0, 0, CONE_HEIGHT + 0.35),
]);
const axis = new THREE.Line(
axisGeometry,
new THREE.LineDashedMaterial({
color: 0x86a9c1,
dashSize: 0.12,
gapSize: 0.09,
transparent: true,
opacity: 0.65,
})
);
axis.computeLineDistances();
scene.add(axis);
// Subtle floor grid, placed perpendicular to the cone axis.
const floorGrid = new THREE.GridHelper(10, 20, 0x31516b, 0x20384b);
floorGrid.rotation.x = Math.PI / 2;
floorGrid.position.z = -CONE_HEIGHT - 0.04;
floorGrid.material.transparent = true;
floorGrid.material.opacity = 0.22;
floorGrid.material.depthWrite = false;
scene.add(floorGrid);
// ---------------------------------------------------------------------
// Slicing plane
// ---------------------------------------------------------------------
const planeGroup = new THREE.Group();
const planeGeometry = new THREE.PlaneGeometry(PLANE_SIZE, PLANE_SIZE);
const planeMaterial = new THREE.MeshBasicMaterial({
color: 0x28b9ee,
transparent: true,
opacity: 0.18,
side: THREE.DoubleSide,
depthWrite: false,
});
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial);
planeMesh.renderOrder = 1;
planeGroup.add(planeMesh);
const planeBorder = new THREE.LineSegments(
new THREE.EdgesGeometry(planeGeometry),
new THREE.LineBasicMaterial({
color: 0x58d8ff,
transparent: true,
opacity: 0.92,
depthTest: false,
depthWrite: false,
})
);
planeBorder.position.z = 0.012;
planeBorder.renderOrder = 6;
planeGroup.add(planeBorder);
// A local grid makes the plane's orientation easy to perceive.
const planeGridPositions = [];
const half = PLANE_SIZE / 2;
const spacing = 0.5;
for (let value = -half; value <= half + 0.001; value += spacing) {
planeGridPositions.push(
-half, value, 0.006,
half, value, 0.006,
value, -half, 0.006,
value, half, 0.006
);
}
const planeGridGeometry = new THREE.BufferGeometry();
planeGridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(planeGridPositions, 3)
);
const planeGrid = new THREE.LineSegments(
planeGridGeometry,
new THREE.LineBasicMaterial({
color: 0x65d9ff,
transparent: true,
opacity: 0.16,
depthWrite: false,
})
);
planeGrid.renderOrder = 2;
planeGroup.add(planeGrid);
scene.add(planeGroup);
// ---------------------------------------------------------------------
// Canvas-sprite labels
// ---------------------------------------------------------------------
function roundedRect(ctx, x, y, w, h, radius) {
const r = Math.min(radius, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function createLabel(
text,
subtext = "",
color = "#58d8ff",
width = 2.4,
height = 0.62
) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
sprite.renderOrder = 20;
function draw(mainText, secondaryText) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 7, 7, 498, 114, 24);
ctx.fillStyle = "rgba(5, 15, 28, 0.86)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 3;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = "800 38px system-ui, sans-serif";
ctx.fillText(mainText, 256, secondaryText ? 48 : 64);
if (secondaryText) {
ctx.fillStyle = "#bdd5e7";
ctx.font = "600 20px system-ui, sans-serif";
ctx.fillText(secondaryText, 256, 91);
}
texture.needsUpdate = true;
}
draw(text, subtext);
return {
sprite,
setLabel(mainText, secondaryText = "") {
draw(mainText, secondaryText);
},
};
}
const planeLabel = createLabel(
"SLICING PLANE",
"movable section",
"#58d8ff",
2.15,
0.55
);
planeLabel.sprite.position.set(-2.65, 2.65, 0.03);
planeGroup.add(planeLabel.sprite);
const coneLabel = createLabel(
"DOUBLE CONE",
"half-angle 28°",
"#b9e9ff",
2.1,
0.55
);
coneLabel.sprite.position.set(-1.75, 1.55, 2.55);
scene.add(coneLabel.sprite);
const axisLabel = createLabel(
"CONE AXIS",
"",
"#89a8bf",
1.5,
0.38
);
axisLabel.sprite.position.set(0.28, -0.38, 3.38);
scene.add(axisLabel.sprite);
const curveLabel = createLabel(
"ELLIPSE",
"bounded closed curve",
"#ffb347",
2.35,
0.64
);
scene.add(curveLabel.sprite);
// ---------------------------------------------------------------------
// Intersection geometry
// ---------------------------------------------------------------------
const curveRoot = new THREE.Group();
scene.add(curveRoot);
const curveLineMaterial = new THREE.LineBasicMaterial({
color: 0xffb347,
transparent: true,
opacity: 1,
depthTest: false,
depthWrite: false,
});
const curvePointMaterial = new THREE.PointsMaterial({
color: 0xffe0a1,
size: 0.055,
sizeAttenuation: true,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false,
});
const state = {
tilt: 38,
spin: 20,
offset: 0.9,
};
const normal = new THREE.Vector3();
const basisU = new THREE.Vector3();
const basisV = new THREE.Vector3();
const zAxis = new THREE.Vector3(0, 0, 1);
function updateBasis() {
const tilt = THREE.MathUtils.degToRad(state.tilt);
const spin = THREE.MathUtils.degToRad(state.spin);
normal.set(
Math.sin(tilt) * Math.cos(spin),
Math.sin(tilt) * Math.sin(spin),
Math.cos(tilt)
);
basisU.set(
-Math.cos(tilt) * Math.cos(spin),
-Math.cos(tilt) * Math.sin(spin),
Math.sin(tilt)
);
basisV.set(-Math.sin(spin), Math.cos(spin), 0);
planeGroup.quaternion.setFromUnitVectors(zAxis, normal);
planeGroup.position.copy(normal).multiplyScalar(state.offset);
}
function worldPoint(u, v) {
return new THREE.Vector3()
.copy(normal)
.multiplyScalar(state.offset)
.addScaledVector(basisU, u)
.addScaledVector(basisV, v);
}
function pointAllowed(point) {
const radial = Math.hypot(point.x, point.y);
return (
Math.abs(point.z) <= CONE_HEIGHT + 0.025 &&
radial <= CONE_RADIUS + 0.035 &&
Math.abs(point.dot(basisU)) <= PLANE_SIZE / 2 + 0.05 &&
Math.abs(point.dot(basisV)) <= PLANE_SIZE / 2 + 0.05
);
}
function clearCurve() {
while (curveRoot.children.length) {
const child = curveRoot.children[0];
if (child.geometry) child.geometry.dispose();
curveRoot.remove(child);
}
}
function addCurveCandidates(candidateArrays) {
const validPoints = [];
function addRun(run) {
if (run.length < 2) return;
const geometry = new THREE.BufferGeometry().setFromPoints(run);
const line = new THREE.Line(geometry, curveLineMaterial);
line.renderOrder = 8;
line.frustumCulled = false;
curveRoot.add(line);
}
for (const candidates of candidateArrays) {
let run = [];
for (const point of candidates) {
if (pointAllowed(point)) {
run.push(point);
validPoints.push(point);
} else {
addRun(run);
run = [];
}
}
addRun(run);
}
if (validPoints.length) {
const pointsGeometry = new THREE.BufferGeometry().setFromPoints(validPoints);
const points = new THREE.Points(pointsGeometry, curvePointMaterial);
points.renderOrder = 9;
points.frustumCulled = false;
curveRoot.add(points);
}
return validPoints;
}
function classifyAndBuild() {
updateBasis();
clearCurve();
const tilt = THREE.MathUtils.degToRad(state.tilt);
const q = Math.tan(CONE_HALF_ANGLE) ** 2;
/*
Restrict the cone equation x² + y² - qz² = 0 to the plane:
A u² + v² + 2D u + F = 0
A > 0: ellipse
A = 0: parabola
A < 0: hyperbola
*/
const A =
Math.cos(tilt) ** 2 -
q * Math.sin(tilt) ** 2;
const D =
-state.offset *
Math.sin(tilt) *
Math.cos(tilt) *
(1 + q);
const F =
state.offset ** 2 *
(Math.sin(tilt) ** 2 - q * Math.cos(tilt) ** 2);
let type = "";
let subtitle = "";
let description = "";
let candidates = [];
let preferredAnchor = null;
const nearlyZeroOffset = Math.abs(state.offset) < 1e-9;
if (Math.abs(A) < 1e-7) {
if (nearlyZeroOffset) {
type = "Generator";
subtitle = "degenerate parabola";
description =
"With the offset set to zero, this limiting plane contains a cone generator.";
const generator = [];
for (let i = 0; i <= 180; i++) {
const u = -4 + (8 * i) / 180;
generator.push(worldPoint(u, 0));
}
candidates = [generator];
} else {
type = "Parabola";
subtitle = "unbounded open curve";
description =
"The plane is parallel to a generator of the cone, producing an open parabola.";
const parabola = [];
const vMax = 8;
for (let i = 0; i <= 420; i++) {
const v = -vMax + (2 * vMax * i) / 420;
const u = -(v * v + F) / (2 * D);
parabola.push(worldPoint(u, v));
}
candidates = [parabola];
preferredAnchor = worldPoint(-F / (2 * D), 0);
}
} else if (A > 0) {
const K = (D * D) / A - F;
if (nearlyZeroOffset || K <= 1e-10) {
type = "Point";
subtitle = "degenerate section";
description =
"This limiting plane touches the cone only at the vertex.";
candidates = [[worldPoint(0, 0)]];
preferredAnchor = worldPoint(0, 0);
} else {
const centerU = -D / A;
const radiusU = Math.sqrt(K / A);
const radiusV = Math.sqrt(K);
if (Math.abs(state.tilt) < 0.001) {
type = "Circle";
subtitle = "round closed curve";
description =
"A plane perpendicular to the cone axis cuts the cone in a circle.";
} else {
type = "Ellipse";
subtitle = "bounded closed curve";
description =
"The tilted plane closes around one nappe of the cone, producing an ellipse.";
}
const ellipse = [];
const segments = 180;
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const u = centerU + radiusU * Math.cos(angle);
const v = radiusV * Math.sin(angle);
ellipse.push(worldPoint(u, v));
}
candidates = [ellipse];
preferredAnchor = worldPoint(centerU, 0);
}
} else {
const K = (D * D) / A - F;
if (nearlyZeroOffset || Math.abs(K) <= 1e-10) {
type = "Pair of Lines";
subtitle = "degenerate hyperbola";
description =
"Through the vertex, this limiting plane contains two straight generators.";
const slope = Math.sqrt(-A);
const first = [];
const second = [];
for (let i = 0; i <= 180; i++) {
const u = -6 + (12 * i) / 180;
first.push(worldPoint(u, slope * u));
second.push(worldPoint(u, -slope * u));
}
candidates = [first, second];
} else {
type = "Hyperbola";
subtitle = "two open branches";
description =
"The steep plane cuts the two nappes of the double cone, producing a hyperbola.";
const H = -K;
const centerU = -D / A;
const a = Math.sqrt(H / -A);
const b = Math.sqrt(H);
const positiveBranch = [];
const negativeBranch = [];
for (let i = 0; i <= 170; i++) {
const s = (4 * i) / 170;
const cosh = Math.cosh(s);
const sinh = Math.sinh(s);
positiveBranch.push(
worldPoint(centerU + a * cosh, b * sinh)
);
negativeBranch.push(
worldPoint(centerU - a * cosh, b * sinh)
);
}
candidates = [positiveBranch, negativeBranch];
}
}
const validPoints = addCurveCandidates(candidates);
let anchor = preferredAnchor;
if (!anchor && validPoints.length) {
anchor = validPoints.reduce((best, point) => {
const bestDistance = Math.abs(best.z);
const pointDistance = Math.abs(point.z);
return pointDistance < bestDistance ? point : best;
}, validPoints[0]);
}
if (!anchor) {
anchor = worldPoint(0, 0);
}
curveLabel.setLabel(type.toUpperCase(), subtitle);
curveLabel.sprite.position.copy(anchor).add(new THREE.Vector3(0, 0.32, 0));
// Update the HTML result card.
document.getElementById("conicName").textContent = type;
document.getElementById("description").textContent = description;
document.getElementById("equation").innerHTML =
`Cone: x² + y² = (z tan 28°)²<br>` +
`Plane: (${normal.x.toFixed(3)}, ${normal.y.toFixed(3)}, ` +
`${normal.z.toFixed(3)}) · (x, y, z) = ${state.offset.toFixed(2)}<br>` +
`Generator inclination: ${THREE.MathUtils.radToDeg(PARABOLA_TILT).toFixed(1)}°`;
}
// ---------------------------------------------------------------------
// UI
// ---------------------------------------------------------------------
const tiltInput = document.getElementById("tilt");
const spinInput = document.getElementById("spin");
const offsetInput = document.getElementById("offset");
const tiltValue = document.getElementById("tiltValue");
const spinValue = document.getElementById("spinValue");
const offsetValue = document.getElementById("offsetValue");
const presetButtons = [...document.querySelectorAll("[data-preset]")];
function clearActivePreset() {
presetButtons.forEach((button) => button.classList.remove("active"));
}
function updateOutputs() {
tiltValue.textContent = `${Number(tiltInput.value).toFixed(2)}°`;
spinValue.textContent = `${Number(spinInput.value).toFixed(0)}°`;
offsetValue.textContent = Number(offsetInput.value).toFixed(2);
}
function readControls() {
state.tilt = Number(tiltInput.value);
state.spin = Number(spinInput.value);
state.offset = Number(offsetInput.value);
updateOutputs();
clearActivePreset();
classifyAndBuild();
}
tiltInput.addEventListener("input", readControls);
spinInput.addEventListener("input", readControls);
offsetInput.addEventListener("input", readControls);
const presets = {
circle: { tilt: 0, spin: 20, offset: 1.15 },
ellipse: { tilt: 38, spin: 20, offset: 0.9 },
parabola: {
tilt: THREE.MathUtils.radToDeg(PARABOLA_TILT),
spin: 35,
offset: 0.9,
},
hyperbola: { tilt: 70, spin: 55, offset: 0.25 },
};
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
const preset = presets[button.dataset.preset];
tiltInput.value = preset.tilt;
spinInput.value = preset.spin;
offsetInput.value = preset.offset;
readControls();
button.classList.add("active");
});
});
// ---------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// ---------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.08,
1.35
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.8,
16
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.64;
cameraState.pitch = 0.36;
cameraState.radius = 9.3;
updateCamera();
});
document.getElementById("resetCamera").addEventListener("click", () => {
cameraState.yaw = 0.64;
cameraState.pitch = 0.36;
cameraState.radius = 9.3;
updateCamera();
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateOutputs();
classifyAndBuild();
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```