@ferret/physics-vehicles
ships, submarines and balloons: hulls, ballast, flooding, thrusters, foils and sails.
Read the guide: how to use it →
Classes
Aeroplane class
class Aeroplanepos: Vec3 | |
vel: Vec3 | |
q: Quat | |
w: Vec3 | |
controls: Controls | |
fuel: number | |
crashed: boolean | |
status: Status | ok, damaged (a part gone, the gear collapsed) or destroyed (the aeroplane is a wreck: the controls and lift are gone) |
wreck: string | null | |
readonly broken: Set<string> | |
gearCollapsed: boolean | |
name: string | |
time: number | |
readonly limits: string[] | |
readonly mass0: number | |
readonly I: Vec3 | |
readonly strips: Strip[] | |
readonly contacts: ContactSpec[] | |
readonly engines: { at: Vec3; powerFull: number; hc: number; exp: number; power: number }[] | |
readonly propOmega: number[] | the propeller's shaft speed of each engine, rad/s (a magnitude; see propClockwise for the sense): the engine's power against the propeller's load, held by the governor near the speed the throttle asks for, rising in a dive and sagging in a climb or a hard pull; running down when the engine stops |
readonly propPitch: number[] | the governor's blade setting of each propeller, as a zero-thrust advance ratio (see propPitchRange) |
readonly propOmegaMax: number | the full shaft speed, rad/s: propRpm if given, else the engine's rpm times the gear ratio if the spec has both, else the speed at which the blade tips run at Mach 0.72 (the usual design speed of a propeller; an estimate, listed in limits) |
readonly opts: AeroplaneOptions | |
readonly atm: Atmosphere | |
out: Readout | the readings of the last step |
constructor(spec: AircraftSpec, opts: AeroplaneOptions = {}) | |
alphaStall: number | the body angle of attack (rad) at which the clean wing reaches CLmax: an autopilot keeps below it |
park(n: number, e: number, headingDeg: number): this | place the aircraft at rest on the ground at (north, east), heading in degrees from north, in its three-point attitude with the wheels on the ground |
fly(n: number, e: number, altitude: number, headingDeg: number, trueAirspeed: number, pitchDeg = 0, pitchBy = 0): this | start in the air: trimmed straight and level is trimLevel; this sets the attitude and speed only |
get altitude() | |
get length() | |
get span() | |
pilotDead: boolean | the pilot is dead: the controls stay where they were (set by the damage rules) |
get totalMass() | |
trimLevel(V: number, altitude: number, headingDeg = 0, o: { stillAir?: boolean } = {}): { ok: boolean; pitch: number; elevator: number; throttle: number; residual: number } | Set up steady level flight at a true airspeed and altitude on the heading: solves the pitch, the elevator and the (common) throttle that make the accelerations along and across the flight path and about the pitch axis vanish (Newton on a numerical Jacobian). The gear is raised, the flaps up. Returns false when no throttle in 0..1 holds that speed (it is too fast or too slow for the engine). |
applyTrim(t: { pitch: number; elevator: number; throttle: number }, V: number, altitude: number, headingDeg = 0, o: { stillAir?: boolean } = {}): void | Put the aeroplane in a trim found before by trimLevel for the same speed, altitude and load (a game that spawns many of one type keeps the
results): the same state trimLevel leaves, without its search (which costs some thousands of force evaluations). |
step(dt: number, hz = 200): void | advance by dt seconds |
hull(): { name: string; a: Vec3; b: Vec3; r: number }[] | the aeroplane's shape for collisions: capsules in the body frame, each a part that can be hit and broken off |
collideWith(other: Aeroplane): { speed: number; parts: [string, string][]; point: Vec3 } | null | A mid-air collision with another aeroplane (a ram, or a wing clipped in formation): the parts' capsules are tested against each other. Fuselage against fuselage destroys both; a wing or tail that meets anything comes off; a fuselage struck by a wing is destroyed above 40 m/s of closing speed (estimated) and damaged below. Momentum is exchanged (restitution 0.2) with a kick in rotation. Returns the closing speed and the parts that met, or null. |
velocityAt(point: Vec3): Vec3 | the velocity of a world point fixed to the aeroplane |
stallSpeedIAS(flaps = 0): number | the indicated stall speed at the present mass, m/s (clean at flaps 0, landing configuration at 1) |
takeEvents(): AeroEvent[] | drain the events since the last call (touchdowns, breaks, collisions, the end) |
breakOff(part: string, cause: 'overstress' | 'ground' | 'collision' | 'hit' = 'hit'): void | a part comes off: 'wingL' / 'wingR' (the outer two thirds), 'htail', 'fin', 'engineN' (the engine stops for good). Lift, balance and control change with it |
destroy(cause: string, speed: number, vertical: number): void | the end: the controls and the lift are gone, the engines stop; the wreck keeps its momentum and drags along the ground |
toScene(): { position: Vec3; forward: Vec3; up: Vec3; right: Vec3 } | the pose for a Babylon scene (x east, y up, z south): the position and the three body axes in scene coordinates |
packages/physics-vehicles/src/aeroplane.ts:118
Airship class
class Airshipreadonly vessel: Vessel | |
readonly spec: AirshipSpec | |
readonly contract: AirshipContract | |
readonly engines: Engine[] | |
readonly cellIds: number[] | |
readonly mooringAt: Vec3 | body-frame positions of the mooring point and the ground contacts |
crash: Crash | null | the first crash, or null: a hard landing (closing speed over 4 m/s) or the hull driven 2 m into the ground |
elevator: number | the elevator and rudder commands, -1..1 (positive: nose up, nose to starboard) |
rudder: number | |
helm: { pitch: number | null; heading: number | null } | The helmsmen: with a target set, the elevator (pitch) or the rudder (heading, rad from +z toward +x) is driven by a PD law each sub-step, as the two helmsmen of the real ship did. The hull is about neutrally stable in pitch and yaw at cruise (the fin lift slope is tuned for that), so a ship left alone drifts slowly; with the helm held it is steady. Set a target to null to take the wheel. |
ventedKg: number | |
fuelBurnt: number | the loads in kg: fuel burnt and ballast dropped so far |
ballastDropped: number | |
map(p: Vec3): Vec3 | A point of the model (X nose to tail, Y up, Z to starboard) in the vessel's body frame. The sign of x is chosen so that the model, as the Babylon glTF importer gives it (z flipped), turns into the body frame by a quarter turn about the vertical and not by a reflection: a mirror would be harmless for a ship symmetric about its centre plane, but the picture and the physics must agree on which engine car is where. (Body x is then the model's port side; the ship is symmetric, only the names say which is which.) |
mapDir(p: Vec3): Vec3 | a direction of the model in the vessel's body frame |
constructor(spec: AirshipSpec, contract: AirshipContract, o: AirshipOptions = {}) | |
telegraph(command: number, i?: number) | Telegraph: -1 (full astern) .. 1 (full ahead) for engine i (0-based), or for all when i is omitted. |
get cruiseCommand() | the commanded share of the maximum shaft speed that gives the cruise power: (cruise_rpm / max_rpm), ahead |
valve(id: number, open: boolean) | Open or shut the manoeuvring valve of a cell (ids from 1, aft to fore); only cells with one respond. |
dropBallast(i?: number) | Drop the water of a bag (or of all bags) at its release rate. |
dropShare(share: number) | Drop a share of every bag's present load (0..1). |
get ballastKg() | |
get fuelKg() | |
cellFill(id: number): number | Gas in cell id as a share of the cell's volume now. |
get heaviness(): number | the heaviness now: the mass less the air the cells displace, in kg (positive: heavy, sinking) |
get gasMassKg(): number | the mass of the lifting gas in the cells, kg |
moor(anchor: Vec3, length: number) | |
unmoor() | |
get moored() | |
tension: number | tension of the mooring line now, N |
setGround(on: boolean) | |
get position(): Vec3 | |
get altitude() | altitude of the hull axis above sea level, m |
get airVelocity(): Vec3 | velocity through the air in the body frame [starboard, up, bow], m/s |
get airspeed() | |
get groundSpeed() | |
get climbRate() | |
get heading() | |
get pitch() | pitch (nose up positive) and roll (starboard down positive), rad |
get roll() | |
get turnRate() | yaw rate about the vertical, rad/s (positive: nose to starboard) |
step(dt: number, h = 0.05) | Advance by dt seconds in sub-steps of at most h s. |
get groundLoad() | Total weight on the ground, N (the sum of the contacts) |
reset() | Start a run: remember the loads for ballastDropped. |
packages/physics-vehicles/src/airship.ts:87
Autopilot class
class AutopilotA heading, altitude and speed hold: the heading error commands a bank (up to the limit), the bank is held by the ailerons; the altitude error commands a climb rate and so a flight path angle, held by the elevator with an integrator that finds the pull a turn needs; the speed is held by the throttle (a common one) with an integrator; the rudder damps the yaw and cancels the sideslip. Engage it on an aeroplane in steady flight (trimLevel puts one there).
heading: number | null | |
altitude: number | null | |
speed: number | null | |
maxBank: number | |
maxClimb: number | |
maxDescent: number | |
constructor(readonly plane: Aeroplane) | |
engage(): this | take the present controls as the trim of the hold |
steerTo(n: number, e: number, altitude?: number): this | point the holds at a place in NED metres: the heading toward it and its altitude (the speed is left as it is) |
update(dt: number): void |
packages/physics-vehicles/src/flight.ts:52
Ballistics class
class Ballisticsreadonly rounds: Round[] | |
readonly targets: { plane: Aeroplane; dmg: Damageable }[] | |
wind: (p: Vec3) => Vec3 | |
onHit: ((h: HitEvent) => void) | null | |
filter: ((owner: Aeroplane | null, target: Aeroplane) => boolean) | null | may a round (or a flak fragment, owner null) of owner hurt target: friendly fire is the caller's rule; default every target |
constructor(readonly z: ZoneSpec) | |
addTarget(plane: Aeroplane, dmg: Damageable) | |
fire(origin: Vec3, vel: Vec3, ammo: Ammo, caliber: number, cd: number, owner: Aeroplane | null, incendiary = false): Round | |
step(dt: number) |
packages/physics-vehicles/src/weapons.ts:111
Damageable class
class Damageableper-aircraft damage state and the rules that turn absorbed energy into failures
readonly toughness: Record<string, number> | |
readonly absorbed: Record<string, number> | |
pilotDead: boolean | |
fire: boolean | |
fireTime: number | |
fuelLeak: number | |
hits: number | |
constructor(readonly plane: Aeroplane, readonly z: ZoneSpec, readonly rng: Rng, spec: { empty: number; engineW: number; crewAt: Vec3 }) | |
readonly crewAt: Vec3 | |
zoneOf(part: string, pb: Vec3): { zone: HitZone; key: string } | which zone a hit on a part at a body-frame point belongs to |
apply(zone: HitZone, key: string, part: string, energy: number, incendiary: boolean): string[] | apply an impact of energy joules (already the absorbed part) in a zone; incendiary can start a fire in a fuel zone |
update(dt: number) | the burn: a fire ends the aeroplane after its time; a pilot killed freezes the controls (the aeroplane flies on as it was trimmed) |
packages/physics-vehicles/src/weapons.ts:65
FlakBattery class
class FlakBatteryan 88 mm battery: predicted fire at a target with a range error, the shell bursts at the aim point and throws fragments
only?: (plane: Aeroplane) => boolean | which aeroplanes this battery's bursts hurt: when set, it replaces the Ballistics filter (a battery of the other side) |
constructor(readonly pos: Vec3, readonly spec: FlakSpec, readonly rng: Rng, readonly guns = 4) | |
update(dt: number, target: Aeroplane, b: Ballistics): Vec3[] | fire one salvo if ready and the target is in the envelope; each shell bursts within the aim error of the predicted position. Returns the bursts |
burst(at: Vec3, b: Ballistics) | a burst at a point: the fragments of the case fly out evenly in all directions; the share that crosses a part's capsule is counted by its solid angle |
packages/physics-vehicles/src/weapons.ts:180
Gun class
class Guna gun on an aeroplane: a mount point and a direction in the body frame, a magazine and a rate; the fire-control is the caller's trigger
rounds: number | |
constructor(readonly plane: Aeroplane, readonly spec: GunSpec, readonly mount: Vec3, readonly ammoType: string, readonly rng: Rng, public dir: Vec3 = [1, 0, 0], readonly tracerEvery = 5, readonly incendiaryEvery = 0) | |
aimAt(world: Vec3): void | point the barrel at a world point (the fire-control: a gunsight or the harmonisation); the bullet's drop and lead are the caller's |
trigger(b: Ballistics, dt: number): number | fire for dt seconds; returns the number of rounds sent |
packages/physics-vehicles/src/weapons.ts:156
HullResistance class
class HullResistanceWhat Vessel reads each step (VesselSpec.resistance): the hull's force on the ship in the body frame (x starboard, y up, z bow) from the body velocity, the
share of the hull that is wet, the sea and the wind. The resistance acts along the surge velocity; across the ship the hull's own hullDrag / hullDamping stay.
constructor(readonly hull: HullParticulars) | |
surge(vz: number, wet = 1): number | the surge force, N (negative while the ship goes ahead) |
seaForce(vz: number, wet: number, sea: SeaState, headingRad: number): number | the added resistance of the sea, N (against the way, or against the drift when the ship is stopped it pushes along the waves) |
windForce(relWind: [number, number, number]): [number, number, number] |
packages/physics-vehicles/src/hull-resistance.ts:170
Pilot class
class PilotsurfaceTime: number | the time a surface takes to go from the middle to the stop, s (a hand on the stick: 0.25) |
throttleRate: number | the throttle lever, per second |
flapRate: number | the flap lever, per second (the flaps take about 8 s to run down) |
constructor(readonly plane: Aeroplane) | |
update(input: PilotInput, dt: number): void | Move the controls toward the input. With a load limit set on the aeroplane the controls stiffen above the manoeuvring speed (the stall speed times the root of the limit load factor): full deflection would break it, so the available throw falls as that speed over the speed. Without a limit they do not. |
packages/physics-vehicles/src/flight.ts:15
Rng class
class Rnga small seeded generator so a run is repeatable
constructor(private s = 1) | |
next(): number | |
gauss(): number |
packages/physics-vehicles/src/weapons.ts:36
Vessel class
class Vesselreadonly spec: VesselSpec | |
env: Environment | |
pos: Vec3 | world position of the body origin, orientation, velocity of the centre of gravity, angular velocity (world) |
q: Quat | |
v: Vec3 | |
w: Vec3 | |
time: number | |
readonly tanks: Tank[] | |
readonly compartments: Comp[] | |
readonly breaches: Array<BreachSpec & { Cd: number }> | |
readonly envelopes: Env[] | |
readonly thrusters: Thr[] | |
readonly surfaces: Surf[] | |
crushed: boolean | |
dynamic: boolean | step the dynamics; false holds the pose (to read the flooding or the forces alone) |
onEvent: ((e: VesselEvent) => void) | null | |
last: { buoyancy: number; weight: number; lift: number; submerged: number; } | forces seen in the last step, for readouts |
readonly doors: Array<DoorSpec & { open: boolean }> | |
constructor(spec: VesselSpec, env: Environment = defaultEnvironment()) | |
mass() | total mass, centre of gravity and principal inertia now (the body-frame centre the state follows is only moved by a step) |
world(p: Vec3): Vec3 | world position of a body-frame point |
body(v: Vec3): Vec3 | body-frame vector of a world vector |
pointVelocity(p: Vec3): Vec3 | velocity of a body point in the world |
hydrostatics(): Hydro | Displaced volume, centre of buoyancy and the force of the water on the hull, from the cells against the surface. |
get wetShare(): number | Share of the hull volume under water. |
get draft(): number | Draft of the hull: the depth of its lowest point under the surface along the up direction (m). |
get heel() | heel (about the bow axis) and trim (about the beam axis) in radians; positive heel lowers the starboard side |
get trim() | |
get depth() | pressure at the gauge, Pa, and the depth of the gauge under the surface, m |
get pressure() | |
get altitude() | |
get total() | |
stability(): { draft: number; volume: number; kb: number; kg: number; bm: number; gm: number; gmNumeric: number; freeSurface: number } | Stability: draft, volume, KB, KG, BM = I/V and GM for a box hull, with the GM also found by heeling the hull a little. |
freeSurfaceLoss(): number | The metacentric height that free surfaces take: a part-filled compartment lets its water run to the low side as the vessel heels, which acts
like a higher centre of gravity by rho_w i / m with i = length x beam^3 / 12 the second moment of its water plane (the formula of the
free-surface correction). A full or empty compartment, or one with no beam, takes nothing. |
metacentric(phi = 0.03): number | GM from the righting arm at a small heel: GZ / sin φ with the draft re-found so that buoyancy equals weight. |
tank(name: string) | |
fill(name: string, fraction: number) | |
blow(name: string) | Blow the tank with compressed air: it empties (fast). |
thruster(name: string) | |
surface(name: string) | |
envelope(name?: string) | |
compartment(name: string) | |
door(name: string) | |
setDoor(name: string, open: boolean) | Shut or open a watertight door. |
breach(b: BreachSpec) | |
lift(e: Env = this.envelopes[0]): number | Lift of an envelope now: (ρ_air − ρ_gas)·V·g, N. |
step(dt: number, sub = 1) | |
windAt(p: Vec3): Vec3 | the air flow at a world point: the wind of the environment at that height plus the flow field |
applyForce(f: Vec3, worldPoint?: Vec3) | A force (N, world) at a world point, held for the step: every sub-step of it sees the force, then the list is cleared. Without a point it acts at the centre of gravity. |
applyTorque(t: Vec3) | A torque (N·m, world) held for the step. |
applyImpulse(j: Vec3, worldPoint?: Vec3) | An instant push (N·s, world) at a world point: changes the velocity and the angular velocity now. |
clearExternal() | Forget the forces and torques applied for the step (the capability does it after reading them). |
forces(h: number): { F: Vec3; T: Vec3; m: { m: number; cog: Vec3; I: Vec3 } } | The vessel's parts over a step of h: pumps, flooding and burners change the mass, then every force on the body is summed about the
centre of gravity (weight included). The state is not moved; step integrates it itself, or a rigid-body kernel does (adopt). |
adopt(pos: Vec3, q: Quat, v: Vec3, w: Vec3) | Take the pose and the velocities from a body a kernel moves (the velocity of the centre of gravity, the angular velocity). |
advanceClock(dt: number) | After a kernel moved the body: the clock and the events. |
get centreWorld(): Vec3 | world position of the centre of gravity |
packages/physics-vehicles/src/vessel.ts:163
Functions
addedResistanceInWaves function
function addedResistanceInWaves(h: HullParticulars, sea: SeaState, rel: number, speed: number): numberThe added resistance in waves, N (positive: against the ship's way), from the wave height, the wave length against the ship's and the heading to the waves.
Faltinsen's bow-reflection estimate, R = 1/2 rho g zeta_a^2 B f(lambda/L) (B/L)^0.5 cos-weighted by the encounter angle, with a ship-length tuning curve
peaking at lambda/L about 0.7 and falling on either side (the pitching resonance of a slender hull). rel is the angle of the waves' travel relative to
the heading, 0 = the waves go the way the ship does (following sea), pi = head sea. The mean of the squared amplitude of a sea of Hs is (Hs/4)^2 x 2 = Hs^2/8.
packages/physics-vehicles/src/hull-resistance.ts:130
buildAirship function
function buildAirship(spec: AirshipSpec, contract: AirshipContract, o: AirshipOptions = {}): AirshipBuild an airship from spec.json and airship.json (parsed).
packages/physics-vehicles/src/airship.ts:422
calmWaterResistance function
function calmWaterResistance(h: HullParticulars, v: number): ResistancePartsthe calm-water resistance at the speed v (m/s, along the hull), N, with its parts
packages/physics-vehicles/src/hull-resistance.ts:106
cfITTC57 function
function cfITTC57(re: number): numberthe ITTC-1957 model-ship correlation line
packages/physics-vehicles/src/hull-resistance.ts:41
coefficients function
function coefficients(h: HullParticulars)the derived coefficients of a hull
packages/physics-vehicles/src/hull-resistance.ts:44
defaultEnvironment function
function defaultEnvironment: (level?: number) => Environmentpackages/physics-vehicles/src/vessel.ts:148
discThrust function
function discThrust(p: number, u: number, rho: number, d: number): numberThrust of an actuator disc of diameter d taking p watts from the shaft at flight speed u (m/s) in air of density rho: P = T (u/2 + sqrt(u²/4 + T/(2 rho A))).
packages/physics-vehicles/src/airship.ts:76
formFactor function
function formFactor(h: HullParticulars): numberHoltrop's form factor 1 + k1 of the hull
packages/physics-vehicles/src/hull-resistance.ts:57
froude function
function froude: (v: number, length: number) => numberpackages/physics-vehicles/src/hull-resistance.ts:38
neutralFill function
function neutralFill(spec: AirshipSpec, contract: AirshipContract, altitude: number, mass = contract.mass.loaded_kg): numberThe cell fill (a share of the volume at the pressure and temperature of altitude) at which the ship of mass kg is neutral with the cells just full at that altitude; with that many moles at a lower altitude the cells are slack and the ship is neutral there too.
packages/physics-vehicles/src/airship.ts:416
propellerThrust function
function propellerThrust(power: number, diameter: number, v: number, o: { rho?: number; figureOfMerit?: number; efficiency?: number } = {}): numberthe thrust of a propeller of a given shaft power and diameter at the speed of advance v, N: the static (bollard) pull from the actuator disc with a figure of merit, falling as eta P / v
packages/physics-vehicles/src/hull-resistance.ts:148
readWeapons function
function readWeapons(j: any): { guns: Record<string, GunSpec>; flak: FlakSpec; zones: ZoneSpec }the read form of weapons.json -> the specs above; a missing (null) value throws, naming it
packages/physics-vehicles/src/weapons.ts:18
reynolds function
function reynolds: (v: number, length: number, nu?: number) => numberpackages/physics-vehicles/src/hull-resistance.ts:39
sailPolar function
function sailPolar(clAlpha: number, stall: number, cd0: number, k: number, alpha: number)Force of a sail (a surface in the wind) along the boat's heading and across it, for an apparent wind at beta from the bow and the sail set at alpha to it.
packages/physics-vehicles/src/vessel.ts:696
topSpeed function
function topSpeed(h: HullParticulars, shaftPower: number, shafts: number, diameter: number, o: { efficiency?: number; figureOfMerit?: number } = {}): numberthe steady speed (m/s) at which the thrust of n shafts of the given power balances the calm-water resistance: the top speed of the ship in calm water
packages/physics-vehicles/src/hull-resistance.ts:156
vehicles function
function vehicles(): VehiclesCapabilitypackages/physics-vehicles/src/index.ts:37
waveMakingResistance function
function waveMakingResistance(h: HullParticulars, v: number): numberthe wave-making resistance, N: the low-speed formula up to Fn 0.4, a straight blend to the high-speed one at 0.55 (Holtrop and Mennen's own interpolation)
packages/physics-vehicles/src/hull-resistance.ts:94
wettedArea function
function wettedArea(h: HullParticulars): numberHoltrop's wetted area of the bare hull, m²
packages/physics-vehicles/src/hull-resistance.ts:51
windage function
function windage(h: HullParticulars, rel: [number, number, number], rhoAir = 1.225): [number, number, number]the wind's force on the ship above the water, N in the body frame (x starboard, z bow), from the relative wind rel in the body frame (the air's velocity minus the ship's)
packages/physics-vehicles/src/hull-resistance.ts:142
Interfaces
AeroplaneOptions interface
interface AeroplaneOptionsatmosphere?: Atmosphere | |
wind?: Wind | wind velocity in the world frame (NED) at a point, m/s |
ground?: (n: number, e: number) => number | the ground height above sea level at (north, east), m |
contacts?: ContactSpec[] | gear positions, relative to the centre of gravity; the default is a tail-dragger with estimated geometry (fractions of length, span and height) |
gearDeflection?: number | spring-damper of the gear: static deflection under full weight at the main gear, m (estimated) |
propRpm?: number | propeller rotation, rpm (the specification leaves the gear ratio blank, so torque and gyroscopic moment need it from the caller) |
propInertia?: number | moment of inertia of one propeller with its spinner, kg m2 (not in the sources) |
propClockwise?: boolean | propeller rotates clockwise seen from behind (the usual British and American engines) |
propPitchRange?: [number, number] | the blade-angle range of a constant-speed propeller, as zero-thrust advance ratios (fine stop, coarse stop); the governor moves the blades inside it to hold the shaft speed the throttle asks for, and at a stop the shaft speed follows the airspeed (an overspeed in a fast dive). Default [0.7, 3.0] (estimated) |
powerWander?: number | relative wander of the engine's power (mixture, cycle-to-cycle scatter), a slow random walk the shaft speed and the governor answer; default 0.015, 0 = steady |
seed?: number | seed of the wander (the same seed gives the same flight) |
sfc?: number | fuel use, kg per joule of shaft work (the specification leaves it blank): with it the fuel burns, without it the mass is constant |
enginePositions?: Vec3[] | engine positions, body frame, m; default: the nose, or the four wing engines at 0.19 and 0.40 of the semi-span for four engines |
fuel?: number | fuel on board, kg; default full |
payload?: number | mass of load besides the empty aircraft and the fuel (crew, ammunition, bombs), kg; default makes up the gross mass |
extraDragArea?: number | extra drag from damage etc., an area in m2 |
loadLimit?: { positive: number; negative: number } | limit load factors, g (the specification has none): without them the airframe never breaks from overload. The structure fails at breakFactor times the limit (1.5, the ultimate factor of the airworthiness rules) |
breakFactor?: number | |
surface?: (n: number, e: number) => 'land' | 'water' | what the ground is at (north, east): 'land' (default) or 'water'. Touching water at all is the end of the aeroplane (a ditching is not modelled) |
sinkLimit?: number | thresholds of the impact tests (estimated: the specification has none): the landing sink rate the gear takes (10 ft/s, the design value of the airworthiness rules), after which the gear collapses at twice that; a vertical or total speed at which the structure is destroyed |
destroyVertical?: number | |
destroyTotal?: number |
packages/physics-vehicles/src/aeroplane.ts:50
AircraftSpec interface
interface AircraftSpecthe part of spec.json for one aircraft that the model reads
name: string | |
geometry: { length: N; span: N; height: N; wing_area: N; prop_diameter?: N; mean_chord: N } | |
mass: { empty: N; gross: N; fuel_capacity?: N; fuel_density?: N } | |
engine: { power_wep?: N; power_rated?: N; power_takeoff?: N; power_each?: N; count?: N; critical_altitude_mil?: N; critical_altitude?: N; power_loss_exponent: N; rpm_max?: N; gear_ratio?: N; sfc?: N } | |
aero: { k_induced: N; cl_alpha: N; alpha_zero_lift_deg: N; cl_max_clean: N; cl_max_flaps: N; cd0: N; oswald_e: N; stall_sharpness?: N } | |
inertia: { Ixx: N; Iyy: N; Izz: N } | |
controls: { max_aileron_deg: N; max_elevator_deg: N; max_rudder_deg: N; aileron_effectiveness: N; elevator_effectiveness: N; rudder_effectiveness: N; cm_alpha_static_margin: N; tail_volume_h: N; tail_volume_v: N; tail_arm_fraction: N; tail_aspect_ratio: N; fin_aspect_ratio: N; wing_cm0: N; dihedral_deg: N; flap_drag_cd: N; gear_drag_cd: N; prop_figure_of_merit: N; prop_efficiency_peak: N; prop_speed_scale: N; engine_spool_time: N } |
packages/physics-vehicles/src/aeroplane.ts:26
AirshipContract interface
interface AirshipContractcells: Array<{ id: number; volume_m3: number; centroid: Vec3 }> | |
mass: { loaded_kg: number; centre: Vec3; groups: Array<{ name: string; kg: number; at: Vec3 }> } | |
engines: { cars: Array<{ car: string; prop: string; at: Vec3 }> } | |
surfaces: Array<{ node: string; fin: string; hinge_at: Vec3; hinge_axis: Vec3; max_deflection_deg: number }> | |
mooring: { at: Vec3 } |
packages/physics-vehicles/src/airship.ts:27
AirshipOptions interface
interface AirshipOptionsaltitude?: number | altitude of the hull axis above sea level, m (default 600) |
heading?: number | heading of the bow, rad from the world +z toward +x |
speed?: number | speed through the air along the bow, m/s |
fuel?: number | the start state of the loads: fuel and ballast in kg (the design values by default) and the cell fill (the spec's start fill) |
ballast?: number | |
fill?: number | |
env?: Environment | |
ground?: boolean | ground contacts and a mooring line |
terrain?: (x: number, z: number) => number | the ground height at (x, z) in metres; without it the ground is flat at the sea level. With it the hull itself is sampled and a hard touch is a crash. |
packages/physics-vehicles/src/airship.ts:35
AirshipSpec interface
interface AirshipSpecA rigid airship (LZ 129 and its kind) on top of Vessel: many gas cells, ballast bags and fuel as tanks, engines with a telegraph and a propeller, four hinged fins, the air's added mass, the hull's aerodynamics (axial drag, Munk moment, cross-flow drag), a mooring line and the ground. It reads two documents of examples/zeppelin: spec/spec.json (the design) and build/airship.json (the contract the Blender model writes: cell volumes and centroids, mass groups, hinge lines). The model's axes are X nose to tail, Y up, Z to starboard; the vessel's body axes are x starboard, y up, z bow, with the origin on the hull axis under the loaded centre of mass in x.
What is estimated rather than sourced: the added-mass coefficients, the cross-flow drag, the fin aspect ratio and the flap effectiveness, the propeller efficiency split, the reverse-thrust share, the ground contacts.
hull: { length: number; diameter: number; xm_share: number; profile_exponent: number } | |
cells: { count: number; valve_flow_m3s: number; list: Array<{ id: number; auto_valve: boolean; manoeuvre_valve: boolean }> } | |
gas: { purity: number; start_fill: number; rho_air: number; rho_he: number } | |
engines: { count: number; max_w: number; max_rpm: number; cruise_w: number; cruise_rpm: number; gear_ratio: number; sfc_kg_per_kwh: number; prop: { diameter: number; eta: number } } | |
fins: Array<{ name: string; area: number; span: number; control_area: number; max_deflection_deg: number }> | |
aero: { cd_volume: number; ref_area_m2: number; v_cruise: number; v_max: number } | |
tanks: { fuel_capacity_kg: number; fuel_density: number; ballast_capacity_kg: number; ballast_bags: number } | |
design: { payload_kg: number; fuel_kg: number; fuel_x: number; fuel_y: number; ballast_kg: number; bag_kg: number[]; bag_x: number[]; bag_y: number[] } |
packages/physics-vehicles/src/airship.ts:17
BreachSpec interface
interface BreachSpecname: string | |
compartment: string | |
at: Vec3 | |
area: number | |
Cd?: number |
packages/physics-vehicles/src/vessel.ts:35
CompartmentSpec interface
interface CompartmentSpecname: string | |
volume: number | |
at: Vec3 | |
area: number | |
floor: number | |
beam?: number | |
slosh?: boolean | number | let the water slosh across the beam as a motion: Housner's mass on a spring at the first mode, ω² = (π g / B) tanh(π h / B), with this damping ratio (0.03 when true) |
packages/physics-vehicles/src/vessel.ts:30
ContactSpec interface
interface ContactSpecname: string | |
at: Vec3 | |
share: number | |
castoring?: boolean | |
brake?: 'left' | 'right' | |
structure?: boolean | |
fatal?: boolean |
packages/physics-vehicles/src/aeroplane.ts:48
Controls interface
interface Controlselevator: number | -1..1, positive pulls the nose up |
aileron: number | -1..1, positive rolls to the right |
rudder: number | -1..1, positive yaws the nose to the right |
throttle: number[] | 0..1 per engine (one number drives all) |
flaps: number | 0..1 |
trim: number | -1..1 elevator trim, as an offset of the tail's incidence (about 4 degrees at full) |
brakeLeft: number | 0..1 |
brakeRight: number | |
gearDown: boolean |
packages/physics-vehicles/src/aeroplane.ts:38
Crash interface
interface Crashwhat the ship hit and how hard (set once: the first crash)
time: number | |
speed: number | |
what: string | |
position: Vec3 |
packages/physics-vehicles/src/airship.ts:73
DoorSpec interface
interface DoorSpecA door between two compartments: open, the water between them levels by Torricelli; shut, nothing passes. at is its sill in the body frame (the flow starts above it).
name: string | |
a: string | |
b: string | |
at: Vec3 | |
area: number | |
open?: boolean | |
Cd?: number |
packages/physics-vehicles/src/vessel.ts:34
EnvelopeSpec interface
interface EnvelopeSpecname: string | |
kind: 'hot' | 'gas' | |
volume: number | m³, the full volume of the envelope |
at: Vec3 | |
temperature?: number | hot air: the temperature inside, K |
moles?: number | lighter gas: moles inside and kg/mol (it expands with height until the envelope is full, then vents) |
molarMass?: number | |
burner?: number | burner power, W, and the lumped loss to the air, W/K |
loss?: number | |
vent?: number | a vent that replaces this share of the hot air per second with ambient air |
dragArea?: number | projected area for the wind drag, m², and its coefficient |
dragCd?: number | |
dragLinear?: number | linear damping against the air, N·s/m |
packages/physics-vehicles/src/vessel.ts:36
Environment interface
interface Environmentsea?: SeaState | the sea state in the area, for the added resistance in waves (the significant height, the peak period, the direction the waves travel) |
surface: (x: number, z: number, t: number) => number | the water surface height at (x, z, t) |
waterDensity: number | |
atmosphere: Atmosphere | |
wind: (height: number) => Vec3 | wind velocity at a height |
flow?: (p: Vec3) => Vec3 | extra air flow at a world point (the level's flow sources, @ferret/flow); added to wind |
seaLevel: number | the height of the ground/sea level that the atmosphere counts from |
packages/physics-vehicles/src/vessel.ts:133
FlakSpec interface
interface FlakSpecshellMass: number | |
muzzle: number | |
rate: number | |
ceiling: number | |
fragments: number | |
fragmentMass: number | |
fragmentSpeed: number | |
aimError: number |
packages/physics-vehicles/src/weapons.ts:15
GunSpec interface
interface GunSpeccaliber: number | |
ammo: Record<string, Ammo> | |
rate: number | |
rounds: number | |
dispersion: number | |
cd: number | |
convergence: number |
packages/physics-vehicles/src/weapons.ts:13
HitEvent interface
interface HitEventpackages/physics-vehicles/src/weapons.ts:40
HullParticulars interface
interface HullParticularslength: number | waterline length, beam on the waterline and mean draft, m |
beam: number | |
draft: number | |
volume: number | displaced volume, m³ (the displacement over the water density) |
cm?: number | midship section coefficient (0.8 to 0.99), waterplane coefficient and the longitudinal centre of buoyancy in per cent of L ahead of amidships (negative: abaft) |
cwp?: number | |
lcb?: number | |
transom?: number | immersed transom area, m² (0 for a hull without a wet transom) |
appendageArea?: number | the wetted area of the appendages (shafts, struts, rudders, bilge keels), m², and their equivalent form factor 1 + k2 (1.5 to 3) |
appendageK?: number | |
frontalArea?: number | frontal and side area above the water, m², and the drag coefficients along and across the ship |
sideArea?: number | |
frontalCd?: number | |
sideCd?: number | |
rho?: number | the density of the water (kg/m³) and its kinematic viscosity (m²/s): sea water at 12 °C |
nu?: number | |
ca?: number | the correlation allowance may be overridden (otherwise Holtrop's C_A) |
packages/physics-vehicles/src/hull-resistance.ts:19
HullSpec interface
interface HullSpecsize: Vec3 | full size of the box hull |
center?: Vec3 | the centre of the box in the body frame |
cells?: [number, number, number] | cells along each axis |
fill?: (x: number, y: number, z: number) => number | the share (0..1) of the box that the hull fills at a body-frame point (a slender hull in its bounding box: a function of the section and the height); cells with none are dropped, the rest displace that share |
packages/physics-vehicles/src/vessel.ts:18
Hydro interface
interface Hydrovolume: number | |
centre: Vec3 | |
force: number | |
waterline: number |
packages/physics-vehicles/src/vessel.ts:161
PilotInput interface
interface PilotInputwhat the player asks for: stick and pedals -1..1 (pitch positive = pull the nose up, roll positive = right, yaw positive = right), throttle 0..1
pitch: number | |
roll: number | |
yaw: number | |
throttle?: number | |
flaps?: number | |
brake?: number | |
brakeLeft?: number | |
brakeRight?: number | |
gearDown?: boolean | |
trim?: number |
packages/physics-vehicles/src/flight.ts:13
Readout interface
interface Readoutairspeed: number | |
trueAirspeed: number | |
indicatedAirspeed: number | |
mach: number | |
altitude: number | |
alpha: number | |
beta: number | |
climbRate: number | |
groundSpeed: number | |
heading: number | |
pitch: number | |
roll: number | |
g: number | |
loadFactor: number | |
throttle: number[] | |
fuel: number | |
mass: number | |
onGround: boolean | |
crashed: boolean | |
stalled: boolean | |
liftOverWeight: number | |
engineKW: number[] | |
thrust: number |
packages/physics-vehicles/src/aeroplane.ts:104
ResistanceParts interface
interface ResistancePartsfriction: number | |
appendage: number | |
wave: number | |
transom: number | |
correlation: number | |
total: number |
packages/physics-vehicles/src/hull-resistance.ts:103
SeaState interface
interface SeaStatehs: number | |
period: number | |
direction: number |
packages/physics-vehicles/src/hull-resistance.ts:122
SurfaceSpec interface
interface SurfaceSpecname: string | |
at: Vec3 | |
area: number | |
hinge: Vec3 | the hinge axis in the body frame |
chord: Vec3 | direction of the chord from leading to trailing edge when undeflected |
medium?: 'water' | 'air' | |
clAlpha?: number | lift slope per radian (2π·AR/(AR+2) for a finite foil) |
stall?: number | |
cd0?: number | |
k?: number | induced drag factor: Cd = cd0 + k·Cl² |
packages/physics-vehicles/src/vessel.ts:69
TankSpec interface
interface TankSpecname: string | |
volume: number | |
at: Vec3 | |
density?: number | |
fill?: number | |
rate?: number |
packages/physics-vehicles/src/vessel.ts:29
ThrusterSpec interface
interface ThrusterSpecname: string | |
at: Vec3 | |
axis: Vec3 | |
maxThrust: number | |
medium?: 'water' | 'air' | |
maxSpeed?: number | speed along the axis at which the thrust is gone, m/s (Infinity = a constant thrust) |
source?: (u: number) => number | a machine supplies the thrust instead of the curve: (speed along the axis) → N |
packages/physics-vehicles/src/vessel.ts:58
VehiclesCapability interface
interface VehiclesCapability extends Capabilityreadonly vessels: Map<string, VesselEntry> | |
surface: Environment['surface'] | null | A surface height other than the flat water level (a wave field of L2). |
addVessel(name: string, spec: VesselSpec, entity?: Entity, opts?: { body?: boolean; material?: string }): Vessel | body: false keeps the vessel on its own integrator even when the kernel has rigid bodies (it then meets nothing). |
packages/physics-vehicles/src/index.ts:29
VesselEntry interface
interface VesselEntryA vessel on a rigid-body kernel has a body there: Havok moves it and it meets the shore, a quay and other vessels.
packages/physics-vehicles/src/index.ts:28
VesselEvent interface
interface VesselEventtype: VesselEventType | |
part?: string | |
time: number |
packages/physics-vehicles/src/vessel.ts:151
VesselSpec interface
interface VesselSpecmass: number | |
cog?: Vec3 | centre of gravity of the dry vessel in the body frame, and its principal inertia about it |
inertia: Vec3 | |
hull?: HullSpec | |
tanks?: TankSpec[] | |
compartments?: CompartmentSpec[] | |
doors?: DoorSpec[] | |
addedMass?: Vec3 | Added mass: the water the hull drags along when it accelerates, as a share of the water it displaces, per body axis (surge, heave, sway as x, y, z). About 0.05 to 0.2 along a slender hull, near 1 across a flat bottom. It slows the vessel's response and lowers the heave frequency, not its weight. |
addedInertia?: Vec3 | Added moment of inertia: the water that turns with the hull, as a share per body axis (roll about z, yaw about y, pitch about x as the axes [x, y, z]) of the moment of the displaced water as a block of the hull's size, rho V_sub (b² + c²) / 12. About 0.3 to 1 in roll for a ship. |
airAddedMass?: Vec3 | Added mass in air (an airship pushes a mass of air about with it, comparable to its own): kg per body axis at sea-level density (surge, heave, sway as x, y, z), scaled with the air density at the altitude. About k·ρ·V of the displaced air: k ≈ 0.05 along a slender hull, ≈ 0.9 across it. |
airAddedInertia?: Vec3 | the air that turns with the hull, kg·m² per body axis at sea-level density (scaled the same way) |
envelopes?: EnvelopeSpec[] | |
thrusters?: ThrusterSpec[] | |
surfaces?: SurfaceSpec[] | |
position?: Vec3 | |
orientation?: Quat | |
velocity?: Vec3 | |
crushDepth?: number | a hull that breaks below this depth, m |
hullDrag?: Vec3 | drag on the hull in the water: quadratic coefficient per axis (½ρ·Cd·A, N/(m/s)²) and linear damping (N·s/m), scaled by the submerged share |
hullDamping?: Vec3 | |
angularDamping?: Vec3 | angular damping in the water, N·m·s/rad per axis, scaled by the submerged share |
resistance?: HullResistance | the resistance of a ship's hull from its numbers (Reynolds friction, wave making, appendages, the added resistance of the sea, windage): replaces the surge term of hullDrag and hullDamping, which stay for sway and heave |
gravity?: number | gravity on the vessel's own mass, m/s² (9.80665; zero holds a test vessel up) |
gauge?: Vec3 | the point the depth gauge reads (body frame; the centre of gravity when missing) |
packages/physics-vehicles/src/vessel.ts:86
ZoneSpec interface
interface ZoneSpecabsorbed: number | |
wingPerKg: number | |
enginePerW: number | |
tailPerKg: number | |
crewEnergy: number | |
fireProb: number | |
fireTime: number | |
tnt: number |
packages/physics-vehicles/src/weapons.ts:14
Types
AeroEvent type
type AeroEvent = | { type: 'touchdown'; sink: number; speed: number; point: string } | { type: 'gear-collapse'; sink: number } | { type: 'break'; part: string; cause: 'overstress' | 'ground' | 'collision' | 'hit' } | { type: 'collision'; other: string; speed: number; parts: string[] } | { type: 'destroyed'; cause: string; speed: number; vertical: number }packages/physics-vehicles/src/aeroplane.ts:92
HitZone type
type HitZone = 'engine' | 'wing' | 'tail' | 'crew' | 'fuel' | 'fuselage'packages/physics-vehicles/src/weapons.ts:39
Status type
type Status = 'ok' | 'damaged' | 'destroyed'packages/physics-vehicles/src/aeroplane.ts:98
VesselEventType type
type VesselEventType = 'breach' | 'flooded' | 'crushed' | 'surfaced' | 'submerged' | 'capsized'packages/physics-vehicles/src/vessel.ts:150
Constants
AIRSHIP_ESTIMATES const
const AIRSHIP_ESTIMATES: { kAxial: number; kLateral: number; kRotation: number; cdCross: number; finAspect: number; finInterference: number; flapEffect: number; finStall: number; finCd0: number; propProfile: number; reverseShare: number; rpmRamp: number; }estimated coefficients, one place
packages/physics-vehicles/src/airship.ts:54
G const
const G: 9.80665A vessel is one rigid body with parts: a hull that displaces liquid (cells against the water surface), ballast tanks, compartments that flood through breaches, gas envelopes, thrusters, control surfaces and sails. It integrates its own six degrees of freedom (the light kernel has no dynamic box and one scalar inertia), reads the water and the air, and reports the readouts a game needs: draft, heel, trim, metacentric height, depth and buoyancy against weight.
Body axes: x to starboard, y up, z to the bow.
packages/physics-vehicles/src/vessel.ts:14
R_UNIVERSAL const
const R_UNIVERSAL: 8.314462618packages/physics-vehicles/src/vessel.ts:15
VEHICLES_DEFAULTS const
const VEHICLES_DEFAULTS: { waterLevel: number; waterDensity: number; wind: Vec3; }Assemblies of capability V: ships, submarines and balloons. A vessel is one body with parts (a hull, ballast tanks, compartments, gas envelopes, thrusters, control surfaces and sails) that read the water and the air and write forces. This capability steps them with the world, moves the scene node that shows each one, and answers the commands a game drives them with.
values (each at world / level / zone / entity scope):
waterLevel height of the water surface, m (0)
waterDensity kg/m³ (1000)
wind wind velocity at all heights, [x, y, z] m/s ([0, 0, 0])
events: vessel:breach, vessel:flooded, vessel:crushed, vessel:surfaced, vessel:submerged, vessel:capsized, each { vessel, part? }.
packages/physics-vehicles/src/index.ts:25