Initial commit: Phase Angle Fixer with README, AGENTS.md, and Cursor rules.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Michael-A-SloanandCursor committed 2026-09-03 17:12:25 -04:00
commit 0c8b61b27f
6 files changed
+1140

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
# Phase Angle Fixer — Cursor rules
- This repo is a single-page web app: one file, `index.html` (HTML + CSS + JS). No build step, no package.json.
- Full project summary and where to edit: see `AGENTS.md`.
- Phase angle logic: angles in degrees, normalized to (-180, 180]; ABC = Vb-Va ≈ -120°, Vc-Va ≈ +120°. V-I angle φ = I − V; pf = cos(φ).
- When editing, keep all UI and logic in index.html; do not split into separate JS/CSS files unless the user asks.
+21
View File
@@ -0,0 +1,21 @@
# OS
.DS_Store
Thumbs.db
desktop.ini
# Editor / IDE
.idea/
.vscode/
*.swp
*.swo
*~
# Local / env (if you add later)
.env
.env.local
*.local
# Logs / temp
*.log
tmp/
temp/
+48
View File
@@ -0,0 +1,48 @@
# Phase Angle Fixer — AI / Agent Summary
This file helps AI assistants and tools understand the repo quickly (project “DNA”).
## What this repo is
- **Single-file web app** (`index.html`): HTML + CSS + JavaScript, no build step, no backend.
- **Purpose:** Check and fix three-phase power meter **phase angles** (Va, Ia, Vb, Ib, Vc, Ic). It suggests wiring fixes, phase rotation (ABC vs ACB), CT/PT polarity, meter settings (CT/PT ratio, phase correction), and shows phasor + time-domain plots.
- **Users:** People who commission or troubleshoot power meters and need to verify/correct phase angles and phase sequence.
## Tech stack
- Vanilla JS (no frameworks).
- No package manager; fonts loaded from Google Fonts (DM Sans, JetBrains Mono).
- All logic and UI in one file: `index.html`.
## Key concepts in code
- **Angle convention:** Angles in degrees; normalized to (−180°, 180°] (NASPI-style). Difference = subtract then wrap.
- **Phase sequence:** ABC (positive) = Vb−Va ≈ −120°, Vc−Va ≈ +120°. ACB (negative) = opposite; also “B and C swapped” pattern.
- **V–I angle:** φ = I − V (phasor difference). pf = cos(φ). Used for power factor, polarity (≈ ±180° → reversed CT), and unity-PF meter correction.
- **Meter setup:** Optional CT ratio, PT ratio, nominal voltage, CT type (standard / Rogowski / residual). Multiplier = (CT ratio) × (PT ratio). These are used in fix suggestions when present.
## File roles
| File | Role |
|------------|------|
| `index.html` | Entire app: inputs, analysis, charts (radial + sinusoidal), fix list, ref notes. |
| `README.md` | Human-facing overview, run instructions, references, structure. |
| `AGENTS.md` | This file; for AI/agents. |
| `.gitignore` | Ignore OS/editor/temp files. |
| `LICENSE` | MIT. |
## How to run
Open `index.html` in a browser (file:// or any static server). No install.
## Where to change things
- **UI copy / labels:** In `index.html`, in the `<body>` card sections and in JS strings (e.g. `suggestion`, `msg`).
- **Phase logic:** In `index.html`, inside `analyze()`: `rotationOk`, `near()`, swap detection, voltage balance, CT polarity, unity-PF fixes.
- **Meter setup / multiplier:** `getMeterSetup()` and the block that writes `meterMultiplierWrap` and `rctNote`.
- **Charts:** `drawRadialChart(norm)` and `drawLineChart(norm)`; both use `CHART_ITEMS` and normalized angles.
- **References / links:** In ref notes and formula blocks in `index.html`; also listed in README.
## References the app cites
NASPI TR-006, electronics-tutorials.ws phasors, learnabout-electronics phase/phasors, NJIT ECE 449 Lab 3 (phase sequence), EEP (phase sequence CW/CCW), Electrical Ampere (phase angle). All URLs are in the app and in README.
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Phase Angle Fixer contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+51
View File
@@ -0,0 +1,51 @@
# Phase Angle Fixer
A single-page web app for checking and correcting **voltage and current phase angles** on three-phase power meters. Enter angles for Va, Ia, Vb, Ib, Vc, Ic and get diagnostics, wiring suggestions, meter settings, and phasor/time-domain visuals.
## Features
- **Phase angles (degrees)** — Input Va, Ia, Vb, Ib, Vc, Ic with optional CT/PT ratios and nominal voltage
- **Phase rotation** — Expects ABC (positive sequence): Vb−Va ≈ −120°, Vc−Va ≈ +120°; detects ACB or B/C swap
- **V–I phase angle & power factor** — φ = I − V, pf = cos(φ); labels resistive / inductive / capacitive
- **Unity PF mode** — Toggle “Expect close to unity power factor” for CT polarity (positive/negative) and meter phase correction suggestions
- **Wiring & CT/PT** — Suggestions for physical wiring, CT on wrong phase, S1/S2 polarity, and meter CT/PT ratio
- **Meter setup** — Optional CT ratio, PT ratio, nominal voltage, CT type (standard / Rogowski / residual); computed meter multiplier
- **Angle views** — Phasor diagram (radial) and sinusoidal waveform (time domain)
- **References** — Logic follows NASPI TR-006, electronics-tutorials phasors, NJIT Lab 3 phase sequence, EEP CW/CCW, Electrical Ampere
## How to run
No build step. Open in a browser:
```bash
# From repo root
open index.html
# or
start index.html
```
Or drag `index.html` into a browser, or use a local server (e.g. `npx serve .`).
## Project structure
```
.
├── README.md # This file
├── AGENTS.md # AI / agent-oriented project summary
├── index.html # Single-file app (HTML, CSS, JS)
├── .gitignore
└── LICENSE # MIT
```
## References (embedded in app)
- [NASPI TR-006](https://www.naspi.org/sites/default/files/reference_documents/naspi_2016_tr_006_phase_angle_calculations_final.pdf) — Phase angle calculations
- [Electronics-Tutorials: Phasors](https://www.electronics-tutorials.ws/accircuits/phasors.html)
- [Learnabout-Electronics: Phase and Phasors](https://learnabout-electronics.org/ac_theory/ac_ccts.php)
- [NJIT ECE 449 Lab 3: Phase Sequence](https://ecelabs.njit.edu/ece449/lab3.php)
- [EEP: Phase sequence CW/CCW](https://electrical-engineering-portal.com/proper-phase-sequence-cw-ccw-electric-motors-generators)
- [Electrical Ampere: Phase angle](https://electricalampere.com/phase-angle/)
## License
MIT — see [LICENSE](LICENSE).
+993
View File
@@ -0,0 +1,993 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Phase Angle Fixer — Power Meter</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0f1419;
--surface: #1a2332;
--surface2: #243044;
--text: #e6edf3;
--text-muted: #8b9cb8;
--accent: #3b82f6;
--ok: #22c55e;
--warn: #eab308;
--err: #ef4444;
--radius: 10px;
--shadow: 0 4px 24px rgba(0,0,0,0.35);
}
* { box-sizing: border-box; }
body {
margin: 0;
min-height: 100vh;
font-family: 'DM Sans', system-ui, sans-serif;
background: var(--bg);
color: var(--text);
padding: 2rem;
}
.container {
max-width: 900px;
margin: 0 auto;
}
h1 {
font-size: 1.75rem;
font-weight: 700;
margin-bottom: 0.25rem;
letter-spacing: -0.02em;
}
.subtitle {
color: var(--text-muted);
font-size: 0.95rem;
margin-bottom: 2rem;
}
.card {
background: var(--surface);
border-radius: var(--radius);
padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: var(--shadow);
border: 1px solid rgba(255,255,255,0.06);
}
.card h2 {
font-size: 1rem;
font-weight: 600;
margin: 0 0 1rem 0;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.06em;
}
.inputs-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.phase-group {
background: var(--surface2);
border-radius: 8px;
padding: 1rem;
border: 1px solid rgba(255,255,255,0.05);
}
.phase-group label {
display: block;
font-size: 0.8rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.5rem;
}
.phase-group .row {
display: flex;
gap: 0.75rem;
align-items: center;
}
.phase-group .v-i-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.5rem;
align-items: center;
}
.phase-group .v-i-pair {
display: flex;
gap: 0.35rem;
align-items: center;
}
.phase-group .v-i-pair input { min-width: 0; }
.phase-group input {
width: 100%;
font-family: 'JetBrains Mono', monospace;
font-size: 1rem;
padding: 0.5rem 0.6rem;
background: var(--bg);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 6px;
color: var(--text);
}
.phase-group input:focus {
outline: none;
border-color: var(--accent);
box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}
.phase-group .symbol {
font-family: 'JetBrains Mono', monospace;
font-size: 0.85rem;
color: var(--text-muted);
min-width: 2ch;
}
.results-section { margin-top: 0.5rem; }
.result-item {
display: flex;
align-items: flex-start;
gap: 0.75rem;
padding: 0.75rem 1rem;
border-radius: 8px;
margin-bottom: 0.5rem;
font-size: 0.95rem;
}
.result-item.ok { background: rgba(34,197,94,0.12); border-left: 3px solid var(--ok); }
.result-item.warn { background: rgba(234,179,8,0.12); border-left: 3px solid var(--warn); }
.result-item.err { background: rgba(239,68,68,0.12); border-left: 3px solid var(--err); }
.result-item .icon { font-size: 1.2rem; }
.result-item .label { font-weight: 600; min-width: 8rem; }
.result-item .detail { color: var(--text-muted); }
.fix-list {
list-style: none;
padding: 0;
margin: 0.5rem 0 0 0;
}
.fix-list li {
padding: 0.5rem 0;
border-bottom: 1px solid rgba(255,255,255,0.06);
font-size: 0.9rem;
}
.fix-list li:last-child { border-bottom: none; }
.fix-list .what { font-weight: 600; color: var(--err); }
.fix-list .suggestion { color: var(--text-muted); margin-top: 0.2rem; }
.fix-list .suggestion a { color: var(--accent); }
.angles-table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
.angles-table th, .angles-table td {
text-align: left;
padding: 0.5rem 0.75rem;
border-bottom: 1px solid rgba(255,255,255,0.06);
}
.angles-table th { color: var(--text-muted); font-weight: 600; }
.angles-table .mono { font-family: 'JetBrains Mono', monospace; }
.ref-note {
font-size: 0.85rem;
color: var(--text-muted);
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid rgba(255,255,255,0.06);
}
.ref-note a { color: var(--accent); }
.pf-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}
.pf-phase {
background: var(--surface2);
border-radius: 8px;
padding: 1rem;
border: 1px solid rgba(255,255,255,0.05);
}
.pf-phase .phase-name { font-weight: 600; margin-bottom: 0.5rem; }
.pf-phase .pf-value { font-family: 'JetBrains Mono', monospace; font-size: 1.1rem; }
.pf-phase .pf-type { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.25rem; }
.pf-phase .pf-type.resistive { color: var(--ok); }
.pf-phase .pf-type.inductive { color: #a78bfa; }
.pf-phase .pf-type.capacitive { color: #38bdf8; }
.formula-block {
background: var(--surface2);
border-radius: 8px;
padding: 1rem;
margin-top: 1rem;
font-size: 0.9rem;
border-left: 3px solid var(--accent);
}
.formula-block code { font-family: 'JetBrains Mono', monospace; }
.toggle-row {
display: flex;
align-items: center;
gap: 0.75rem;
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid rgba(255,255,255,0.06);
}
.toggle-row label {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
font-size: 0.9rem;
color: var(--text-muted);
}
.toggle-switch {
position: relative;
width: 2.5rem;
height: 1.25rem;
background: var(--surface2);
border-radius: 999px;
border: 1px solid rgba(255,255,255,0.1);
transition: background 0.2s, border-color 0.2s;
}
.toggle-switch::after {
content: '';
position: absolute;
top: 2px;
left: 2px;
width: calc(1.25rem - 4px);
height: calc(1.25rem - 4px);
background: var(--text-muted);
border-radius: 50%;
transition: transform 0.2s;
}
.toggle-row input:checked + .toggle-switch {
background: rgba(59,130,246,0.3);
border-color: var(--accent);
}
.toggle-row input:checked + .toggle-switch::after {
transform: translateX(1.25rem);
background: var(--accent);
}
.toggle-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.meter-setup-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
.meter-setup-item label {
display: block;
font-size: 0.8rem;
font-weight: 600;
color: var(--text-muted);
margin-bottom: 0.35rem;
}
.meter-setup-inputs {
display: flex;
align-items: center;
gap: 0.35rem;
}
.meter-setup-inputs input {
width: 5rem;
font-family: 'JetBrains Mono', monospace;
font-size: 0.95rem;
padding: 0.45rem 0.5rem;
background: var(--bg);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 6px;
color: var(--text);
}
.meter-setup-sep { color: var(--text-muted); font-weight: 600; }
.meter-setup-single { width: 6rem; font-family: 'JetBrains Mono', monospace; font-size: 0.95rem; padding: 0.45rem 0.5rem; background: var(--bg); border: 1px solid rgba(255,255,255,0.1); border-radius: 6px; color: var(--text); }
.meter-multiplier-wrap {
margin-top: 1rem;
padding-top: 1rem;
border-top: 1px solid rgba(255,255,255,0.06);
font-size: 0.9rem;
color: var(--text-muted);
}
.meter-multiplier-wrap .value { font-family: 'JetBrains Mono', monospace; color: var(--text); font-weight: 500; }
.meter-setup-full { grid-column: 1 / -1; }
.meter-select {
font-family: 'DM Sans', sans-serif;
font-size: 0.95rem;
padding: 0.45rem 0.5rem;
background: var(--bg);
border: 1px solid rgba(255,255,255,0.1);
border-radius: 6px;
color: var(--text);
min-width: 12rem;
}
.rct-note {
grid-column: 1 / -1;
margin-top: 0.5rem;
padding: 0.75rem 1rem;
background: rgba(59,130,246,0.08);
border-left: 3px solid var(--accent);
border-radius: 6px;
font-size: 0.85rem;
color: var(--text-muted);
}
.charts-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1.5rem;
align-items: start;
}
.chart-wrap {
background: var(--surface2);
border-radius: 8px;
padding: 1rem;
border: 1px solid rgba(255,255,255,0.05);
}
.chart-wrap h3 {
font-size: 0.85rem;
font-weight: 600;
color: var(--text-muted);
margin: 0 0 0.75rem 0;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.chart-wrap canvas {
display: block;
width: 100%;
height: auto;
border-radius: 4px;
}
.chart-legend {
display: flex;
flex-wrap: wrap;
gap: 0.5rem 1rem;
margin-top: 0.75rem;
font-size: 0.75rem;
color: var(--text-muted);
}
.chart-legend span {
display: inline-flex;
align-items: center;
gap: 0.35rem;
}
.chart-legend .dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.chart-legend .dot.line-v { border-left: 3px solid; background: transparent; width: 0; height: 0; border-radius: 0; border-color: inherit; }
.chart-legend .dash { width: 10px; height: 0; border-top: 2px dashed; }
@media (max-width: 640px) {
.inputs-grid { grid-template-columns: 1fr; }
.pf-grid { grid-template-columns: 1fr; }
.charts-row { grid-template-columns: 1fr; }
}
</style>
</head>
<body>
<div class="container">
<h1>Phase Angle Fixer</h1>
<p class="subtitle">Enter voltage and current phase angles (degrees) for each phase. Uses ±180° convention per NASPI TR-006.</p>
<div class="card">
<h2>Phase angles (degrees)</h2>
<div class="inputs-grid">
<div class="phase-group">
<label>Phase A</label>
<div class="v-i-row">
<div class="v-i-pair"><span class="symbol">Vₐ</span><input type="number" id="Va" placeholder="0" step="0.1"></div>
<div class="v-i-pair"><span class="symbol">Iₐ</span><input type="number" id="Ia" placeholder="0" step="0.1"></div>
</div>
</div>
<div class="phase-group">
<label>Phase B</label>
<div class="v-i-row">
<div class="v-i-pair"><span class="symbol">Vᵦ</span><input type="number" id="Vb" placeholder="-120" step="0.1"></div>
<div class="v-i-pair"><span class="symbol">Iᵦ</span><input type="number" id="Ib" placeholder="-120" step="0.1"></div>
</div>
</div>
<div class="phase-group">
<label>Phase C</label>
<div class="v-i-row">
<div class="v-i-pair"><span class="symbol">Vc</span><input type="number" id="Vc" placeholder="120" step="0.1"></div>
<div class="v-i-pair"><span class="symbol">Ic</span><input type="number" id="Ic" placeholder="120" step="0.1"></div>
</div>
</div>
</div>
<div class="toggle-row">
<label>
<input type="checkbox" id="unityPf" aria-describedby="unityPfHelp">
<span class="toggle-switch"></span>
Expect close to unity power factor
</label>
</div>
<p id="unityPfHelp" style="margin:0.25rem 0 0 0; font-size:0.85rem; color:var(--text-muted);">When on, suggests positive/negative CT (reversed polarity) when V−I angle is near ±180°.</p>
</div>
<div class="card">
<h2>Meter / transformer setup</h2>
<p style="margin:0 0 1rem 0; font-size:0.9rem; color:var(--text-muted);">Optional. Used for multiplier and to tailor fix suggestions (e.g. “set CT ratio to 100:5”).</p>
<div class="meter-setup-grid">
<div class="meter-setup-item">
<label for="ctPrimary">CT ratio (primary : secondary)</label>
<div class="meter-setup-inputs">
<input type="number" id="ctPrimary" placeholder="100" min="1" step="1">
<span class="meter-setup-sep">:</span>
<input type="number" id="ctSecondary" placeholder="5" min="0.1" step="0.1">
</div>
</div>
<div class="meter-setup-item">
<label for="ptPrimary">PT ratio (primary : secondary)</label>
<div class="meter-setup-inputs">
<input type="number" id="ptPrimary" placeholder="7200" min="1" step="1">
<span class="meter-setup-sep">:</span>
<input type="number" id="ptSecondary" placeholder="120" min="1" step="1">
</div>
</div>
<div class="meter-setup-item">
<label for="nominalVoltage">Nominal voltage (V)</label>
<input type="number" id="nominalVoltage" placeholder="120" min="1" step="1" class="meter-setup-single">
</div>
<div class="meter-setup-item meter-setup-full">
<label for="ctType">CT type</label>
<select id="ctType" class="meter-select">
<option value="standard">Standard (wound/core CT)</option>
<option value="rogowski">Rogowski coil / RCCT</option>
<option value="residual">Residual CT (RCT)</option>
</select>
</div>
<div id="rctNote" class="rct-note" style="display:none;"></div>
</div>
<div id="meterMultiplierWrap" class="meter-multiplier-wrap"></div>
</div>
<div class="card results-section">
<h2>Summary — what needs fixing</h2>
<div id="summary"></div>
<div id="fixList"></div>
</div>
<div class="card">
<h2>V–I phase angle &amp; power factor</h2>
<p style="margin:0 0 1rem 0; font-size:0.9rem; color:var(--text-muted);">Phase angle φ = I − V (phasor difference). Power factor pf = cos(φ). Per <a href="https://www.electronics-tutorials.ws/accircuits/phasors.html" target="_blank" rel="noopener" style="color:var(--accent);">phasor convention</a>: positive φ = current lags voltage (inductive); negative φ = current leads voltage (capacitive). Resistive: φ ≈ 0°.</p>
<div id="pfSection" class="pf-grid"></div>
<div class="formula-block">
<strong>Phase angle &amp; phasors</strong><br>
<a href="https://www.electronics-tutorials.ws/accircuits/phasors.html" target="_blank" rel="noopener" style="color:var(--accent);">Electronics-Tutorials: Phasors</a> — v(t) = Vm cos(ωt + θ) ↔ <code>V∠θ</code>; lead = +θ, lag = −θ; CCW, 0° = real axis.<br>
<a href="https://learnabout-electronics.org/ac_theory/ac_ccts.php" target="_blank" rel="noopener" style="color:var(--accent);">Learnabout-Electronics: Phase and Phasors</a> — phase shift, phasor diagrams and calculations (AC theory).<br>
<a href="https://electricalampere.com/phase-angle/" target="_blank" rel="noopener" style="color:var(--accent);">Electrical Ampere</a> — <code>pf = cos(φ)</code>, φ = cos⁻¹(pf); φ = tan⁻¹(X/R); φ = 360°×(Δt/T).
</div>
</div>
<div class="card">
<h2>Angle views</h2>
<p style="margin:0 0 1rem 0; font-size:0.9rem; color:var(--text-muted);">Per <a href="https://www.electronics-tutorials.ws/accircuits/phasors.html" target="_blank" rel="noopener" style="color:var(--accent);">phasor convention</a>: each quantity is a phasor (magnitude ∠ phase); 0° = right (real axis), CCW = positive angle.</p>
<div class="charts-row">
<div class="chart-wrap">
<h3>Phasor diagram (radial)</h3>
<canvas id="radialChart" width="320" height="320"></canvas>
<div id="radialLegend" class="chart-legend"></div>
</div>
<div class="chart-wrap">
<h3>Sinusoidal waveform (time domain)</h3>
<canvas id="lineChart" width="320" height="240"></canvas>
<div id="lineLegend" class="chart-legend"></div>
</div>
</div>
</div>
<div class="card">
<h2>Normalized angles (±180°) &amp; differences</h2>
<table class="angles-table">
<thead>
<tr>
<th>Phase</th>
<th>V entered</th>
<th>I entered</th>
<th>V norm</th>
<th>I norm</th>
<th>V–I angle (PF)</th>
</tr>
</thead>
<tbody id="anglesBody"></tbody>
</table>
<p class="ref-note"><strong>Angles:</strong> Subtract then wrap to (−180°, 180°] (phasor angle difference; <a href="https://www.electronics-tutorials.ws/accircuits/phasors.html" target="_blank" rel="noopener">phasors</a>, <a href="https://learnabout-electronics.org/ac_theory/ac_ccts.php" target="_blank" rel="noopener">phase &amp; phasors</a>). <strong>Phase sequence:</strong> We expect <strong>ABC (positive sequence)</strong>: Va reference 0°, Vb ≈ −120° (lagging), Vc ≈ +120°; so Vb−Va ≈ −120°, Vc−Va ≈ +120°. <strong>ACB (negative sequence)</strong> gives Vb−Va ≈ +120°, Vc−Va ≈ −120°. CW/CCW can mean motor rotation (<a href="https://ecelabs.njit.edu/ece449/lab3.php" target="_blank" rel="noopener">NJIT Lab 3</a>: abc = CW positive, acb = CCW negative) or phasor diagram (<a href="https://electrical-engineering-portal.com/proper-phase-sequence-cw-ccw-electric-motors-generators" target="_blank" rel="noopener">EEP</a>: ABC = CCW, ACB = CW)—conventions vary. Phase sequence affects motor direction, paralleling transformers, and two-wattmeter method.</p>
<div class="formula-block" style="margin-top:1rem;">
<strong>References</strong><br>
<a href="https://www.electronics-tutorials.ws/accircuits/phasors.html" target="_blank" rel="noopener" style="color:var(--accent);">Electronics-Tutorials: Phasors</a> · <a href="https://learnabout-electronics.org/ac_theory/ac_ccts.php" target="_blank" rel="noopener" style="color:var(--accent);">Learnabout-Electronics: Phase and Phasors</a> · <a href="https://ecelabs.njit.edu/ece449/lab3.php" target="_blank" rel="noopener" style="color:var(--accent);">NJIT ECE 449 Lab 3: Phase Sequence</a> · <a href="https://electrical-engineering-portal.com/proper-phase-sequence-cw-ccw-electric-motors-generators" target="_blank" rel="noopener" style="color:var(--accent);">EEP: Phase sequence CW/CCW</a>
</div>
</div>
</div>
<script>
const ids = ['Va','Ia','Vb','Ib','Vc','Ic'];
// Phasor/angle convention per electronics-tutorials.ws/accircuits/phasors: phasor V∠θ ↔ v(t)=Vm cos(ωt+θ);
// phase lead = +θ, lag = −θ; 0° = real axis, CCW positive. Angles stored in (−180°, 180°] per NASPI.
const CHART_ITEMS = [
{ key: 'Va', label: 'Vₐ', color: '#ef4444' },
{ key: 'Ia', label: 'Iₐ', color: '#f87171' },
{ key: 'Vb', label: 'Vᵦ', color: '#22c55e' },
{ key: 'Ib', label: 'Iᵦ', color: '#4ade80' },
{ key: 'Vc', label: 'Vc', color: '#3b82f6' },
{ key: 'Ic', label: 'Ic', color: '#60a5fa' },
];
// Wrap angle to (-180, 180] per NASPI
function wrap(deg) {
if (deg == null || isNaN(deg)) return NaN;
let d = deg % 360;
if (d > 180) d -= 360;
if (d <= -180) d += 360;
return d;
}
// Angle difference: subtract then wrap (NASPI "Subtract Then Wrap")
function angleDiff(a, b) {
const d = wrap(a) - wrap(b);
return wrap(d);
}
function parseInput(id) {
const v = document.getElementById(id).value.trim();
return v === '' ? NaN : parseFloat(v);
}
function drawRadialChart(norm) {
const canvas = document.getElementById('radialChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const w = canvas.width;
const h = canvas.height;
const cx = w / 2;
const cy = h / 2;
const r = Math.min(w, h) / 2 - 24;
ctx.clearRect(0, 0, w, h);
// Circle and grid (0° = right, angle increases CCW)
ctx.strokeStyle = 'rgba(255,255,255,0.08)';
ctx.lineWidth = 1;
for (let deg = -180; deg <= 180; deg += 30) {
const rad = (deg * Math.PI) / 180;
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.lineTo(cx + r * Math.cos(rad), cy - r * Math.sin(rad));
ctx.stroke();
}
ctx.strokeStyle = 'rgba(255,255,255,0.15)';
ctx.beginPath();
ctx.arc(cx, cy, r, 0, Math.PI * 2);
ctx.stroke();
// Labels 0, 90, 180, -90
ctx.fillStyle = 'rgba(139,156,184,0.9)';
ctx.font = '11px DM Sans, sans-serif';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
[[0, '0°', cx + r + 10, cy], [90, '90°', cx, cy - r - 10], [180, '180°', cx - r - 18, cy], [-90, '-90°', cx, cy + r + 10]].forEach(([_, txt, x, y]) => {
ctx.fillText(txt, x, y);
});
// Phasor rays
CHART_ITEMS.forEach((item) => {
const deg = norm[item.key];
if (deg == null || isNaN(deg)) return;
const rad = (deg * Math.PI) / 180;
const x = cx + r * Math.cos(rad);
const y = cy - r * Math.sin(rad);
ctx.strokeStyle = item.color;
ctx.lineWidth = item.key.startsWith('V') ? 2.5 : 1.5;
ctx.setLineDash(item.key.startsWith('I') ? [4, 3] : []);
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.lineTo(x, y);
ctx.stroke();
ctx.setLineDash([]);
// Dot at end
ctx.fillStyle = item.color;
ctx.beginPath();
ctx.arc(x, y, 3, 0, Math.PI * 2);
ctx.fill();
});
// Legend
document.getElementById('radialLegend').innerHTML = CHART_ITEMS.map(
(item) => `<span style="color:${item.color}"><span class="dot" style="background:${item.color}"></span> ${item.label}</span>`
).join('');
}
function drawLineChart(norm) {
const canvas = document.getElementById('lineChart');
if (!canvas) return;
const ctx = canvas.getContext('2d');
const w = canvas.width;
const h = canvas.height;
const padding = { top: 14, right: 14, bottom: 32, left: 32 };
const chartW = w - padding.left - padding.right;
const chartH = h - padding.top - padding.bottom;
const angleMin = 0;
const angleMax = 360;
const ampMin = -1;
const ampMax = 1;
const xScale = (deg) => padding.left + chartW * (deg / 360);
const yScale = (amp) => padding.top + chartH * (1 - (amp - ampMin) / (ampMax - ampMin));
ctx.clearRect(0, 0, w, h);
// Grid: vertical at 30° steps, horizontal at ±1 and 0
ctx.strokeStyle = 'rgba(255,255,255,0.06)';
ctx.lineWidth = 1;
for (let deg = 0; deg <= 360; deg += 30) {
ctx.beginPath();
ctx.moveTo(xScale(deg), padding.top);
ctx.lineTo(xScale(deg), h - padding.bottom);
ctx.stroke();
}
for (const amp of [-1, 0, 1]) {
ctx.beginPath();
ctx.moveTo(padding.left, yScale(amp));
ctx.lineTo(w - padding.right, yScale(amp));
ctx.stroke();
}
ctx.strokeStyle = 'rgba(255,255,255,0.12)';
ctx.strokeRect(padding.left, padding.top, chartW, chartH);
// Y labels: +A_m, 0, -A_m
ctx.fillStyle = 'rgba(139,156,184,0.9)';
ctx.font = '10px JetBrains Mono, monospace';
ctx.textAlign = 'right';
ctx.textBaseline = 'middle';
ctx.fillText('+A_m', padding.left - 6, yScale(1));
ctx.fillText('0', padding.left - 6, yScale(0));
ctx.fillText('-A_m', padding.left - 6, yScale(-1));
// X labels: angle in degrees (0, 90, 180, 270, 360)
ctx.textAlign = 'center';
ctx.textBaseline = 'top';
[0, 90, 180, 270, 360].forEach((deg) => {
ctx.fillStyle = 'rgba(139,156,184,0.9)';
ctx.fillText(deg + '°', xScale(deg), h - padding.bottom + 6);
});
// Sinusoidal waveforms: A(θ) = sin(θ + φ), φ = phase angle (degrees)
const steps = 360;
CHART_ITEMS.forEach((item) => {
const phi = norm[item.key];
if (phi == null || isNaN(phi)) return;
ctx.strokeStyle = item.color;
ctx.lineWidth = item.key.startsWith('V') ? 2 : 1.5;
ctx.setLineDash(item.key.startsWith('I') ? [5, 4] : []);
ctx.beginPath();
for (let i = 0; i <= steps; i++) {
const thetaDeg = (i / steps) * 360;
const rad = ((thetaDeg + phi) * Math.PI) / 180;
const amp = Math.sin(rad);
const x = xScale(thetaDeg);
const y = yScale(amp);
if (i === 0) ctx.moveTo(x, y);
else ctx.lineTo(x, y);
}
ctx.stroke();
ctx.setLineDash([]);
});
document.getElementById('lineLegend').innerHTML = 'A(θ) = A_m sin(θ + φ) — projection of rotating phasor (equivalent to cos(θ+φ) with 90° ref). One cycle 0°–360°; each curve shifted by its phase angle φ.';
}
function getMeterSetup() {
const ctP = parseFloat(document.getElementById('ctPrimary')?.value) || NaN;
const ctS = parseFloat(document.getElementById('ctSecondary')?.value) || NaN;
const ptP = parseFloat(document.getElementById('ptPrimary')?.value) || NaN;
const ptS = parseFloat(document.getElementById('ptSecondary')?.value) || NaN;
const nominalV = parseFloat(document.getElementById('nominalVoltage')?.value) || NaN;
const ctType = (document.getElementById('ctType')?.value) || 'standard';
const ctOk = ctP > 0 && ctS > 0;
const ptOk = ptP > 0 && ptS > 0;
const ctStr = ctOk ? Math.round(ctP) + ':' + (ctS % 1 === 0 ? Math.round(ctS) : ctS) : null;
const ptStr = ptOk ? Math.round(ptP) + ':' + Math.round(ptS) : null;
const multiplier = (ctOk && ptOk) ? (ctP / ctS) * (ptP / ptS) : NaN;
return { ctStr, ptStr, multiplier, nominalV: isNaN(nominalV) ? null : nominalV, ctType };
}
function analyze() {
const raw = {};
ids.forEach(id => { raw[id] = parseInput(id); });
const norm = {};
ids.forEach(id => { norm[id] = wrap(raw[id]); });
const meter = getMeterSetup();
const mWrap = document.getElementById('meterMultiplierWrap');
if (mWrap) {
const parts = [];
if (meter.ctStr) parts.push('CT ' + meter.ctStr);
if (meter.ptStr) parts.push('PT ' + meter.ptStr);
if (parts.length) {
let line = 'Entered: ' + parts.join(', ');
if (!isNaN(meter.multiplier)) line += '. <span class="value">Meter multiplier = ' + Math.round(meter.multiplier).toLocaleString() + '</span> (for energy/power scaling).';
if (meter.nominalV != null) line += ' Nominal voltage: <span class="value">' + meter.nominalV + ' V</span>.';
mWrap.innerHTML = line;
} else {
mWrap.innerHTML = 'Enter CT and/or PT ratios to see multiplier and use them in fix suggestions.';
}
}
const rctNoteEl = document.getElementById('rctNote');
if (rctNoteEl) {
if (meter.ctType === 'rogowski') {
rctNoteEl.style.display = 'block';
rctNoteEl.innerHTML = '<strong>Rogowski coil / RCCT:</strong> These transducers can have different phase response (e.g. integrator phase shift). Enter the phase angles as reported by the meter <em>after</em> any internal phase compensation. If the meter applies a fixed correction for the Rogowski output, your angles should already reflect that. Phase angle errors here affect power and PF accuracy more at low power factor.';
} else if (meter.ctType === 'residual') {
rctNoteEl.style.display = 'block';
rctNoteEl.innerHTML = '<strong>Residual CT (RCT):</strong> A residual CT measures the vector sum (Iₐ+Iᵦ+Ic), not per-phase currents. This tool assumes <em>per-phase</em> CTs for Va, Ia, Vb, Ib, Vc, Ic. If you are metering with a residual CT only, you have one combined current signal — use this tool for the three voltage phases and the residual current only as a check; phase-angle fixes here apply to per-phase CT setups.';
} else {
rctNoteEl.style.display = 'none';
rctNoteEl.innerHTML = '';
}
}
const viAngle = {
A: angleDiff(raw.Ia, raw.Va),
B: angleDiff(raw.Ib, raw.Vb),
C: angleDiff(raw.Ic, raw.Vc),
};
const vDiffBA = angleDiff(raw.Vb, raw.Va);
const vDiffCA = angleDiff(raw.Vc, raw.Va);
const vDiffCB = angleDiff(raw.Vc, raw.Vb);
const issues = [];
const fixes = [];
const expectUnityPf = document.getElementById('unityPf').checked;
const BALANCE_TOL = 25;
// Phase sequence: ABC (positive) = Vb−Va ≈ −120°, Vc−Va ≈ +120° (per NJIT Lab 3, EEP). ACB (negative) = opposite.
const near = (d, target) => Math.abs(angleDiff(d, target)) < BALANCE_TOL;
const rotationOk = !isNaN(vDiffBA) && !isNaN(vDiffCA) && near(vDiffBA, -120) && near(vDiffCA, 120);
// ACB / negative sequence: Vb−Va ≈ +120°, Vc−Va ≈ −120° (NJIT: acb = CCW negative; EEP: ACB = CW)
if (!isNaN(vDiffBA) && !isNaN(vDiffCA)) {
if (near(vDiffBA, 120) && near(vDiffCA, -120)) {
issues.push({ type: 'swap', msg: 'Vb−Va ≈ +120°, Vc−Va ≈ −120° (ACB / negative sequence or B and C swapped)' });
fixes.push({
what: 'Phase rotation ACB (negative sequence) or B and C swapped',
suggestion: 'Angles match <strong>ACB (negative sequence)</strong>. Per <a href="https://ecelabs.njit.edu/ece449/lab3.php" target="_blank" rel="noopener">NJIT Lab 3</a>, acb = counter-clockwise/negative; per <a href="https://electrical-engineering-portal.com/proper-phase-sequence-cw-ccw-electric-motors-generators" target="_blank" rel="noopener">EEP</a>, ACB = CW. Phase sequence affects motor direction and paralleling. Wiring: (1) If the source is ACB, swap the two PT secondaries (or current inputs) for B and C at the meter to read ABC. (2) Confirm the CT for B is on the B conductor and for C on the C conductor. (3) Re-check angles after any change.'
});
} else if (near(vDiffBA, -120) && near(vDiffCA, -120)) {
issues.push({ type: 'swap', msg: 'Vb and Vc at same angle (both ≈ −120° from Va)' });
fixes.push({
what: 'B and C reading same phase',
suggestion: 'Vb and Vc have the same phase angle — the meter may have B and C wired to the same phase conductor, or one of B/C is miswired. Check that the B and C voltage (and current) inputs are on different phase conductors. Verify phase rotation (ABC vs ACB) at the source.'
});
} else if (near(vDiffBA, 120) && near(vDiffCA, 120)) {
issues.push({ type: 'swap', msg: 'Vb and Vc at same angle (both ≈ +120° from Va)' });
fixes.push({
what: 'B and C reading same phase',
suggestion: 'Vb and Vc have the same phase angle — the meter may have B and C wired to the same phase conductor, or one of B/C is miswired. Check that the B and C voltage (and current) inputs are on different phase conductors. Verify phase rotation (ABC vs ACB) at the source.'
});
}
}
// Expected: Vb - Va ≈ -120°, Vc - Va ≈ +120° (ABC, 120° separation)
if (!isNaN(vDiffBA) && Math.abs(vDiffBA - (-120)) > BALANCE_TOL && Math.abs(vDiffBA - 240) > BALANCE_TOL && !near(vDiffBA, 120)) {
issues.push({ type: 'voltage', phase: 'B', msg: `Vb−Va = ${vDiffBA.toFixed(1)}° (expected ≈ −120° or 240°)` });
fixes.push({
what: 'Phase B voltage angle',
suggestion: `Wiring: (1) Confirm PT for phase B is on the B phase conductor and secondary polarity (S1/S2) is correct. (2) Check that the voltage input labeled B at the meter is not swapped with another phase. If polarity is reversed, swap PT secondary leads or add 180° in meter. Target Vb−Va ≈ −120°.`
});
}
if (!isNaN(vDiffCA) && Math.abs(vDiffCA - 120) > BALANCE_TOL && Math.abs(vDiffCA - (-240)) > BALANCE_TOL && !near(vDiffCA, -120)) {
issues.push({ type: 'voltage', phase: 'C', msg: `Vc−Va = ${vDiffCA.toFixed(1)}° (expected ≈ 120° or −240°)` });
fixes.push({
what: 'Phase C voltage angle',
suggestion: `Wiring: (1) Confirm PT for phase C is on the C phase conductor and secondary polarity (S1/S2) is correct. (2) Check that the voltage input labeled C at the meter is not swapped with another phase. If polarity is reversed, swap PT secondary leads or add 180° in meter. Target Vc−Va ≈ 120°.`
});
}
// CT polarity: V-I angle near ±180° → reversed; when unity PF expected, suggest positive/negative CT
[['A', raw.Va, raw.Ia], ['B', raw.Vb, raw.Ib], ['C', raw.Vc, raw.Ic]].forEach(([ph, v, i]) => {
const vi = viAngle[ph];
if (isNaN(vi)) return;
if (Math.abs(Math.abs(vi) - 180) < 25) {
issues.push({ type: 'polarity', phase: ph, msg: `Phase ${ph} V−I angle = ${vi.toFixed(1)}° (possible CT or polarity reversal)` });
if (expectUnityPf) {
fixes.push({
what: `Phase ${ph} — negative CT (reversed)`,
suggestion: `Wiring: (1) CT may be on the correct phase but secondary reversed — swap S1 and S2 at the meter for phase ${ph}. (2) Or CT may be on the wrong phase conductor (e.g. Phase ${ph} CT on another phase); move CT to the correct conductor. Meter: for unity PF, use positive CT connection, or add 180° to I${ph.toLowerCase()} angle in settings.`
});
} else {
fixes.push({
what: `Phase ${ph} current (I${ph.toLowerCase()}) — CT wiring or polarity`,
suggestion: `Wiring: (1) Swap CT secondary leads (S1/S2) for phase ${ph} at the meter — often fixes ±180° V−I. (2) Confirm the CT labeled "${ph}" is installed on the ${ph} phase conductor; if it is on another phase, move it to the correct phase. Meter: or add/subtract 180° to I${ph.toLowerCase()} angle.`
});
}
} else if (expectUnityPf && Math.abs(vi) > 25) {
const correction = -vi;
const pfVal = Math.cos(vi * Math.PI / 180).toFixed(2);
fixes.push({
what: `Phase ${ph} — meter setting (not unity PF)`,
suggestion: `Wiring first: (1) Confirm the CT for phase ${ph} is on the ${ph} phase conductor (not wrong phase). (2) Check CT secondary polarity (S1/S2). If wiring is correct and load is resistive, use meter setting: set current phase angle correction for Phase ${ph} to ${correction > 0 ? '+' : ''}${correction.toFixed(1)}°, or PF/angle compensation to ${correction.toFixed(1)}° on the current channel. If load is not resistive, turn off "Expect unity PF".`
});
}
});
// Render summary
const summaryEl = document.getElementById('summary');
if (issues.length === 0) {
summaryEl.innerHTML = `
<div class="result-item ok">
<span class="icon">✓</span>
<span class="label">Phase rotation</span>
<span class="detail">${rotationOk ? 'ABC (positive sequence): Vb−Va ≈ −120°, Vc−Va ≈ +120°.' : 'Voltage angles within tolerance.'}</span>
</div>
<div class="result-item ok">
<span class="icon">✓</span>
<span class="label">Voltage balance</span>
<span class="detail">Vb−Va and Vc−Va within expected range.</span>
</div>
<div class="result-item ok">
<span class="icon">✓</span>
<span class="label">V−I angles</span>
<span class="detail">No polarity reversal indicated.</span>
</div>
`;
} else {
const voltageIssues = issues.filter(i => i.type === 'voltage');
const polarityIssues = issues.filter(i => i.type === 'polarity');
summaryEl.innerHTML = '';
if (voltageIssues.length) {
summaryEl.innerHTML += `
<div class="result-item err">
<span class="icon">⚠</span>
<span class="label">Voltage phase</span>
<span class="detail">${voltageIssues.map(i => i.msg).join('; ')}</span>
</div>`;
}
if (polarityIssues.length) {
summaryEl.innerHTML += `
<div class="result-item err">
<span class="icon">⚠</span>
<span class="label">Polarity / CT</span>
<span class="detail">${polarityIssues.map(i => i.msg).join('; ')}</span>
</div>`;
}
const swapIssues = issues.filter(i => i.type === 'swap');
if (swapIssues.length) {
summaryEl.innerHTML += `
<div class="result-item err">
<span class="icon">⚠</span>
<span class="label">Phase swap / rotation</span>
<span class="detail">${swapIssues.map(i => i.msg).join('; ')}</span>
</div>`;
}
}
// Power factor from phase angle: pf = cos(φ) — Electrical Ampere
const PF_RESISTIVE_TOL = 15; // degrees; |φ| < this → resistive
const pfSectionEl = document.getElementById('pfSection');
const phases = [
{ name: 'Phase A', vi: viAngle.A },
{ name: 'Phase B', vi: viAngle.B },
{ name: 'Phase C', vi: viAngle.C },
];
pfSectionEl.innerHTML = phases.map(({ name, vi }) => {
if (isNaN(vi)) return `<div class="pf-phase"><span class="phase-name">${name}</span><div class="pf-value">—</div><div class="pf-type">Enter angles</div></div>`;
const rad = vi * Math.PI / 180;
const pf = Math.cos(rad);
let typeClass = '';
let typeText = '';
if (Math.abs(vi) < PF_RESISTIVE_TOL) {
typeClass = 'resistive';
typeText = 'Resistive (V and I in phase)';
} else if (vi > 0) {
typeClass = 'inductive';
typeText = 'Lagging (I lags V — inductive)';
} else {
typeClass = 'capacitive';
typeText = 'Leading (I leads V — capacitive)';
}
const pfStr = pf.toFixed(3);
const lowPf = Math.abs(pf) < 0.5 && Math.abs(vi) > 30;
if (lowPf) fixes.push({ what: `${name} power factor`, suggestion: `PF = ${pfStr} (φ = ${vi.toFixed(1)}°). Low PF may indicate heavy reactive load or meter angle error — verify CT/PT and phase angles.` });
return `<div class="pf-phase">
<span class="phase-name">${name}</span>
<div class="pf-value">φ = ${vi.toFixed(1)}° &nbsp; → &nbsp; pf = ${pfStr}</div>
<div class="pf-type ${typeClass}">${typeText}</div>
</div>`;
}).join('');
// Fix list
if (meter.ctStr || meter.ptStr || meter.ctType !== 'standard') {
const meterNote = [meter.ctStr && ('Set meter CT ratio to ' + meter.ctStr + '.'), meter.ptStr && ('PT ratio: ' + meter.ptStr + '.')].filter(Boolean).join(' ');
const rctAdd = meter.ctType === 'rogowski' ? ' If using a Rogowski/RCCT, ensure meter phase compensation matches the transducer.' : meter.ctType === 'residual' ? ' Residual CT gives one combined current; this tool assumes per-phase CTs.' : '';
fixes.forEach(f => {
if (/CT|meter|PT ratio|conductor|wiring|polarity|secondary|S1|S2/i.test(f.what + f.suggestion)) {
if (meterNote) f.suggestion += (f.suggestion.trim().endsWith('.') ? ' ' : '. ') + meterNote;
if (rctAdd) f.suggestion += rctAdd;
}
});
}
const fixListEl = document.getElementById('fixList');
if (fixes.length === 0) {
fixListEl.innerHTML = '<p style="color:var(--text-muted); margin:0;">No fixes suggested. Angles look consistent.</p>';
} else {
fixListEl.innerHTML = `
<p style="margin:0 0 0.5rem 0; font-weight:600;">Suggested fixes</p>
<ul class="fix-list">
${fixes.map(f => `
<li>
<span class="what">${f.what}</span><br>
<span class="suggestion">${f.suggestion}</span>
</li>
`).join('')}
</ul>`;
}
// Table: one row per phase, V and I next to each other
const tableRows = [
{ phase: 'A', Ve: raw.Va, Ie: raw.Ia, Vn: norm.Va, In: norm.Ia, vi: viAngle.A },
{ phase: 'B', Ve: raw.Vb, Ie: raw.Ib, Vn: norm.Vb, In: norm.Ib, vi: viAngle.B },
{ phase: 'C', Ve: raw.Vc, Ie: raw.Ic, Vn: norm.Vc, In: norm.Ic, vi: viAngle.C },
];
const fmt = (x) => (x != null && !isNaN(x) ? x.toFixed(2) + '°' : '—');
document.getElementById('anglesBody').innerHTML = tableRows.map(r => `
<tr>
<td>Phase ${r.phase}</td>
<td class="mono">${fmt(r.Ve)}</td>
<td class="mono">${fmt(r.Ie)}</td>
<td class="mono">${fmt(r.Vn)}</td>
<td class="mono">${fmt(r.In)}</td>
<td class="mono">${r.vi != null ? fmt(r.vi) : '—'}</td>
</tr>
`).join('');
drawRadialChart(norm);
drawLineChart(norm);
}
ids.forEach(id => {
document.getElementById(id).addEventListener('input', analyze);
document.getElementById(id).addEventListener('change', analyze);
});
document.getElementById('unityPf').addEventListener('change', analyze);
['ctPrimary', 'ctSecondary', 'ptPrimary', 'ptSecondary', 'nominalVoltage', 'ctType'].forEach(id => {
const el = document.getElementById(id);
if (el) { el.addEventListener('input', analyze); el.addEventListener('change', analyze); }
});
analyze();
</script>
</body>
</html>