Documentation / @interstellar-tools/equations / forceOn1By2
Function: forceOn1By2()
ts
function forceOn1By2(
m1: number,
m2: number,
r1: Vector3DTupleType,
r2: Vector3DTupleType,
G?: number
): Vector3DTupleType;Defined in: gravity/force-on1-by2.ts:90
Gravitational force vector on body 1 due to body 2 (newtons, N).
Definitions
Newton's law (vector form)
Magnitude & Components
Newton's 3rd law (context)
Units
- Inputs: masses in kg, positions in m, (
) in m³·kg⁻¹·s⁻². - Output: force vector in newtons (N).
INFO
- The returned vector points from body 1 toward body 2 (i.e., along ($ \hat{\mathbf r} $)).
- Internally delegates to
gravitationalForce(m1, m2, r1, r2, G)and returns its direction-scaled magnitude as a 3-tuple. - For acceleration instead of force, use
accelerationOn1By2or compute ($ \mathbf a=\mathbf F/m_1 $).
Invariants (within FP tolerance)
||F|| = G*m1*m2/r²F = ||F|| * r̂
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
m1 | number | undefined | Mass of body 1 (kg). |
m2 | number | undefined | Mass of body 2 (kg). |
r1 | Vector3DTupleType | undefined | Position of body 1 [x, y, z] in meters. |
r2 | Vector3DTupleType | undefined | Position of body 2 [x, y, z] in meters. |
G? | number | G_SI | Gravitational constant. |
Returns
Force on body 1 due to body 2, in newtons [Fx, Fy, Fz].
Throws
Error Propagated from gravitationalForce if inputs are invalid (non-finite/negative masses, coincident positions (
Examples
ts
// Earth–Sun at ~1 AU (force on Earth due to Sun)
const mEarth = 5.972e24; // kg
const mSun = 1.9885e30; // kg
const rEarth: [number, number, number] = [0, 0, 0];
const rSun: [number, number, number] = [1.495978707e11, 0, 0]; // m
const F = forceOn1By2(mEarth, mSun, rEarth, rSun); // N
const Fmag = Math.hypot(F[0], F[1], F[2]); // ≈ 3.54e22 Nts
// Derive acceleration from the returned force: a = F / m1
const a: [number, number, number] = [
F[0] / mEarth,
F[1] / mEarth,
F[2] / mEarth
]; // m/s²See
https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation