← back to the observatory

Newton's Law of Universal Gravitation

With Softening Kernel

A symbol-by-symbol guide with a concrete worked example

The Equation
F_gravity  = 
G · m₁ · m₂ · r_vec
( + ε² ) ^(3/2)

Each colored symbol is explained below

What each symbol means

Classic gravity pulls two masses together based on how heavy they are and how far apart they sit. The softening kernel (ε) is a modification that prevents simulation singularity.

Negative sign (out front)
Attractive direction
Gravity always pulls inward — toward the other mass — never pushes away. The minus sign encodes this: the force acts in the opposite direction to r̂ (which points away from the source). Without it, the formula would describe repulsion.
Notation — flips the vector direction
G
Capital G
Gravitational constant
A fixed number set by nature — the same everywhere in the universe. It's very small, which is why gravity is the weakest of the four fundamental forces. G = 6.674 × 10⁻¹¹. In simulations, G = 1 for convenience.
6.674 × 10⁻¹¹ N·m²/kg²
m₁
m subscript 1
Mass of the first body
The mass of one of the two objects. Gravity scales with both masses equally — double the mass of either object and the force doubles. The subscript 1 just distinguishes it from the second body.
kg (kilograms)
m₂
m subscript 2
Mass of the second body
The mass of the other object. Newton's third law: m₁ pulls m₂ with the same force that m₂ pulls m₁ — they feel equal and opposite forces regardless of whether one is a planet and the other a pebble.
kg (kilograms)
r_vec
r_vec — separation vector
Direction and distance combined
The vector pointing from m₁ to m₂ — it carries both direction and distance. Because it has units of meters, the formula works out dimensionally: G·m₁·m₂ has units N·m², dividing by (r²+ε²)^(3/2) in m³ gives N·m, and the remaining meter from r_vec cancels to leave Newtons. The −G·m₁·m₂ part controls how strongly; r_vec supplies which way and how far.
m (meters) — a vector, not a unit vector
r squared
Separation distance squared
The actual distance between the two masses, squared. This is the famous inverse-square law: double the distance and gravity drops to a quarter; triple it and gravity drops to a ninth. r is always a positive scalar (plain number, not a vector).
m² (meters squared)
ε²
epsilon squared
Softening length (squared)
The softening parameter — a small constant add to prevent singularity. In pure Newtonian gravity, force → infinity as r → 0 (two objects at the exact same point). ε² puts a floor on the denominator so the force stays finite and the simulation doesn't fail catastrophically.
m² (meters squared) — ε is arbitrary
Reading the notation

Three pieces of notation in this formula are worth unpacking separately.

Notation decoder

r̂ (r-hat) Hat notation always means "unit vector" — same direction as r_vec, but rescaled to length 1. Used in the diagram and direction checks. r̂ = r_vec / |r_vec|. Note: the formula uses r_vec, not r̂, so that the meters in r_vec cancel the m³ denominator and the result is in Newtons.
(r² + ε²)^(3/2) The softened denominator. Without ε this would be r³ (since r² to the power 3/2 = r³). Adding ε² inside the brackets before raising to 3/2 blends the true distance with a minimum safe floor.
^(3/2) Power of 3/2 — equivalent to "square root of the cube": (r²+ε²)^(3/2) = √[(r²+ε²)³]. Why 3/2? When ε=0 this recovers r³ in the denominator, which — combined with r_vec in the numerator — gives the classic 1/r² force law: r_vec/r³ = r̂/r².
−G·m₁·m₂·r_vec The numerator — a vector quantity (direction and magnitude from r_vec, scaled by masses and G). Dividing a vector by a scalar just scales its length, so F_gravity is also a vector pointing from m₂ toward m₁.

Why the softening kernel exists

In Newton's original formula the denominator is just r² (or equivalently r³ when combined with the unit vector). This is physically correct for real point masses — but in simulations, particles can drift to nearly the same position, making r ≈ 0 and the force astronomically large. One timestep later the entire simulation has exploded to infinity (this is sometimes referred to as a singularity).

Adding ε² inside the bracket before the exponent ensures the denominator never falls below ε³. The force is now bounded. Choose ε small (e.g. 0.01 × typical particle spacing) and the physics is accurate everywhere except at extremely close range.

Without softening (ε = 0)

As r → 0, force → ∞. Two nearby particles accelerate to impossible speeds. Simulation diverges. All particles vanish to infinity in one step.

With softening (ε > 0)

As r → 0, force → 0. The r_vec in the numerator goes to zero faster than the denominator approaches ε³, so the force tapers smoothly to zero at contact. Particles survive close encounters. Long-range gravity is essentially unchanged.

Anatomy of the formula — what each part contributes

m₁ 1 × 10¹² kg m₂ 5 × 10¹¹ kg r = 50 m −r̂ (toward m₁) ε = 2 m (softening floor) F_gravity

m₂ feels a force pulling it toward m₁. The yellow arrow shows the force direction (opposite to r_vec). Distance r goes into the denominator; ε adds the safety floor.

Worked example — two asteroids in a simulation

We want the gravitational force that asteroid 2 feels from asteroid 1.

Given:   G = 6.674×10⁻¹¹  |  m₁ = 1×10¹² kg  |  m₂ = 5×10¹¹ kg
                 positions: body 1 at (0, 0)  |  body 2 at (40, 30) meters  |  ε = 2 m

1
Find the separation vector and distance r
Subtract the positions to get the vector pointing from m₁ to m₂. Then find its length (r) using Pythagoras.
r_vector = pos₂ − pos₁ = (40, 30) − (0, 0) = (40, 30)

r = |r_vector| = √(40² + 30²)
= √(1600 + 900)
= √2500 = 50 m
💡 The separation vector (40, 30) tells us both the distance (50 m) and the direction. We'll use both pieces separately in the next steps.
2
Compute the unit vector r̂ — for direction checking
Divide each component of the separation vector by r to get a direction-only vector of length 1. We use this to verify the force direction at the end, but the formula uses r_vec directly.
r̂ = r_vector / r
= (40, 30) / 50
= (0.8, 0.6)

Check: √(0.8² + 0.6²) = √(0.64+0.36) = √1.0 = 1 ✓
💡 r̂ carries direction only (length = 1). The formula uses r_vec — not r̂ — because r_vec's units of meters are needed to make the overall result come out in Newtons.
3
Compute the numerator — G · m₁ · m₂
Multiply the three scalars together. This is the "strength" before we account for distance.
G · m₁ · m₂
= 6.674×10⁻¹¹ × 1×10¹² × 5×10¹¹
= 6.674×10⁻¹¹ × 5×10²³
= 3.337×10¹³ N·m²
4
Compute the softened denominator — (r² + ε²)^(3/2)
First add r² and ε² inside the bracket, then raise the whole thing to the power 3/2.
r² = 50² = 2500
ε² = = 4

(r² + ε²) = 2500 + 4 = 2504

(2504)^(3/2) = √(2504³)
= √(15,700,096,000)
125,300 m³
💡 Compare: without softening the denominator would be 50³ = 125,000. With ε = 2 the denominator is 125,300 — barely different at this distance. Softening only matters when r is tiny (close to ε).
5
Divide numerator by denominator — intermediate scalar
Dividing G·m₁·m₂ by the softened denominator gives an intermediate value with units N/m. We multiply by r_vec in the next step to get the final force in Newtons.
intermediate = G·m₁·m₂ / denominator
= 3.337×10¹³ / 125,300
2.663×10⁸ N/m
6
Apply direction — multiply by −r_vec
Multiply the intermediate scalar by −r_vec to get the final force vector. Using r_vec (not r̂) provides the meter factor that makes the units work out to Newtons. The minus sign flips the direction from "away from m₁" to "toward m₁".
F_gravity = −(intermediate) × r_vec
= −2.663×10⁸ × (40, 30)

F_x = −2.663×10⁸ × 40 = −1.065×10¹⁰ N
F_y = −2.663×10⁸ × 30 = −7.990×10⁹ N

F_gravity ≈ (−1.07×10¹⁰, −7.99×10⁹) N
💡 Both components are negative because m₂ is northeast of m₁ — the force pulls m₂ back southwest toward m₁. The direction is exactly opposite to r_vec, as expected for attraction. The force magnitude |F| = √(1.065² + 0.799²) × 10¹⁰ ≈ 1.33×10¹⁰ N.
How ε changes the result at different distances

Using our same two masses (G·m₁·m₂ = 3.337×10¹³), here's how the force magnitude varies with r, with and without softening (ε = 2 m). Force magnitude = G·m₁·m₂·r / (r²+ε²)^(3/2) with softening; G·m₁·m₂/r² without.

Distance r Without softening (G·m₁·m₂/r²) With softening (G·m₁·m₂·r/(r²+ε²)^(3/2)) Difference
50 m (far) 1.335×10¹⁰ N 1.332×10¹⁰ N ~0.24% — negligible
10 m (medium) 3.337×10¹¹ N 3.146×10¹¹ N ~6% — noticeable
2 m (= ε) 8.342×10¹² N 2.950×10¹² N ~2.8× smaller — significant
0.1 m (very close) 3.337×10¹⁵ N 4.156×10¹¹ N ~8,000× smaller — saves the sim
Our two asteroids at r = 50 m:
F ≈ (−1.07×10¹⁰, −7.99×10⁹) N
pulling m₂ back toward m₁ (southwest) — magnitude ≈ 1.33×10¹⁰ N
"Pull the two masses toward each other with a strength
proportional to both their masses and to G,
falling off with the square of their distance —
but capped by ε so force stays finite no matter how close they get."