# Luminous Intensity Distribution Tool

Interactive tool for visualizing LED illuminance distributions on a 2D target panel. Helps engineers design uniform lighting arrays by simulating Lambertian (cos) emitters in a grid, adjustable height, spacing, panel dimensions, and reflective side panels.

## What it does

1. **Polar plot** — shows the single-emitter radiation pattern (cos theta Lambertian)
2. **Top-down heatmap** — 2D view looking down at the target panel, showing illuminance as a white-to-green color gradient with LED positions and reflector outlines
3. **Cross-section chart** — line plot of illuminance along y=0 through the center of the panel
4. **Reflective panels** — optional rectangular reflector enclosure around the LED array with configurable reflectivity
5. **Power & energy calculator** — computes total power, efficiency (% of emitted light hitting the target), energy density (J/cm²), and time-to-target calculations
6. **Interactive hover** — hover the heatmap or cross-section for exact position and intensity values

## Parameters

| Parameter | Description | Default |
|-----------|-------------|---------|
| **h** | Height of the target panel above the LED array (mm) | 100 |
| **d** | Spacing between adjacent LEDs in both x and y (mm) | 30 |
| **cols** | Number of LED columns | 12 |
| **rows** | Number of LED rows | 14 |
| **l** | Target panel length in x (mm) | 300 |
| **w** | Target panel width in y (mm) | 340 |
| **R** | Reflector panel reflectivity (0-100%) | 88% (Aluminum) |
| **Power/LED** | Optical power per LED (mW) | 500 |

Each parameter has a direct-entry number field (type any value), a slider, and configurable min/max/step.

## Reflector presets

| Preset | Reflectivity |
|--------|-------------|
| Perfect mirror | 100% |
| Aluminum foil | 88% |
| White cardboard | 75% |
| Black cardboard | 5% |
| Void (none) | 0% |

Reflectors form a rectangular enclosure around the LED array at x = +/-(cols*d/2) and y = +/-(rows*d/2). They redirect sideways-emitted light back onto the target panel, improving both efficiency and edge uniformity. Light outside the reflectors is attenuated by (1-R).

## Power & energy calculations

- **Total power**: cols x rows x power-per-LED
- **Efficiency**: fraction of total emitted power that lands on the target panel (direct + reflected, properly integrated using Lambertian irradiance model)
- **Target receives**: total power x efficiency
- **Energy density**: (target power / panel area in cm²) x time = J/cm²
- **Time calculator**: enter target J/cm², get time needed (or enter time, get J/cm²)

The irradiance integration accounts for:
- Lambertian cos(theta) emission pattern
- Inverse-square distance falloff
- Angle of incidence on reflector walls
- First-order reflections from all 4 walls
- Proper energy conservation (efficiency capped at 100%)

## How to use

The tool is a single self-contained HTML file served via a local HTTP server:

```bash
cd /home/adom/project
python3 -m http.server 8123 &>/dev/null &
```

Open in a Hydrogen webview:

```bash
PROXY_URL="${VSCODE_PROXY_URI/\{\{port\}\}/8123}luminous-intensity.html"
adom-cli hydrogen webview open-or-refresh \
  --name "Luminous Intensity" \
  --url "$PROXY_URL"
```

URL parameters can preset values: `?h=100&d=30&cols=12&rows=14&l=300&w=340&r=88`

## Physics model

- **Single source**: Lambertian emitter with intensity I(theta) = I0 * cos(theta)
- **Illuminance on plane**: E(x,y) = sum of cos^3(theta_i) / h^2, where theta_i = atan(sqrt((x-xi)^2 + (y-yi)^2) / h)
- **Reflectors**: Mirror sources placed symmetrically across each wall, with gain = reflectivity. Light outside reflectors attenuated by (1-R).
- **Wall irradiance**: cos(theta_source) * cos(theta_wall) / (pi * r^2), properly integrated over wall height and width
- **Color mapping**: Linear interpolation from white (0%) to green #2e7d32 (100%)

## Source file

The tool lives at `/home/adom/project/luminous-intensity.html`.
