Skip to content

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

r=r2−r1,r=‖r‖,r^=rr

Newton's law (vector form)

F1←2=Gm1m2r2r^

Magnitude & Components

‖F‖=Gm1m2r2,F=⟨Fx,Fy,Fz⟩=‖F‖r^Fx=‖F‖r^x,Fy=‖F‖r^y,Fz=‖F‖r^z

Newton's 3rd law (context)

F1←2=−F2←1

Units

  • Inputs: masses in kg, positions in m, (G) 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 accelerationOn1By2 or compute ($ \mathbf a=\mathbf F/m_1 $).

Invariants (within FP tolerance)

  • ||F|| = G*m1*m2/r²
  • F = ||F|| * r̂

Parameters ​

ParameterTypeDefault valueDescription
m1numberundefinedMass of body 1 (kg).
m2numberundefinedMass of body 2 (kg).
r1Vector3DTupleTypeundefinedPosition of body 1 [x, y, z] in meters.
r2Vector3DTupleTypeundefinedPosition of body 2 [x, y, z] in meters.
G?numberG_SIGravitational constant.

Returns ​

Vector3DTupleType

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 (r=0), or non-positive (G)).

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 N
ts
// 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