Prompt specification
Build or customize the Three.js 3D scene "Intensity-distance exploration tool" 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: Intensity-distance exploration tool
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/intensity-distance-exploration-tool-x1556
Scene Description Prompt:
Explore low-poly isotropic-source intensity versus power and distance, displaying units and flagging the zero-radius singularity. One HTML file using Three.js from cdnjs.
Working Three.js Starter (intensity-distance-exploration-tool-x1556):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Isotropic Source Lab</title>
<style>
:root {
--bg: #071018;
--panel: rgba(13, 24, 34, 0.92);
--panel-solid: #0d1822;
--panel-2: #111f2b;
--line: rgba(160, 196, 220, 0.14);
--line-strong: rgba(160, 196, 220, 0.26);
--text: #e9f2f7;
--muted: #8fa6b5;
--faint: #607887;
--cyan: #62e4ff;
--cyan-soft: rgba(98, 228, 255, 0.14);
--orange: #ff9a55;
--red: #ff6474;
--yellow: #ffd166;
--green: #6ee7a8;
--radius: 16px;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
min-height: 100%;
margin: 0;
}
body {
overflow: hidden;
background:
radial-gradient(circle at 48% 42%, rgba(40, 94, 121, 0.13), transparent 37%),
var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
-webkit-font-smoothing: antialiased;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app-header {
height: 68px;
display: flex;
align-items: center;
gap: 22px;
padding: 0 22px;
border-bottom: 1px solid var(--line);
background: rgba(7, 16, 24, 0.88);
backdrop-filter: blur(18px);
position: relative;
z-index: 10;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 250px;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
transform: rotate(30deg);
border: 1px solid rgba(98, 228, 255, 0.7);
background:
linear-gradient(135deg, transparent 48%, rgba(98, 228, 255, 0.22) 49% 51%, transparent 52%),
rgba(98, 228, 255, 0.05);
box-shadow: 0 0 28px rgba(98, 228, 255, 0.12);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
inset: 6px;
border: 1px solid rgba(98, 228, 255, 0.45);
}
.brand-mark::after {
inset: 12px;
background: var(--cyan);
border: 0;
box-shadow: 0 0 16px var(--cyan);
}
.brand-copy {
display: flex;
flex-direction: column;
line-height: 1.15;
}
.brand-copy strong {
font-size: 13px;
letter-spacing: 0.15em;
font-weight: 750;
}
.eyebrow {
color: var(--faint);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.header-equation {
padding: 9px 14px;
border: 1px solid var(--line);
border-radius: 999px;
color: #c8dbe6;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 13px;
background: rgba(255, 255, 255, 0.025);
}
.header-equation b {
color: var(--cyan);
font-weight: 650;
}
.live-state {
margin-left: auto;
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 10px;
letter-spacing: 0.14em;
white-space: nowrap;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 12px rgba(110, 231, 168, 0.85);
}
.workbench {
height: calc(100vh - 68px);
display: grid;
grid-template-columns: 300px minmax(360px, 1fr) 320px;
grid-template-rows: minmax(380px, 1fr) 238px;
gap: 1px;
background: var(--line);
}
.panel {
background: var(--panel);
min-width: 0;
min-height: 0;
}
.controls-panel {
grid-column: 1;
grid-row: 1 / 3;
padding: 24px 22px;
overflow: auto;
}
.section-kicker {
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 10px;
font-size: 27px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 24px;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
}
.control-group {
padding: 18px 0;
border-top: 1px solid var(--line);
}
.control-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
margin-bottom: 14px;
}
.control-heading label {
display: block;
font-size: 12px;
font-weight: 700;
margin-bottom: 4px;
}
.control-heading small {
color: var(--faint);
font-size: 10px;
}
.control-value {
color: var(--cyan);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
white-space: nowrap;
}
input[type="range"] {
--pct: 50%;
appearance: none;
width: 100%;
height: 4px;
margin: 7px 0 10px;
border-radius: 10px;
outline: none;
background:
linear-gradient(
to right,
var(--cyan) 0,
var(--cyan) var(--pct),
rgba(145, 177, 197, 0.18) var(--pct),
rgba(145, 177, 197, 0.18) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 15px;
border-radius: 50%;
background: #dff8ff;
border: 3px solid var(--cyan);
box-shadow: 0 0 0 4px rgba(98, 228, 255, 0.11);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border-radius: 50%;
background: #dff8ff;
border: 3px solid var(--cyan);
box-shadow: 0 0 0 4px rgba(98, 228, 255, 0.11);
}
.range-extents {
display: flex;
justify-content: space-between;
color: var(--faint);
font-size: 9px;
}
.quick-row {
display: flex;
gap: 6px;
margin-top: 12px;
flex-wrap: wrap;
}
.quick-button,
.small-button,
.reset-button {
border: 1px solid var(--line-strong);
background: rgba(255, 255, 255, 0.025);
border-radius: 8px;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.quick-button {
padding: 6px 9px;
color: var(--muted);
font-size: 10px;
}
.quick-button:hover,
.small-button:hover,
.reset-button:hover {
color: var(--text);
border-color: rgba(98, 228, 255, 0.48);
background: var(--cyan-soft);
}
.quick-button:active,
.small-button:active,
.reset-button:active {
transform: translateY(1px);
}
.danger-button {
color: #ff9ca8;
border-color: rgba(255, 100, 116, 0.32);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 9px 0;
color: #b9cad4;
font-size: 11px;
cursor: pointer;
}
.toggle input {
appearance: none;
width: 33px;
height: 18px;
border-radius: 20px;
background: rgba(135, 167, 188, 0.18);
border: 1px solid var(--line-strong);
position: relative;
cursor: pointer;
transition: background 150ms ease;
}
.toggle input::after {
content: "";
position: absolute;
width: 12px;
height: 12px;
top: 2px;
left: 2px;
border-radius: 50%;
background: #8196a3;
transition:
transform 150ms ease,
background 150ms ease;
}
.toggle input:checked {
background: rgba(98, 228, 255, 0.2);
border-color: rgba(98, 228, 255, 0.45);
}
.toggle input:checked::after {
transform: translateX(15px);
background: var(--cyan);
}
.inverse-note {
margin-top: 18px;
padding: 14px;
border: 1px solid rgba(98, 228, 255, 0.15);
border-left: 2px solid var(--cyan);
border-radius: 0 10px 10px 0;
background: rgba(98, 228, 255, 0.045);
color: var(--muted);
font-size: 10px;
line-height: 1.6;
}
.inverse-note strong {
display: block;
color: #cdebf4;
font-size: 11px;
margin-bottom: 3px;
}
.stage {
grid-column: 2;
grid-row: 1;
position: relative;
overflow: hidden;
background:
radial-gradient(circle at 50% 45%, rgba(43, 90, 115, 0.17), transparent 38%),
linear-gradient(180deg, rgba(10, 20, 29, 0.66), rgba(5, 12, 18, 0.94));
}
#sceneHost {
position: absolute;
inset: 0;
}
#sceneHost canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#sceneHost canvas.dragging {
cursor: grabbing;
}
.stage-top {
position: absolute;
top: 16px;
left: 16px;
right: 16px;
z-index: 3;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.stage-badge {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 9px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(7, 16, 24, 0.62);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
}
.stage-badge .live-dot {
width: 5px;
height: 5px;
}
.reset-button {
padding: 7px 10px;
pointer-events: auto;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.08em;
background: rgba(7, 16, 24, 0.7);
}
.scene-label {
position: absolute;
z-index: 2;
left: 0;
top: 0;
padding: 6px 8px;
border: 1px solid var(--line-strong);
border-radius: 6px;
background: rgba(6, 14, 20, 0.82);
color: #bdd0da;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
white-space: nowrap;
pointer-events: none;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.22);
}
.scene-label::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 12px;
background: linear-gradient(var(--line-strong), transparent);
}
.scene-label.source {
color: var(--orange);
border-color: rgba(255, 154, 85, 0.34);
}
.scene-label.detector {
color: var(--cyan);
border-color: rgba(98, 228, 255, 0.34);
}
.stage-bottom {
position: absolute;
z-index: 3;
left: 16px;
right: 16px;
bottom: 14px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 18px;
pointer-events: none;
}
.scene-legend {
max-width: 420px;
padding: 10px 12px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(7, 16, 24, 0.66);
backdrop-filter: blur(10px);
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 4px;
}
.legend-swatch {
width: 16px;
height: 2px;
background: var(--cyan);
box-shadow: 0 0 8px currentColor;
}
.legend-swatch.shell {
height: 9px;
border: 1px solid rgba(98, 228, 255, 0.6);
background: transparent;
box-shadow: none;
}
.camera-hint {
color: var(--faint);
font-size: 9px;
text-align: right;
white-space: nowrap;
}
.stage-warning {
position: absolute;
z-index: 4;
left: 50%;
top: 50%;
width: min(410px, calc(100% - 34px));
transform: translate(-50%, -50%);
padding: 18px;
border: 1px solid rgba(255, 100, 116, 0.55);
border-radius: 12px;
background: rgba(37, 12, 18, 0.9);
box-shadow:
0 0 0 1px rgba(255, 100, 116, 0.08),
0 25px 70px rgba(0, 0, 0, 0.5);
backdrop-filter: blur(14px);
display: none;
}
.stage-warning.visible {
display: block;
}
.stage-warning strong {
display: block;
color: #ff9ca8;
font-size: 13px;
letter-spacing: 0.08em;
margin-bottom: 7px;
}
.stage-warning p {
margin: 0;
color: #d8afb6;
font-size: 11px;
line-height: 1.55;
}
.metrics-panel {
grid-column: 3;
grid-row: 1;
padding: 22px;
overflow: auto;
}
.result-card {
padding: 20px;
border: 1px solid rgba(98, 228, 255, 0.22);
border-radius: 13px;
background:
linear-gradient(135deg, rgba(98, 228, 255, 0.08), transparent 58%),
rgba(255, 255, 255, 0.018);
transition:
border-color 180ms ease,
background 180ms ease;
}
.result-card.singular {
border-color: rgba(255, 100, 116, 0.55);
background:
linear-gradient(135deg, rgba(255, 100, 116, 0.13), transparent 58%),
rgba(255, 255, 255, 0.018);
}
.result-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.status-pill {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.1em;
}
.status-pill::before {
content: "";
width: 5px;
height: 5px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 8px currentColor;
}
.status-pill.singular {
color: var(--red);
}
.status-pill.zero {
color: var(--cyan);
}
.intensity-display {
margin-top: 15px;
font-family: "SFMono-Regular", Consolas, monospace;
line-height: 1;
}
#intensityValue {
font-size: clamp(32px, 4.2vw, 48px);
letter-spacing: -0.06em;
color: #f4fbff;
}
#intensityUnit {
margin-top: 8px;
color: var(--cyan);
font-size: 12px;
letter-spacing: 0.04em;
}
.singular #intensityValue,
.singular #intensityUnit {
color: var(--red);
}
#intensitySI {
margin-top: 12px;
color: var(--faint);
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 9px;
line-height: 1.45;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1px;
margin-top: 18px;
border: 1px solid var(--line);
border-radius: 10px;
overflow: hidden;
background: var(--line);
}
.metric {
min-height: 66px;
padding: 12px;
background: var(--panel-solid);
}
.metric-label {
color: var(--faint);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric-value {
margin-top: 8px;
color: #dceaf1;
font-family: "SFMono-Regular", Consolas, monospace;
font-size: 12px;
}
.formula-box {
margin-top: 16px;
padding: 15px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.018);
}
.formula-main {
color: #ecf8fc;
font-family: Georgia, "Times New Roman", serif;
font-size: 22px;
text-align: center;
letter-spacing: 0.02em;
}
.formula-main i {
color: var(--cyan);
font-style: italic;
}
.formula-units {
margin-top: 8px;
color: var(--faint);
font-size: 9px;
line-height: 1.55;
text-align: center;
}
.singularity-alert {
display: none;
margin-top: 14px;
padding: 13px;
border: 1px solid rgba(255, 100, 116, 0.35);
border-left: 2px solid var(--red);
border-radius: 0 9px 9px 0;
background: rgba(255, 100, 116, 0.07);
color: #d9abb2;
font-size: 10px;
line-height: 1.6;
}
.singularity-alert.visible {
display: block;
}
.singularity-alert strong {
display: block;
margin-bottom: 4px;
color: #ff9ca8;
font-size: 11px;
}
.reading-note {
margin-top: 18px;
color: var(--muted);
font-size: 10px;
line-height: 1.65;
}
.reading-note strong {
color: #c8dbe5;
}
.chart-deck {
grid-column: 2 / 4;
grid-row: 2;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1px;
min-width: 0;
min-height: 0;
background: var(--line);
}
.chart-card {
min-width: 0;
min-height: 0;
padding: 14px 16px 8px;
background: var(--panel-solid);
}
.chart-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
height: 22px;
}
.chart-heading h2 {
margin: 0;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.03em;
}
.chart-heading span {
color: var(--faint);
font-size: 9px;
}
.chart-wrap {
position: relative;
height: calc(100% - 22px);
min-height: 150px;
}
.chart-wrap canvas {
display: block;
width: 100%;
height: 100%;
}
@media (max-width: 1120px) {
.workbench {
grid-template-columns: 280px minmax(350px, 1fr);
grid-template-rows: minmax(390px, 1fr) 270px 238px;
}
.controls-panel {
grid-column: 1;
grid-row: 1 / 4;
}
.stage {
grid-column: 2;
grid-row: 1;
}
.metrics-panel {
grid-column: 2;
grid-row: 2;
}
.chart-deck {
grid-column: 2;
grid-row: 3;
}
}
@media (max-width: 760px) {
body {
overflow: auto;
}
.app-header {
position: sticky;
top: 0;
height: 62px;
padding: 0 14px;
}
.brand {
min-width: 0;
}
.brand-copy strong {
font-size: 11px;
}
.header-equation,
.live-state {
display: none;
}
.workbench {
display: flex;
flex-direction: column;
height: auto;
gap: 1px;
}
.controls-panel,
.stage,
.metrics-panel,
.chart-deck {
width: 100%;
}
.controls-panel {
order: 1;
padding: 22px 18px;
}
.stage {
order: 2;
height: 62vh;
min-height: 430px;
}
.metrics-panel {
order: 3;
padding: 20px 18px;
}
.chart-deck {
order: 4;
display: flex;
flex-direction: column;
}
.chart-card {
height: 245px;
}
.camera-hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<span class="eyebrow">Field study / 01</span>
<strong>ISOTROPIC SOURCE LAB</strong>
</div>
</div>
<div class="header-equation" aria-label="Inverse square intensity equation">
I(r) = <b>P</b> / 4π<b>r</b>²
</div>
<div class="live-state">
<span class="live-dot"></span>
LIVE PARAMETRIC MODEL
</div>
</header>
<main class="workbench">
<aside class="panel controls-panel">
<div class="section-kicker">Source parameters</div>
<h1>Intensity in free space</h1>
<p class="intro">
Explore the inverse-square law for an ideal isotropic point source.
Power is distributed uniformly over a sphere of radius
<strong>r</strong>.
</p>
<section class="control-group">
<div class="control-heading">
<div>
<label for="powerInput">Source power</label>
<small>Total radiated power P</small>
</div>
<output id="powerOut" class="control-value" for="powerInput">1.20 kW</output>
</div>
<input
id="powerInput"
type="range"
min="0"
max="5000"
step="10"
value="1200"
aria-label="Source power in watts"
>
<div class="range-extents">
<span>0 W</span>
<span>5 kW</span>
</div>
<div class="quick-row" aria-label="Power presets">
<button class="quick-button" data-power="250">250 W</button>
<button class="quick-button" data-power="1200">1.2 kW</button>
<button class="quick-button" data-power="5000">5 kW</button>
</div>
</section>
<section class="control-group">
<div class="control-heading">
<div>
<label for="distanceInput">Observation distance</label>
<small>Radial distance r from source</small>
</div>
<output id="distanceOut" class="control-value" for="distanceInput">6.00 m</output>
</div>
<input
id="distanceInput"
type="range"
min="0"
max="20"
step="0.05"
value="6"
aria-label="Observation distance in metres"
>
<div class="range-extents">
<span>0 m</span>
<span>20 m</span>
</div>
<div class="quick-row" aria-label="Distance presets">
<button class="quick-button" data-distance="1">1 m</button>
<button class="quick-button" data-distance="5">5 m</button>
<button class="quick-button" data-distance="10">10 m</button>
<button class="quick-button danger-button" data-distance="0">
Test r = 0
</button>
</div>
</section>
<section class="control-group">
<div class="section-kicker">Scene layers</div>
<label class="toggle">
<span>Constant-intensity shell</span>
<input id="shellToggle" type="checkbox" checked>
</label>
<label class="toggle">
<span>Directional radiation field</span>
<input id="raysToggle" type="checkbox" checked>
</label>
</section>
<div class="inverse-note">
<strong>Inverse-square behavior</strong>
Doubling the distance reduces intensity to one quarter.
Tripling it reduces intensity to one ninth.
</div>
</aside>
<section class="stage" aria-label="Interactive three-dimensional source visualization">
<div id="sceneHost"></div>
<div class="stage-top">
<div class="stage-badge">
<span class="live-dot"></span>
IDEAL POINT SOURCE / ISOTROPIC
</div>
<button id="resetView" class="reset-button" type="button">RESET VIEW</button>
</div>
<div id="sourceLabel" class="scene-label source">SOURCE · 1.20 kW</div>
<div id="detectorLabel" class="scene-label detector">DETECTOR · 6.00 m</div>
<div id="stageWarning" class="stage-warning" role="alert">
<strong id="warningTitle">ZERO-RADIUS SINGULARITY</strong>
<p id="warningCopy"></p>
</div>
<div class="stage-bottom">
<div class="scene-legend">
<div class="legend-row">
<span class="legend-swatch"></span>
<span>Directional field: equal power per solid angle</span>
</div>
<div class="legend-row">
<span class="legend-swatch shell"></span>
<span id="shellLegendText">Constant-intensity shell at r = 6.00 m</span>
</div>
</div>
<div class="camera-hint">
DRAG TO ORBIT · SCROLL TO ZOOM<br>
DOUBLE-CLICK TO RESET
</div>
</div>
</section>
<aside class="panel metrics-panel">
<div class="section-kicker">Live measurement</div>
<div id="resultCard" class="result-card">
<div class="result-top">
<span class="eyebrow">Observed intensity</span>
<span id="statusPill" class="status-pill">FINITE FIELD</span>
</div>
<div class="intensity-display">
<div id="intensityValue">2.65</div>
<div id="intensityUnit">W/m²</div>
</div>
<div id="intensitySI">I = 2.653 W/m²</div>
</div>
<div class="metric-grid">
<div class="metric">
<div class="metric-label">Power</div>
<div id="metricPower" class="metric-value">1.20 kW</div>
</div>
<div class="metric">
<div class="metric-label">Distance</div>
<div id="metricDistance" class="metric-value">6.00 m</div>
</div>
<div class="metric">
<div class="metric-label">Sphere area</div>
<div id="metricArea" class="metric-value">452.39 m²</div>
</div>
<div class="metric">
<div class="metric-label">Solid angle</div>
<div class="metric-value">4π sr</div>
</div>
</div>
<div class="formula-box">
<div class="formula-main">I = <i>P</i> / (4π<i>r</i>²)</div>
<div class="formula-units">
W ÷ m² = W/m²<br>
Ideal source · no absorption or environmental effects
</div>
</div>
<div id="singularityAlert" class="singularity-alert" role="status">
<strong>Zero-radius singularity</strong>
<span id="singularityCopy"></span>
</div>
<div class="reading-note">
<strong>How to read the scene:</strong>
the faceted wire sphere is an iso-intensity surface through the
detector. Its radius equals the selected observation distance.
The moving markers indicate equal emission in every direction.
<br><br>
This is a point-source idealization. A physical source has finite
size and a near-field limit, so the model must not be extrapolated
into that regime.
</div>
</aside>
<section class="chart-deck">
<article class="chart-card">
<div class="chart-heading">
<h2>Intensity versus distance</h2>
<span>LOGARITHMIC INTENSITY AXIS</span>
</div>
<div class="chart-wrap">
<canvas id="distanceChart" aria-label="Chart of intensity versus distance"></canvas>
</div>
</article>
<article class="chart-card">
<div class="chart-heading">
<h2>Intensity versus source power</h2>
<span>FIXED OBSERVATION DISTANCE</span>
</div>
<div class="chart-wrap">
<canvas id="powerChart" aria-label="Chart of intensity versus source power"></canvas>
</div>
</article>
</section>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// State and DOM
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const state = {
power: 1200,
distance: 6,
showShell: true,
showRays: true
};
const powerInput = $("#powerInput");
const distanceInput = $("#distanceInput");
const powerOut = $("#powerOut");
const distanceOut = $("#distanceOut");
const sceneHost = $("#sceneHost");
const sourceLabel = $("#sourceLabel");
const detectorLabel = $("#detectorLabel");
const stageWarning = $("#stageWarning");
const warningTitle = $("#warningTitle");
const warningCopy = $("#warningCopy");
const shellLegendText = $("#shellLegendText");
const resultCard = $("#resultCard");
const statusPill = $("#statusPill");
const intensityValue = $("#intensityValue");
const intensityUnit = $("#intensityUnit");
const intensitySI = $("#intensitySI");
const metricPower = $("#metricPower");
const metricDistance = $("#metricDistance");
const metricArea = $("#metricArea");
const singularityAlert = $("#singularityAlert");
const singularityCopy = $("#singularityCopy");
const distanceChart = $("#distanceChart");
const powerChart = $("#powerChart");
const prefersReducedMotion =
window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function intensityAt(power = state.power, distance = state.distance) {
if (distance === 0) {
return power > 0 ? Infinity : NaN;
}
return power / (4 * Math.PI * distance * distance);
}
function formatPower(power) {
if (power >= 1000) {
return `${(power / 1000).toFixed(power % 1000 === 0 ? 0 : 2)} kW`;
}
return `${power.toFixed(0)} W`;
}
function formatDistance(distance) {
return `${distance.toFixed(2)} m`;
}
function formatArea(area) {
if (area >= 1000) {
return `${(area / 1000).toFixed(2)} km²`;
}
return `${area.toFixed(2)} m²`;
}
function scientific(value) {
if (value === 0) return "0";
if (value >= 10000 || value < 0.01) {
return value.toExponential(3);
}
return Number(value.toPrecision(4)).toString();
}
function intensityParts(value) {
if (!Number.isFinite(value)) {
return { value: value === Infinity ? "∞" : "—", unit: value === Infinity ? "W/m²" : "—" };
}
const absolute = Math.abs(value);
if (absolute === 0) return { value: "0", unit: "W/m²" };
if (absolute >= 1000) {
return {
value: (value / 1000).toFixed(value >= 10000 ? 1 : 2),
unit: "kW/m²"
};
}
if (absolute >= 1) {
return { value: value.toFixed(value >= 100 ? 1 : 2), unit: "W/m²" };
}
if (absolute >= 1e-3) {
return { value: (value * 1e3).toFixed(2), unit: "mW/m²" };
}
if (absolute >= 1e-6) {
return { value: (value * 1e6).toFixed(2), unit: "µW/m²" };
}
return { value: value.toExponential(2), unit: "W/m²" };
}
function axisIntensity(value) {
const absolute = Math.abs(value);
if (absolute === 0) return "0";
if (absolute >= 1000) return `${(value / 1000).toFixed(absolute >= 10000 ? 0 : 1)}k`;
if (absolute >= 1) return value.toFixed(value >= 100 ? 0 : 1);
if (absolute >= 1e-3) return `${(value * 1e3).toFixed(0)}m`;
if (absolute >= 1e-6) return `${(value * 1e6).toFixed(0)}µ`;
return value.toExponential(0);
}
function updateRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--pct", `${percentage}%`);
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x08111a, 0.023);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 200);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly isotropic radiation field. Drag to orbit and scroll to zoom."
);
renderer.domElement.tabIndex = 0;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xa6d9ff, 0x101820, 1.6);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(5, 8, 7);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4ea8ff, 1.8);
rimLight.position.set(-8, 3, -5);
scene.add(rimLight);
// Low-poly ground platform.
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(3.4, 3.8, 0.34, 12),
new THREE.MeshStandardMaterial({
color: 0x132431,
roughness: 0.92,
metalness: 0.04,
flatShading: true
})
);
platform.position.y = -1.42;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.RingGeometry(3.45, 3.62, 12),
new THREE.MeshBasicMaterial({
color: 0x5bbed4,
transparent: true,
opacity: 0.23,
side: THREE.DoubleSide
})
);
platformRing.rotation.x = -Math.PI / 2;
platformRing.position.y = -1.235;
scene.add(platformRing);
// Triangular/rectilinear floor guide.
const gridPositions = [];
for (let i = -14; i <= 14; i += 1) {
gridPositions.push(-14, -1.23, i, 14, -1.23, i);
gridPositions.push(i, -1.23, -14, i, -1.23, 14);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x456174,
transparent: true,
opacity: 0.17
})
);
scene.add(grid);
// Source assembly.
const sourceGroup = new THREE.Group();
scene.add(sourceGroup);
const sourceMaterial = new THREE.MeshStandardMaterial({
color: 0xff9a55,
emissive: 0xff6f2c,
emissiveIntensity: 0.7,
roughness: 0.38,
metalness: 0.06,
flatShading: true
});
const sourceCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.52, 1),
sourceMaterial
);
sourceGroup.add(sourceCore);
const sourceCage = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.72, 1),
new THREE.MeshBasicMaterial({
color: 0xffa45b,
wireframe: true,
transparent: true,
opacity: 0.55
})
);
sourceGroup.add(sourceCage);
const sourceLight = new THREE.PointLight(0xff8b47, 70, 18, 2);
sourceGroup.add(sourceLight);
// Detector assembly.
const detectorGroup = new THREE.Group();
scene.add(detectorGroup);
const detectorMaterial = new THREE.MeshStandardMaterial({
color: 0x8cecff,
emissive: 0x35c9f2,
emissiveIntensity: 0.65,
roughness: 0.38,
metalness: 0.08,
flatShading: true
});
const detector = new THREE.Mesh(
new THREE.OctahedronGeometry(0.44, 0),
detectorMaterial
);
detectorGroup.add(detector);
const detectorRing = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.035, 4, 18),
new THREE.MeshBasicMaterial({
color: 0x62e4ff,
transparent: true,
opacity: 0.62
})
);
detectorRing.rotation.y = Math.PI / 2;
detectorGroup.add(detectorRing);
// Iso-intensity shell through the detector.
const shellMaterial = new THREE.MeshBasicMaterial({
color: 0x62e4ff,
wireframe: true,
transparent: true,
opacity: 0.16,
depthWrite: false
});
const isoShell = new THREE.Mesh(
new THREE.IcosahedronGeometry(1, 1),
shellMaterial
);
scene.add(isoShell);
// Source-to-detector measurement line.
const measurementGeometry = new THREE.BufferGeometry();
measurementGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const measurementLine = new THREE.Line(
measurementGeometry,
new THREE.LineDashedMaterial({
color: 0x7cecff,
dashSize: 0.22,
gapSize: 0.13,
transparent: true,
opacity: 0.85
})
);
scene.add(measurementLine);
// Distance tick marks.
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(12 * 6), 3)
);
const distanceTicks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0x8bdff0,
transparent: true,
opacity: 0.52
})
);
scene.add(distanceTicks);
// Fibonacci-sphere directions give a reasonably even isotropic field.
const directions = [];
const directionCount = 32;
const goldenAngle = Math.PI * (3 - Math.sqrt(5));
for (let i = 0; i < directionCount; i++) {
const y = 1 - (2 * (i + 0.5)) / directionCount;
const radius = Math.sqrt(Math.max(0, 1 - y * y));
const theta = goldenAngle * i;
directions.push(
new THREE.Vector3(
Math.cos(theta) * radius,
y,
Math.sin(theta) * radius
).normalize()
);
}
// Static low-poly ray cage.
const rayPositions = [];
for (const direction of directions) {
const inner = direction.clone().multiplyScalar(0.84);
const outer = direction.clone().multiplyScalar(14.5);
rayPositions.push(inner.x, inner.y, inner.z, outer.x, outer.y, outer.z);
}
const rayGeometry = new THREE.BufferGeometry();
rayGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(rayPositions, 3)
);
const rayMaterial = new THREE.LineBasicMaterial({
color: 0x62e4ff,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const rayCage = new THREE.LineSegments(rayGeometry, rayMaterial);
scene.add(rayCage);
// Animated faceted direction markers.
const arrowGeometry = new THREE.ConeGeometry(0.075, 0.34, 4);
const arrowMaterial = new THREE.MeshStandardMaterial({
color: 0x62e4ff,
emissive: 0x2e9dbb,
emissiveIntensity: 0.8,
roughness: 0.6,
metalness: 0.05,
flatShading: true
});
const arrowMesh = new THREE.InstancedMesh(
arrowGeometry,
arrowMaterial,
directions.length * 2
);
arrowMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
arrowMesh.frustumCulled = false;
scene.add(arrowMesh);
const arrowDummy = new THREE.Object3D();
const arrowQuaternions = directions.map((direction) =>
new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction
)
);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, reset
// -------------------------------------------------------------------------
const cameraGoal = {
theta: 0.86,
phi: 1.08,
radius: 14,
target: new THREE.Vector3(2.3, 0, 0)
};
const cameraCurrent = {
theta: cameraGoal.theta,
phi: cameraGoal.phi,
radius: cameraGoal.radius,
target: cameraGoal.target.clone()
};
let cameraTouched = false;
let dragging = false;
let dragX = 0;
let dragY = 0;
function clamp(value, minimum, maximum) {
return Math.min(maximum, Math.max(minimum, value));
}
function fitCameraToScene() {
cameraGoal.radius = clamp(8 + state.distance * 1.35, 9, 35);
cameraGoal.target.set(Math.min(state.distance * 0.38, 7.5), 0, 0);
}
function resetCamera() {
cameraTouched = false;
cameraGoal.theta = 0.86;
cameraGoal.phi = 1.08;
fitCameraToScene();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
cameraTouched = true;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - dragX;
const deltaY = event.clientY - dragY;
cameraGoal.theta -= deltaX * 0.006;
cameraGoal.phi = clamp(
cameraGoal.phi - deltaY * 0.005,
0.25,
Math.PI - 0.25
);
dragX = event.clientX;
dragY = event.clientY;
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && 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();
cameraTouched = true;
const scale = Math.exp(event.deltaY * 0.001);
cameraGoal.radius = clamp(cameraGoal.radius * scale, 5, 60);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
cameraTouched = true;
switch (event.key) {
case "ArrowLeft":
cameraGoal.theta += 0.09;
break;
case "ArrowRight":
cameraGoal.theta -= 0.09;
break;
case "ArrowUp":
cameraGoal.phi = clamp(cameraGoal.phi - 0.07, 0.25, Math.PI - 0.25);
break;
case "ArrowDown":
cameraGoal.phi = clamp(cameraGoal.phi + 0.07, 0.25, Math.PI - 0.25);
break;
case "+":
case "=":
cameraGoal.radius = clamp(cameraGoal.radius * 0.9, 5, 60);
break;
case "-":
cameraGoal.radius = clamp(cameraGoal.radius * 1.1, 5, 60);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) event.preventDefault();
});
$("#resetView").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Scene state and visual encoding
// -------------------------------------------------------------------------
const coolColor = new THREE.Color(0x4d8cff);
const warmColor = new THREE.Color(0xff9b4b);
const hotColor = new THREE.Color(0xff5368);
const zeroColor = new THREE.Color(0x315064);
function colorForIntensity(value) {
if (value === 0) return zeroColor.clone();
if (!Number.isFinite(value)) return hotColor.clone();
const logarithmic = Math.log10(Math.max(value, 1e-9));
const normalized = clamp((logarithmic + 6) / 8, 0, 1);
if (normalized < 0.72) {
return coolColor.clone().lerp(warmColor, normalized / 0.72);
}
return warmColor.clone().lerp(
hotColor,
(normalized - 0.72) / 0.28
);
}
function updateSceneState() {
const intensity = intensityAt();
const color = colorForIntensity(intensity);
const distance = state.distance;
detectorGroup.position.x = distance;
detectorGroup.visible = distance > 0;
isoShell.visible = state.showShell && distance > 0;
isoShell.scale.setScalar(distance);
shellMaterial.color.copy(color);
shellMaterial.opacity =
state.power === 0 ? 0.07 : 0.1 + clamp(Math.log10(intensity + 1) / 20, 0, 0.15);
sourceMaterial.color.copy(color);
sourceMaterial.emissive.copy(color);
sourceMaterial.emissiveIntensity =
state.power === 0
? 0.08
: 0.45 + clamp(Math.log10(intensity + 1) / 5, 0, 1.5);
sourceCage.material.color.copy(color);
sourceLight.color.copy(color);
sourceLight.intensity =
state.power === 0
? 0
: clamp(18 + Math.log10(intensity + 1) * 13, 18, 160);
arrowMaterial.color.copy(color);
arrowMaterial.emissive.copy(color);
arrowMaterial.emissiveIntensity =
state.power === 0 ? 0.08 : 0.45 + clamp(Math.log10(intensity + 1) / 8, 0, 1);
rayMaterial.color.copy(color);
rayMaterial.opacity =
state.power === 0 ? 0.025 : 0.07 + clamp(Math.log10(intensity + 1) / 25, 0, 0.17);
rayCage.visible = state.showRays;
arrowMesh.visible = state.showRays;
const measurementPositions =
measurementGeometry.attributes.position.array;
measurementPositions[0] = 0;
measurementPositions[1] = 0;
measurementPositions[2] = 0;
measurementPositions[3] = distance;
measurementPositions[4] = 0;
measurementPositions[5] = 0;
measurementGeometry.attributes.position.needsUpdate = true;
measurementLine.computeLineDistances();
measurementLine.visible = distance > 0;
const tickPositions = distanceTicks.geometry.attributes.position.array;
const tickCount = 12;
for (let i = 0; i < tickCount; i++) {
const fraction = i / (tickCount - 1);
const x = distance * fraction;
const halfHeight = i % 3 === 0 ? 0.18 : 0.09;
const offset = i * 6;
tickPositions[offset] = x;
tickPositions[offset + 1] = -halfHeight;
tickPositions[offset + 2] = 0;
tickPositions[offset + 3] = x;
tickPositions[offset + 4] = halfHeight;
tickPositions[offset + 5] = 0;
}
distanceTicks.geometry.attributes.position.needsUpdate = true;
distanceTicks.visible = distance > 0;
sourceLabel.textContent = `SOURCE · ${formatPower(state.power)}`;
detectorLabel.textContent = `DETECTOR · ${formatDistance(distance)}`;
shellLegendText.textContent = distance > 0
? `Constant-intensity shell at r = ${distance.toFixed(2)} m`
: "Iso-intensity shell collapses at the source";
if (!cameraTouched) fitCameraToScene();
}
function updateArrowInstances(time) {
if (!state.showRays) return;
const intensity = intensityAt();
const intensityScale =
state.power === 0
? 0.6
: 0.8 + clamp(Math.log10(intensity + 1) * 0.08, 0, 0.55);
let instance = 0;
for (let directionIndex = 0; directionIndex < directions.length; directionIndex++) {
const direction = directions[directionIndex];
for (let lane = 0; lane < 2; lane++) {
const phase = prefersReducedMotion
? 0.35 + lane * 0.42
: (time * 0.085 + lane * 0.5 + directionIndex / directions.length) % 1;
const radius = 1.05 + phase * 12.2;
const scale =
intensityScale *
(0.62 + Math.sin(Math.PI * phase) * 0.62);
arrowDummy.position.copy(direction).multiplyScalar(radius);
arrowDummy.quaternion.copy(arrowQuaternions[directionIndex]);
arrowDummy.scale.setScalar(scale);
arrowDummy.updateMatrix();
arrowMesh.setMatrixAt(instance, arrowDummy.matrix);
instance++;
}
}
arrowMesh.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Interface updates
// -------------------------------------------------------------------------
function updateInterface() {
const intensity = intensityAt();
const parts = intensityParts(intensity);
const singular = state.distance === 0 && state.power > 0;
const zeroPowerAtOrigin = state.distance === 0 && state.power === 0;
powerOut.textContent = formatPower(state.power);
distanceOut.textContent = formatDistance(state.distance);
powerInput.value = state.power;
distanceInput.value = state.distance;
updateRangeFill(powerInput);
updateRangeFill(distanceInput);
intensityValue.textContent = parts.value;
intensityUnit.textContent = parts.unit;
if (singular) {
intensitySI.textContent = "I(r → 0⁺) → ∞ for nonzero point-source power";
} else if (zeroPowerAtOrigin) {
intensitySI.textContent = "I = 0 for r > 0; the exact origin gives 0/0";
} else {
intensitySI.textContent = `I = ${scientific(intensity)} W/m²`;
}
metricPower.textContent = formatPower(state.power);
metricDistance.textContent = formatDistance(state.distance);
metricArea.textContent = formatArea(
4 * Math.PI * state.distance * state.distance
);
resultCard.classList.toggle("singular", singular);
statusPill.classList.toggle("singular", singular);
statusPill.classList.toggle("zero", zeroPowerAtOrigin);
if (singular) {
statusPill.textContent = "SINGULARITY";
} else if (zeroPowerAtOrigin) {
statusPill.textContent = "NO EMISSION";
} else if (state.power === 0) {
statusPill.textContent = "ZERO EMISSION";
} else {
statusPill.textContent = "FINITE FIELD";
}
singularityAlert.classList.toggle(
"visible",
singular || zeroPowerAtOrigin
);
if (singular) {
singularityCopy.textContent =
"At exactly r = 0 m, the ideal point-source expression contains division by zero. " +
"For P > 0, the predicted intensity diverges as r approaches zero. " +
"A real source has finite dimensions and a finite near-field limit.";
} else {
singularityCopy.textContent =
"With P = 0, no radiation is emitted. The formula is 0/0 at exactly r = 0, " +
"but the field is identically zero at every distance r > 0.";
}
stageWarning.classList.toggle(
"visible",
singular || zeroPowerAtOrigin
);
if (singular) {
warningTitle.textContent = "ZERO-RADIUS SINGULARITY";
warningCopy.textContent =
"The detector is at the source center. For nonzero point-source power, " +
"I = P/(4πr²) diverges as r → 0. No finite intensity exists in this ideal model.";
} else {
warningTitle.textContent = "ZERO-RADIUS EDGE CASE";
warningCopy.textContent =
"At exactly r = 0, the expression is 0/0 because the source radiates no power. " +
"At every r > 0, the intensity is exactly zero.";
}
document.querySelectorAll("[data-power]").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.power) === state.power
);
});
document.querySelectorAll("[data-distance]").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.distance) === state.distance
);
});
updateSceneState();
renderCharts();
}
// -------------------------------------------------------------------------
// Canvas 2D charts
// -------------------------------------------------------------------------
const chartColors = {
text: "#9db1be",
faint: "#536a79",
grid: "rgba(145, 177, 197, 0.12)",
axis: "rgba(160, 196, 220, 0.3)",
cyan: "#62e4ff",
orange: "#ff9a55",
red: "#ff6474",
surface: "rgba(255, 255, 255, 0.012)"
};
function prepareChart(canvas) {
const rect = canvas.getBoundingClientRect();
const width = Math.max(100, rect.width);
const height = Math.max(100, rect.height);
const pixelRatio = Math.min(window.devicePixelRatio || 1, 2);
const targetWidth = Math.round(width * pixelRatio);
const targetHeight = Math.round(height * pixelRatio);
if (canvas.width !== targetWidth || canvas.height !== targetHeight) {
canvas.width = targetWidth;
canvas.height = targetHeight;
}
const context = canvas.getContext("2d");
context.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
context.clearRect(0, 0, width, height);
return { context, width, height };
}
function drawDistanceChart() {
const { context: ctx, width, height } = prepareChart(distanceChart);
const padding = { left: 58, right: 18, top: 25, bottom: 40 };
const plotWidth = width - padding.left - padding.right;
const plotHeight = height - padding.top - padding.bottom;
if (plotWidth <= 0 || plotHeight <= 0) return;
const maxDistance = 20;
const power = state.power;
const intensityNear = power / (4 * Math.PI * 0.01);
const intensityFar = power / (4 * Math.PI * 400);
let yMinimum = power > 0 ? Math.max(intensityFar / 2, 1e-8) : 0.1;
let yMaximum = power > 0 ? Math.max(intensityNear * 1.5, 1) : 1;
const logMin = Math.log10(yMinimum);
const logMax = Math.log10(yMaximum);
const xPosition = (distance) =>
padding.left + (distance / maxDistance) * plotWidth;
const yPosition = (value) => {
if (value <= 0) return padding.top + plotHeight;
const logarithmic = Math.log10(Math.max(value, yMinimum));
const fraction =
(logarithmic - logMin) / Math.max(logMax - logMin, 1e-9);
return padding.top + plotHeight - fraction * plotHeight;
};
ctx.fillStyle = chartColors.surface;
ctx.fillRect(
padding.left,
padding.top,
plotWidth,
plotHeight
);
// Horizontal log-scale grid.
const firstExponent = Math.floor(logMin);
const lastExponent = Math.ceil(logMax);
const exponentStep = Math.max(1, Math.ceil((lastExponent - firstExponent) / 6));
ctx.font = "9px system-ui";
ctx.textBaseline = "middle";
for (
let exponent = firstExponent;
exponent <= lastExponent;
exponent += exponentStep
) {
const value = 10 ** exponent;
if (value < yMinimum || value > yMaximum) continue;
const y = yPosition(value);
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(padding.left + plotWidth, y);
ctx.strokeStyle = chartColors.grid;
ctx.lineWidth = 1;
ctx.stroke();
ctx.fillStyle = chartColors.faint;
ctx.textAlign = "right";
ctx.fillText(axisIntensity(value), padding.left - 8, y);
}
// Distance ticks.
ctx.textAlign = "center";
ctx.textBaseline = "top";
for (let distance = 0; distance <= maxDistance; distance += 2) {
const x = xPosition(distance);
ctx.beginPath();
ctx.moveTo(x, padding.top);
ctx.lineTo(x, padding.top + plotHeight);
ctx.strokeStyle = chartColors.grid;
ctx.stroke();
ctx.fillStyle = chartColors.faint;
ctx.fillText(
String(distance),
x,
padding.top + plotHeight + 8
);
}
// Axes.
ctx.beginPath();
ctx.moveTo(padding.left, padding.top);
ctx.lineTo(padding.left, padding.top + plotHeight);
ctx.lineTo(padding.left + plotWidth, padding.top + plotHeight);
ctx.strokeStyle = chartColors.axis;
ctx.stroke();
// Inverse-square curve.
if (power > 0) {
ctx.beginPath();
for (let index = 0; index <= 240; index++) {
const distance = 0.025 + (maxDistance - 0.025) * (index / 240);
const intensity = power / (4 * Math.PI * distance * distance);
const x = xPosition(distance);
const y = yPosition(intensity);
if (index === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.strokeStyle = chartColors.orange;
ctx.lineWidth = 2;
ctx.stroke();
// Current measurement.
if (state.distance > 0) {
const currentIntensity = intensityAt();
const x = xPosition(state.distance);
const y = yPosition(currentIntensity);
ctx.beginPath();
ctx.arc(x, y, 4.5, 0, Math.PI * 2);
ctx.fillStyle = chartColors.cyan;
ctx.fill();
ctx.beginPath();
ctx.arc(x, y, 8, 0, Math.PI * 2);
ctx.strokeStyle = "rgba(98, 228, 255, 0.3)";
ctx.stroke();
} else {
// Asymptote at r = 0.
ctx.setLineDash([4, 4]);
ctx.beginPath();
ctx.moveTo(padding.left, padding.top);
ctx.lineTo(padding.left, padding.top + plotHeight);
ctx.strokeStyle = "rgba(255, 100, 116, 0.8)";
ctx.lineWidth = 1.5;
ctx.stroke();
ctx.setLineDash([]);
ctx.beginPath();
ctx.arc(padding.left, padding.top, 4, 0, Math.PI * 2);
ctx.fillStyle = chartColors.red;
ctx.fill();
ctx.fillStyle = chartColors.red;
ctx.font = "bold 10px system-ui";
ctx.textAlign = "left";
ctx.textBaseline = "top";
ctx.fillText("r = 0: ∞", padding.left + 8, padding.top + 5);
}
} else {
ctx.beginPath();
ctx.moveTo(padding.left, padding.top + plotHeight);
ctx.lineTo(padding.left + plotWidth, padding.top + plotHeight);
ctx.strokeStyle = chartColors.cyan;
ctx.lineWidth = 2;
ctx.stroke();
}
// Axis titles.
ctx.fillStyle = chartColors.text;
ctx.font = "9px system-ui";
ctx.textAlign = "right";
ctx.textBaseline = "bottom";
ctx.fillText(
"Distance r (m)",
padding.left + plotWidth,
height - 4
);
ctx.save();
ctx.translate(11, padding.top + plotHeight / 2);
ctx.rotate(-Math.PI / 2);
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.fillText("Intensity (W/m²)", 0, 0);
ctx.restore();
// Highlight annotation.
if (state.distance > 0 && power > 0) {
const currentIntensity = intensityAt();
const x = xPosition(state.distance);
const y = yPosition(currentIntensity);
const label = `${state.distance.toFixed(2)} m`;
const textWidth = ctx.measureText(label).width;
const labelX = clamp(x - textWidth / 2 - 5, padding.left + 2, width - textWidth - 12);
const labelY = clamp(y - 24, padding.top + 2, height - 25);
ctx.fillStyle = "rgba(7, 16, 24, 0.9)";
ctx.fillRect(labelX, labelY, textWidth + 10, 17);
ctx.fillStyle = chartColors.cyan;
ctx.font = "9px system-ui";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText(label, labelX + 5, labelY + 8.5);
}
}
function drawPowerChart() {
const { context: ctx, width, height } = prepareChart(powerChart);
const padding = { left: 58, right: 18, top: 25, bottom: 40 };
const plotWidth = width - padding.left - padding.right;
const plotHeight = height - padding.top - padding.bottom;
if (plotWidth <= 0 || plotHeight <= 0) return;
const maxPower = 5000;
const xPosition = (power) =>
padding.left + (power / maxPower) * plotWidth;
ctx.fillStyle = chartColors.surface;
ctx.fillRect(
padding.left,
padding.top,
plotWidth,
plotHeight
);
// The formula is undefined at exactly r = 0.
if (state.distance === 0) {
ctx.strokeStyle = chartColors.axis;
ctx.beginPath();
ctx.moveTo(padding.left, padding.top);
ctx.lineTo(padding.left, padding.top + plotHeight);
ctx.lineTo(padding.left + plotWidth, padding.top + plotHeight);
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = chartColors.red;
ctx.font = "bold 11px system-ui";
ctx.fillText(
"UNDEFINED AT r = 0 m",
padding.left + plotWidth / 2,
padding.top + plotHeight * 0.44
);
ctx.fillStyle = chartColors.text;
ctx.font = "9px system-ui";
ctx.fillText(
state.power > 0
? "For nonzero P, I → ∞ as r → 0"
: "For P = 0, the exact origin is 0/0",
padding.left + plotWidth / 2,
padding.top + plotHeight * 0.44 + 19
);
ctx.fillStyle = chartColors.text;
ctx.font = "9px system-ui";
ctx.textAlign = "right";
ctx.textBaseline = "bottom";
ctx.fillText(
"Source power P (W)",
padding.left + plotWidth,
height - 4
);
ctx.save();
ctx.translate(11, padding.top + plotHeight / 2);
ctx.rotate(-Math.PI / 2);
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.fillText("Intensity (W/m²)", 0, 0);
ctx.restore();
return;
}
const maximumIntensity =
maxPower / (4 * Math.PI * state.distance * state.distance);
const yMaximum = maximumIntensity * 1.12;
const yPosition = (intensity) =>
padding.top + plotHeight - (intensity / yMaximum) * plotHeight;
// Horizontal grid.
ctx.font = "9px system-ui";
ctx.textBaseline = "middle";
for (let index = 0; index <= 4; index++) {
const value = (yMaximum * index) / 4;
const y = yPosition(value);
ctx.beginPath();
ctx.moveTo(padding.left, y);
ctx.lineTo(padding.left + plotWidth, y);
ctx.strokeStyle = chartColors.grid;
ctx.stroke();
ctx.fillStyle = chartColors.faint;
ctx.textAlign = "right";
ctx.fillText(axisIntensity(value), padding.left - 8, y);
}
// Power ticks.
ctx.textAlign = "center";
ctx.textBaseline = "top";
for (let power = 0; power <= maxPower; power += 1000) {
const x = xPosition(power);
ctx.beginPath();
ctx.moveTo(x, padding.top);
ctx.lineTo(x, padding.top + plotHeight);
ctx.strokeStyle = chartColors.grid;
ctx.stroke();
ctx.fillStyle = chartColors.faint;
ctx.fillText(
power === 0 ? "0" : `${power / 1000}k`,
x,
padding.top + plotHeight + 8
);
}
// Axes.
ctx.beginPath();
ctx.moveTo(padding.left, padding.top);
ctx.lineTo(padding.left, padding.top + plotHeight);
ctx.lineTo(padding.left + plotWidth, padding.top + plotHeight);
ctx.strokeStyle = chartColors.axis;
ctx.stroke();
// Linear intensity-power relation.
ctx.beginPath();
ctx.moveTo(xPosition(0), yPosition(0));
ctx.lineTo(xPosition(maxPower), yPosition(maximumIntensity));
ctx.strokeStyle = chartColors.orange;
ctx.lineWidth = 2;
ctx.stroke();
// Current measurement.
const currentIntensity = intensityAt();
const currentX = xPosition(state.power);
const currentY = yPosition(currentIntensity);
ctx.beginPath();
ctx.arc(currentX, currentY, 4.5, 0, Math.PI * 2);
ctx.fillStyle = chartColors.cyan;
ctx.fill();
ctx.beginPath();
ctx.arc(currentX, currentY, 8, 0, Math.PI * 2);
ctx.strokeStyle = "rgba(98, 228, 255, 0.3)";
ctx.stroke();
// Titles.
ctx.fillStyle = chartColors.text;
ctx.font = "9px system-ui";
ctx.textAlign = "right";
ctx.textBaseline = "bottom";
ctx.fillText(
"Source power P (W)",
padding.left + plotWidth,
height - 4
);
ctx.save();
ctx.translate(11, padding.top + plotHeight / 2);
ctx.rotate(-Math.PI / 2);
ctx.textAlign = "center";
ctx.textBaseline = "top";
ctx.fillText("Intensity (W/m²)", 0, 0);
ctx.restore();
const label = `r = ${state.distance.toFixed(2)} m`;
ctx.fillStyle = chartColors.cyan;
ctx.font = "9px system-ui";
ctx.textAlign = "left";
ctx.textBaseline = "bottom";
ctx.fillText(
label,
clamp(currentX + 8, padding.left, width - 70),
clamp(currentY - 8, padding.top + 12, height - 24)
);
}
function renderCharts() {
drawDistanceChart();
drawPowerChart();
}
// -------------------------------------------------------------------------
// Events
// -------------------------------------------------------------------------
powerInput.addEventListener("input", () => {
state.power = Number(powerInput.value);
updateInterface();
});
distanceInput.addEventListener("input", () => {
state.distance = Number(distanceInput.value);
updateInterface();
});
document.querySelectorAll("[data-power]").forEach((button) => {
button.addEventListener("click", () => {
state.power = Number(button.dataset.power);
updateInterface();
});
});
document.querySelectorAll("[data-distance]").forEach((button) => {
button.addEventListener("click", () => {
state.distance = Number(button.dataset.distance);
updateInterface();
});
});
$("#shellToggle").addEventListener("change", (event) => {
state.showShell = event.target.checked;
updateSceneState();
});
$("#raysToggle").addEventListener("change", (event) => {
state.showRays = event.target.checked;
updateSceneState();
});
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resizeThreeScene() {
const width = Math.max(1, sceneHost.clientWidth);
const height = Math.max(1, sceneHost.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const sceneResizeObserver = new ResizeObserver(resizeThreeScene);
sceneResizeObserver.observe(sceneHost);
const chartResizeObserver = new ResizeObserver(() => renderCharts());
chartResizeObserver.observe(distanceChart.parentElement);
chartResizeObserver.observe(powerChart.parentElement);
const projectedPosition = new THREE.Vector3();
function placeSceneLabel(element, worldPosition) {
projectedPosition.copy(worldPosition).project(camera);
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
const x = (projectedPosition.x * 0.5 + 0.5) * width;
const y = (-projectedPosition.y * 0.5 + 0.5) * height;
const visible =
projectedPosition.z > -1 &&
projectedPosition.z < 1 &&
x > -40 &&
x < width + 40 &&
y > -30 &&
y < height + 30;
element.style.display = visible ? "block" : "none";
element.style.transform =
`translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
const sourceLabelPosition = new THREE.Vector3();
const detectorLabelPosition = new THREE.Vector3();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
const damping = 0.09;
cameraCurrent.theta +=
(cameraGoal.theta - cameraCurrent.theta) * damping;
cameraCurrent.phi +=
(cameraGoal.phi - cameraCurrent.phi) * damping;
cameraCurrent.radius +=
(cameraGoal.radius - cameraCurrent.radius) * damping;
cameraCurrent.target.lerp(cameraGoal.target, damping);
const spherical = new THREE.Spherical(
cameraCurrent.radius,
cameraCurrent.phi,
cameraCurrent.theta
);
camera.position.setFromSpherical(spherical).add(cameraCurrent.target);
camera.lookAt(cameraCurrent.target);
const pulse = prefersReducedMotion
? 1
: 1 + Math.sin(elapsed * 2.1) * 0.035;
sourceCore.scale.setScalar(pulse);
sourceCage.rotation.y = elapsed * 0.16;
sourceCage.rotation.x = elapsed * 0.08;
detector.rotation.x = elapsed * 0.35;
detector.rotation.y = elapsed * 0.48;
updateArrowInstances(elapsed);
sourceLabelPosition.set(0, 1.0, 0);
detectorLabelPosition.set(state.distance, 1.0, 0);
placeSceneLabel(sourceLabel, sourceLabelPosition);
placeSceneLabel(detectorLabel, detectorLabelPosition);
renderer.render(scene, camera);
}
resizeThreeScene();
updateInterface();
resetCamera();
animate();
</script>
</body>
</html>
```