# Rotor Spectral Studio

Rotor Spectral Studio combines the Fourier-rotor matrix core with calibrated spectral light, coherent phase interference, a standard-observer projection, a direct-light 3D optics scene, an interactive 2D Maxwell diffraction lab, and a computed 3D Maxwell result.

## Launch the studio

Open `Rotor_Spectral_Studio.html` in any current desktop browser. It is a single, offline file: the official 471-sample CIE table, interface, renderer, and simulation logic are embedded. The studio starts in **Real-world optics** mode.

This mode shows a sphere and a block on a table. Move or orbit the point light to watch the shadows change, drag to move the camera, edit the wave spectrum to alter each material's colour, and save a high-resolution PNG. The image is formed from camera rays, solid-object intersections, direct point illumination, inverse-square falloff, Lambertian diffuse reflection, wavelength-dependent material curves, occlusion tests, and the calibrated CIE observer.

Switch to **Diffraction lab** to watch waves pass through zero, one, or two conducting slits. Adjust physical wavelength, slit geometry, and TMz/TEz polarization, then inspect the detector fringe pattern. **3D Maxwell result** shows the precomputed full-vector 3D six-field run. See [MAXWELL_VALIDATION.md](MAXWELL_VALIDATION.md) for formulation, validation, and numerical limits.

Light oscillates hundreds of trillions of times per second. A browser cannot display those individual cycles, and neither can an eye. The optics renderer therefore computes **time-averaged intensity analytically** from the coherent equal-wavelength sources, then projects the result to the display. The optical carrier-cycle counter shows the number of cycles in the selected observation window. Playback rate controls the macroscopic motion of the lamp and the illustrative rotor view.

The four projection layers are intentionally separate:

| Layer | What it displays | What it must not be confused with |
|---|---|---|
| Human eye | CIE 1931 2° response plus an adjustable temporal inspection window | An individual person's complete visual system |
| Physical spectrum | Every stored wavelength/power/phase component | A solved Maxwell field |
| Hidden waves | Out-of-observer-band components in explicit false colour | The actual colour of ultraviolet or infrared |
| Compare | Human-eye and physical views of the same state | Two different simulations |
| Real-world optics | Spectral illumination of a sphere, block, floor, and cast shadows | Full wave optics or globally illuminated path tracing |
| Diffraction lab | Live 2D Yee Maxwell solver with time-averaged intensity | A solved 3D photorealistic scene |
| 3D Maxwell result | Precomputed vector diffraction and detector | A live 3D browser simulation |

Try the **Broadband**, **Visible trio**, **UV + IR**, and **Phase cancel** presets. Wavelength, power, phase, coherence, light position, layer spacing, exposure, and observer time window can all be changed live. Drag the main viewport to orbit and use the wheel to zoom. The rotor field now defaults to larger strands and faster macroscopic animation, with a wider speed and radius range.

## Calibrated spectral core

`rotorlab/spectral.py` provides:

- exact vacuum wavelength/frequency conversion using `c = 299,792,458 m/s`;
- the official 1 nm CIE 1931 2° colour-matching table from 360–830 nm;
- spectral-power integration into CIE XYZ;
- an explicit, lossy XYZ → D65 sRGB display projection;
- visible/hidden band energy accounting;
- coherent complex-field addition and incoherent intensity addition;
- a one-dimensional scalar electric-field sampler.

The physical spectrum is never overwritten by its RGB preview. This is essential: metameric spectra can look alike, and displays cannot emit UV, infrared, or every visible chromaticity.

## Matrix rotor core

The original numerical engine measures how many conjugate two-dimensional Fourier modes—interpreted as rotating phasors—are required to reconstruct a real matrix to a declared energy threshold.

## Core definition

For a real `m × n` matrix, each frequency `(u,v)` is paired with its conjugate `(-u mod m, -v mod n)`. That pair is counted as one real cosine rotor. DC and Nyquist coordinates are degenerate self-conjugate rotors.

`K_q(M)` is the smallest number of strongest rotor groups retaining fraction `q` of matrix energy. Parseval's identity guarantees that omitted Fourier energy equals squared reconstruction error.

## Run

```bash
python tools/build_studio.py
node tools/check_optics.cjs
node tools/check_maxwell.cjs
python run_maxwell3d.py
python run_spectral_demo.py
python run_benchmarks.py
python -m unittest discover -s tests -v
```

Analyze your own matrix:

```bash
python -m rotorlab analyze matrix.csv --energy 0.99 --json analysis.json --reconstruction reconstructed.csv
```

Supported inputs: `.npy`, `.csv`, `.txt`, and `.tsv`.

## Outputs

- `Rotor_Spectral_Studio.html`: standalone interactive application.
- `web/optics.js`: testable spectral direct-light ray tracer.
- `web/maxwell.js`: live two-polarization 2D Maxwell FDTD solver.
- `rotorlab/maxwell3d.py`: reproducible 3D six-field vector Maxwell solver.
- `run_maxwell3d.py`: regenerate the 3D plot and numerical volume before rebuilding HTML.
- `tools/check_optics.cjs`: geometry, shadow, spectral-material, and phase tests.
- `results/figures/optics_preview.png`: rendered demonstration frame.
- `SPECTRAL_VALIDATION.md`: scientific scope and verification record.
- `data/CIE_xyz_1931_2deg.csv`: official standard-observer source table.
- `results/spectral_example.json`: reproducible spectral projection metrics.
- `results/figures/spectral_validation.png`: physical/perceptual/interference diagnostic.
- `THEORY_AND_RESULTS.md`: interpretation, evidence, and limitations.
- `results/benchmark_results.json`: full measurements and dominant modes.
- `results/benchmark_summary.csv`: compact matrix-level results.
- `results/random_trials.csv`: all random and pseudorandom trials.
- `results/random_summary.csv`: aggregated trial statistics.
- `results/figures/`: compression, representation comparison, and reconstruction plots.

## Scientific guardrail

Rotor count measures complexity in the periodic Fourier dictionary. It is not a basis-independent measure of structure, a proof of randomness, or an estimate of the shortest generating program. The included impulse, rank-one, and LCG controls explicitly test and demonstrate those limitations.

Likewise, the viewer is not claiming that a helix literally is an electromagnetic wave. The animated rotor is an inspectable representation of amplitude, phase, frequency, and layer coupling. The new Maxwell modes compute vacuum wave propagation and conducting aperture diffraction, with finite grid resolution and a lossy sponge boundary; measured materials and convergence studies remain necessary for quantitatively predictive scene simulation.
