Skip to content
AI-Ready Docs
/llms.txt/llms-mcp.txt

Physics units and frames ​

Declare the unit system and coordinate frame before you connect a Robot, a CAD proxy and a Physics world. Convert each value once at its boundary. Do not convert Physics output again before you use it as input to the next Physics step.

This page describes the current unreleased branch. See the package overview and robot motion guide for API ownership. The existing Robot unit boundaries remain the Robot facade contract.

Conversion and frame contract ​

Quantity or boundarySource conventionPhysics or destination conventionRequired conversion or declaration
Public Robot turn input/outputDegreesInternal joint calculations use radiansrad = deg * Math.PI / 180. The facade owns this conversion; do not preconvert facade turn inputs.
Public Robot slide input/outputmmInternal Robot joint calculations also use mmNo conversion inside the Robot facade. Convert mm to m when passing length to Physics.
Timed Robot joint limitsJoint units per second, squared second or cubed secondPublic turn limits use degrees; internal turn math uses radians. Slide limits use mm.Match the API layer and each joint's unit. A playback speed is a display setting.
CAD/Viewer length and Robot MMGS lengthmmPhysics length in mMultiply by 1e-3; return Physics display positions to mm with 1e3. Thus 100 mm is 0.1 m.
Robot facade MMGS massgkgMultiply by 1e-3.
Robot facade MMGS inertiag·mm²kg·m²Multiply by 1e-9. State the inertia origin and axis as well.
Robot reported momentN·mmN·mMultiply by 1e-3. Force in N needs no scale change.
Physics time, angles and loadss, rad, N, N·mSame SI units in Physics state and commandsLinear impulse is N·s; angular impulse is N·m·s. Do not treat either as a force or torque.
World frameHost declares right-handed XYZ and CAD orientationPhysics body positions and velocities use that declared world frameThere is no universal CAD up axis. These Physics examples use −Y gravity; Robot statics default to −Z. Rotate vectors explicitly when connecting these frames.
Body rotationLocal-to-world quaternion[x, y, z, w], right-handedThe input and state field is orientationXYZW; identity is [0,0,0,1]. Rigid admission requires norm within 1e-6 of one and normalizes it. cadProxyPose requires norm within 1e-9.
Body axes and angular inputShape dimensions and joint anchors are body-localTorque and angular velocity are world-frame vectorsA capsule's segment uses its local Y axis. axisWorld is a world hinge axis.

| Contact convention | Pair IDs sorted as A, B | normalAtoB points from A to B; pointM is world metres | Positive normal impulse acts along the normal on B and against it on A. tangentImpulseOnBNs is the accumulated world-vector impulse on B, opposite on A. | | Independent pendulum reference inertia | inertia: {about:'com'|'pivot', kgM2} | Moment about the +Z axis through the named origin | For COM input, Physics adds massKg * comDistanceM² once. For pivot input, include this term yourself. | | CAD proxy display | Source points and sourceCenterMM in mm; body centre in m | Viewer translation in mm and unchanged XYZW orientation | translation = 1000 * bodyPositionM - R * sourceCenterMM. Rotate around the source centre, then place that centre at the body position. |

For continuous primitive rotation, angular impulse acts instantaneously at step start. Torque is constant in world coordinates during that step, then expires. The independent reference checks Lend=Lbefore+J+tau*dt and integrated torque work, not final momentum alone. The old full-kick/free G1d PASS remains a historical discrete-map result; the current World integrates continuous torque.

The rigid world's sphere inertia is 2*m*r²/5; a dynamic sphere can declare inertia:{kind:'sphere-isotropic',about:'com',frame:'body-local',kgM2} to supply that scalar. Other admitted primitive bodies use explicit inertia:{kind:'primitive-com',about:'com',frame:'body-local'}. Its box inertia is the local COM diagonal m/3 * [hy²+hz², hx²+hz², hx²+hy²]. Capsule inertia integrates a uniform cylinder and two hemispheres. For radius r, half centreline length h, cylinder mass mc=m*3h/(3h+2r) and cap mass ms=m-mc, its local Y moment is mc*r²/2 + 2*ms*r²/5. The X/Z moments are mc*(r²/4+h²/3) + ms*(2*r²/5+h²+3*h*r/4). These primitive models do not recover exact CAD mass properties. Supply the correct mass and model before interpreting the motion.

For the independent pendulum example, comDistanceM is the pivot-to-COM distance. Its state angle is zero when the COM is below the origin on −Y. Positive angle turns about +Z, and comPositionM = [L*sin(angle), -L*cos(angle), 0]. The pivot equation is I_pivot * angleAcceleration = -massKg * gravityMps2 * L * sin(angle). A COM moment and a pivot moment cannot be substituted without the parallel-axis term.

Off-origin CAD proxy example ​

The public adapter admits one selected native Surface from the exact source text and revision. It returns body:RigidBody, collider:Collider and binding:SourceBinding. Add these values to the model's bodies, colliders and sourceBindings arrays. The binding has source revision/digest, occurrence/model IDs, numerical entity references and approximation metadata. Exact source text and native bounds remain with the adapter. They do not enter the numerical World.

The body's input position is proxy.body.initial.positionM; geometry is proxy.collider.geometry. The accepted body state uses orientationXYZW. cadProxyPose reads that state and returns the display pose's rotation, also XYZW. The fixture below has source bounds [20,-30,40] to [120,10,100] mm. Its centre is [70,-10,70] mm. The admitted box half extents are [0.05,0.02,0.03] m. A +0.1 m X offset places its body centre at [0.17,-0.01,0.07] m.

mjs
import { createPhysicsWorld, PhysicsError } from '@barocss/physics';
import { admitCadSurfaceProxy, cadProxyPose } from '@barocss/physics/cad-proxy';
mjs
const source = `@model units_fixture {
  version: 0;
  length-unit: mm;
  @surface #asymmetric_panel {
    type: nurbs;
    degree-u: 1;
    degree-v: 1;
    knots-u: [0,0,1,1];
    knots-v: [0,0,1,1];
    control-points: [[[20,-30,40],[20,-30,100]],[[120,10,40],[120,10,100]]];
    weights: [[1,1],[1,1]];
  }
}`;

Turn the body +90° about Z while keeping that body centre. The literal quarter-turn matrix gives R*[x,y,z] = [-y,x,z], so R*sourceCenterMM = [10,70,70] mm. The display translation is therefore [170,-10,70] - [10,70,70] = [160,-80,0] mm. A translation of [100,0,0] mm alone is correct only for this fixture's identity orientation.

mjs
const proxy = admitCadSurfaceProxy(source, {
  sourceVersion: 0, sourceRevision: 'unitsRev1', modelId: 'units_fixture',
  surfaceId: 'asymmetric_panel', kind: 'dynamic', proxy: 'box',
  massKg: 1, initialOffsetM: [0.1, 0, 0],
});
vectorNear(proxy.sourceCenterMM, [70, -10, 70], 1e-6);
assert.equal(proxy.collider.bodyId, proxy.body.id);
assert.deepEqual(proxy.binding.entityIds, [proxy.body.id, proxy.collider.id]);
assert.equal(proxy.binding.sourceRevision, 'unitsRev1');
assert.match(proxy.binding.sourceDigest, /^sha256:[0-9a-f]{64}$/);
assert.equal(proxy.collider.geometry.kind, 'box');
vectorNear(proxy.collider.geometry.halfExtentsM, [0.05, 0.02, 0.03], 1e-9);
vectorNear(proxy.body.initial.positionM, [0.17, -0.01, 0.07], 1e-9);
const body = { id: proxy.bodyId, positionM: [...proxy.body.initial.positionM],
  orientationXYZW: [0, 0, Math.SQRT1_2, Math.SQRT1_2] };
const pose = cadProxyPose(proxy, body, source, 'unitsRev1');
vectorNear(pose.translation, [160, -80, 0], 1e-6);
// Independent +90° Z matrix: (x,y,z) -> (-y,x,z).
const original = [[20, -30, 40], [20, -30, 100], [120, 10, 40], [120, 10, 100]];
const expected = [[190, -60, 40], [190, -60, 100], [150, 40, 40], [150, 40, 100]];
original.forEach(([x, y, z], i) => {
  const displayed = [-y + pose.translation[0], x + pose.translation[1], z + pose.translation[2]];
  vectorNear(displayed, expected[i], 1e-6);
  vectorNear([displayed[1] + 80, 160 - displayed[0], displayed[2]], original[i], 1e-6);
});

The four expected display points are literal coordinates. The sample uses the quarter-turn matrix and an inverse transform rather than the adapter's quaternion helper to calculate its oracle. It compares admission lengths at 1e-9 m and display/inverse coordinates at 1e-6 mm. The source centre maps to the body centre [170,-10,70] mm under the same transform.

The returned pose is a display transform of the original Surface. It is not a replacement collision mesh. A box proxy uses the Surface control-net AABB with minimum half extent; a sphere encloses that AABB. Keep the returned lossLabel with the simulation record. These source-adapter checks do not establish a compiled CAD consumer, a Viewer frame or exact Surface collision.

Keep the source identity with the pose ​

assertCadProxyCurrent(proxy, currentSource, currentRevision) and cadProxyPose(...) compare the complete source string and the caller revision. A changed string with an unchanged revision still gives STALE_SOURCE. A changed revision with the original string also gives STALE_SOURCE. An unknown or malformed binding is not permission to display a guessed pose.

Keep the last accepted world state and frame after refusal. Re-admit the selected Surface explicitly when the source changes, then let the host replace the world and display binding. Do not silently reuse an old centre or apply the scale conversion twice. The documentation sample checks both stale cases and reuse of the original valid binding without changing retained input.

For the numerical and product evidence boundaries, see Physics verification. For command timing and state retention, see profiles and lifecycle.