aboutsummaryrefslogtreecommitdiff
path: root/src/models/electric-flux/state.ts
blob: 7bded331898e32188fe8850914112733e93edd01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import type { ClosedSurface, PointCharge, SurfaceShape } from './physics';

export interface FluxState {
  chargeNC: number;
  chargeX: number;
  size: number;
  shape: SurfaceShape;
  fieldLines: boolean;
  surface: boolean;
  normals: boolean;
}

export const defaultState: Readonly<FluxState> = {
  chargeNC: 2,
  chargeX: 0,
  size: 1.8,
  shape: 'sphere',
  fieldLines: true,
  surface: true,
  normals: false,
};

export const presets = {
  positive: { ...defaultState },
  negative: { ...defaultState, chargeNC: -2 },
  outside: { ...defaultState, chargeX: 3.2 },
} satisfies Record<string, FluxState>;

export type Preset = keyof typeof presets;

export function physicsInputs(state: FluxState): { charge: PointCharge; surface: ClosedSurface } {
  return {
    charge: { coulombs: state.chargeNC * 1e-9, position: { x: state.chargeX, y: 0, z: 0 } },
    surface: { shape: state.shape, size: state.size },
  };
}