Skip to content

physics: forces and torques at a point (O10) - #1172

Merged
transfix merged 8 commits into
masterfrom
feat/physics-force-at
Nov 13, 2026
Merged

transfix merged 8 commits into
masterfrom
feat/physics-force-at

Conversation

@transfix

Copy link
Copy Markdown
Owner

O10 in docs/roadmap/OCEAN-AND-WEATHER-ROADMAP.md (section 7, D1): forces and torques at a point, which a boat's propeller and rudder need.

The calls

  • world::add_force_at(id, force, point) applies a world-frame force (N) at a world-frame point (m). A point off the centre of mass also turns the body by (point − com) × force. The point is in world coordinates, not the floating origin's.
  • world::add_torque(id, torque) applies a world-frame torque (N·m) about the centre of mass.
  • Both work exactly like add_force:
    • every value must be finite, or physics_error is thrown;
    • they act through the next step and add up with each other and with add_force;
    • they wake a sleeping dynamic body and do nothing to a static or kinematic one;
    • an unknown id throws.
  • In Jolt they are BodyInterface::AddForce(id, f, point) and AddTorque, with the default activation as add_force has. The null backend checks the id.
  • They don't reuse the field loads' AddForceAndTorque path, because that path never wakes a sleeping body.
  • world.h and docs/PHYSICS_API.md say that body_state::position is the body's origin, not its centre of mass. The two differ for a convex hull.
  • pycvc binds both: physics_world.add_force_at and add_torque. A None point raises rather than meaning the world origin.

Tests

New cases in physics_world_test:

  • An off-centre force spins the body with the sign and size r × F dt / I predicts, within 0.1 %, and moves its centre at F dt / m. The box sits 3 m from a floating origin at (1000, −500, 0), so a point left in world coordinates instead of engine offsets would show up as a huge torque.
  • A force at the centre of mass gives add_force's state hash, bit for bit, over 120 steps.
  • A torque spins the body without translating it.
  • Both calls wake a sleeping body, and a force at a hull's origin acts as documented.
  • On the null and Jolt backends, NaN and inf throw, as do removed and null ids. Static and kinematic bodies are left bit-for-bit unchanged.
  • test_pycvc_physics.py gains test_forces_at_a_point.

The existing golden hashes are unchanged.

Checked locally (Windows Release)

Before the review fixes:

  • physics_world_test: 45 passed, 2 skipped by design;
  • ctest -R Physics: 127 passed, 2 skipped;
  • pycvc_physics: 139 checks.

After the fixes, the force and torque tests (7/7, including the golden hash) and pycvc again. An independent review found four low-severity issues, all fixed:

  • the None point in pycvc;
  • the origin-versus-centre-of-mass wording;
  • an untested kinematic claim;
  • a stale line in roadmap section 1.2.

This touches docs/PHYSICS_API.md next to O11a's hull row; whichever merges second needs a one-line merge.

world::add_force_at(id, force, point) applies a world-frame force at a
world-frame point, so off the centre of mass it also torques the body;
world::add_torque(id, torque) applies a world-frame torque. Both check
that every value is finite and otherwise act as add_force does: through
the next step only, waking a sleeping body, refusing an unknown id.
New backend_impl calls carry them to Jolt (AddForce at a point, moved to
the engine's floating-origin frame, and AddTorque) and to the null
backend, which checks the id. pycvc binds both.

Tests in physics_world_test check the spin against r x F dt / I, that a
force at the centre of mass gives add_force's state hash, that a torque
does not translate, that both wake a sleeping body, and the refusals.
This is roadmap item D1 of OCEAN-AND-WEATHER-ROADMAP.md.
pycvc's add_force_at refuses a point of None instead of reading it as the
world origin. world.h and PHYSICS_API.md say body_state::position is the
body's origin, not its centre of mass, which differs for a hull or a
vehicle chassis; a new test shows a force at a hull's origin torques it.
ForceAtAndTorqueAreChecked now covers a kinematic body, and roadmap 1.2
marks off-centre forces done.
@transfix
transfix enabled auto-merge (squash) November 12, 2026 08:27
#1159 (O7c) kept the last source sea_surface found in a thread_local, so
the velocity a fluid field reads after a cell's height at the same point
and time did not invert the sideways move again. A thread_local that
keeps state between calls is a static cache, which libcvc's no-singletons
rule forbids (VOLROVER-LIBRARY-PORTS-ROADMAP.md 1.3,
tools/singleton_scan). #1159's release-grpc job, where the scan runs, was
cancelled, so the scan never judged it; the next PR that merges master
would fail that lane on it.

The memo now belongs to the caller:

- sea_surface::source_memo, and height() / velocity() overloads that take
  one. The plain reads share nothing.
- fluid_surface::height_with / velocity_with and a surface_memo the
  caller owns; the defaults ignore it. ocean_surface passes it to the sea.
- field_set::apply keeps one memo per cell, for the cell's height and its
  velocity at the same clipped centre.

The memo is keyed on the point, the time and the digest as before, so
every value is unchanged.
…ocal

The writable-data scan (#1152 made its allowlist a ratchet) refuses process-wide state, and
sea_surface::source kept its last source in a thread_local (O7c, #1159), so every PR's
package-linux release-grpc lane now fails on master's code. The memo moves into the time's
frame, under the mutex the frame already has for its lattice: a frame is the surface at one
time, so the point alone is the key, and as a memo of a pure function it changes no value.
ocean_sea_test (19, pins unchanged) and physics_field_test (22, goldens unchanged) pass; the
exact height-and-velocity pair still costs about what it did (3.8 us, 1.76 us on the lattice).
@transfix

Copy link
Copy Markdown
Owner Author

This branch carried #1193's fix for the sea's source memo, so the writable-data scan would pass. #1193 was closed as superseded by #1181, Joe's pick, so I swapped it:

Until #1181 merges, this PR's diff includes #1181's 10 files. Once #1181 lands they match master, and this PR merges with only its own changes.

The other order is safe too: the branch now carries exactly #1181's code, so whichever merges first, the master that results was tested. Physics and ocean tests pass locally on Windows Release.

@transfix
transfix merged commit 2872b84 into master Nov 13, 2026
30 of 33 checks passed
@transfix
transfix deleted the feat/physics-force-at branch November 13, 2026 10:58
transfix added a commit that referenced this pull request Nov 13, 2026
The one conflict was arigl_web_smoke.mjs. Both sides are kept:
- the /apps/up endpoint, with #1200's ISOLATION headers on its replies as on every response;
- the settle probe reads out and isolated/sab;
- each case runs its before/inject and #1200's isolation check.
The headless-Chrome smoke passes 6/6 here, the picked-file upload included.
Master since then: #1179, #1174, #1196, #1198, #1178, #1157, #1172, #1200.
transfix added a commit that referenced this pull request Nov 13, 2026
…erf/threaded-s1b

#925 starts ws-open's connect and ws-recv's wait where the transport does not block (the browser
without threads), and their callbacks settle the call. Its start paths kept the async_host by
reference and posted through it; here they take the host's finisher (host.make_finisher()) and
settle_started through it, as http_work and uri_fetch_work do: the callbacks answer later, and an
isolated document's group's host may be gone by then.

- net_intrinsics.cpp: the conflict kept this branch's providers by kind; have_ws takes master's
  NetAccess::ws. The any provider's comment says a host's own WebSocket transport must be as
  thread-safe as the compiled backend.
- ariadne_runtime_test: both sides' new L4 cases are kept, plus
  AStartedWebSocketCallKeepsTheHostItStartedOn, the WebSocket twin of
  AStartedRequestKeepsTheHostItStartedOn.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant