an.kinematics.bodies#
Bodies and the points on them: the things a joint joins and a driver moves.
A Body is a rigid rectangle of width by height (its extent)
posed in one frame by (x, y, rotation, scale): the pose point is the
body’s origin, a fraction of the extent ((0.5, 0.5) is the centre,
(0.5, 0.0) the middle of the top edge: where a hanging part is hinged). A
Point on a body is likewise a fraction (u, v) of the extent, so a
caller that knows its landmarks (a bone, a grip, a corner) resolves them to
fractions once and the solver never learns their names. The world is the body
named WORLD: a point on it is an absolute position.
Nothing here imports the scene IR or the stage: a body is four numbers and an
extent, which is what lets this package be described without naming an
animation (# extraction candidate: it becomes its own package when a
second consumer exists).
>>> arm = Body("arm", x=10.0, y=20.0, width=60.0, height=10.0, origin=(0.0, 0.5))
>>> point_world(arm, Point("arm", 1.0, 0.5)) # the far end of an unrotated arm
(70.0, 20.0)
>>> point_world(arm, Point(WORLD, 3.0, 4.0)) # a world point is itself
(3.0, 4.0)
Module Attributes
a |
|
mass = density × area. |
|
the centre of its extent. |
Functions
|
Rotational inertia about the body's pose point (parallel-axis from the extent's centre); |
|
The point's offset from the body's pose point, in the body's own (unrotated) frame, scaled. |
|
The body's mass: density × scaled area; |
|
The point's position in the body's frame of reference (the world, for a body posed in it); a |
Classes
|
A rigid rectangle posed in one frame. |
|
A point on a body, as a fraction of the body's extent. |
- class an.kinematics.bodies.Body(name, x=0.0, y=0.0, rotation=0.0, scale=1.0, width=1.0, height=1.0, origin=(0.5, 0.5), fixed=False, density=1.0, vx=0.0, vy=0.0, omega=0.0)[source]#
Bases:
objectA rigid rectangle posed in one frame.
fixedbodies have infinite mass: joints move everything else around them.vx,vy(the velocity of the extent’s centre) andomegaare what a dynamic solve carries from one frame to the next (zero at rest).densitysets the mass per unit area, spread evenly over the extent, so a limb whose pose point is at its end still swings about it.>>> b = Body("box", width=4.0, height=2.0) >>> round(mass(b), 3), round(inertia(b), 3) (8.0, 13.333)
- an.kinematics.bodies.DFLT_DENSITY: float = 1.0#
mass = density × area. Only the RATIO of masses matters to a solve (a heavy prop drags a light arm), so one unit per square unit of extent is the natural default.
- Type:
Density of a body whose caller gave none
- an.kinematics.bodies.DFLT_ORIGIN: tuple[float, float] = (0.5, 0.5)#
the centre of its extent.
- Type:
Where a body’s pose point sits by default
- class an.kinematics.bodies.Point(body, u, v)[source]#
Bases:
objectA point on a body, as a fraction of the body’s extent.
On
WORLDthe fraction is an absolute position instead.>>> Point("hand", 0.5, 1.0).body 'hand'
- an.kinematics.bodies.WORLD: str = 'world'#
a
Pointon it is an absolute position, and it has infinite mass (a joint to it is a joint to the ground).- Type:
The name of the world body
- an.kinematics.bodies.inertia(body)[source]#
Rotational inertia about the body’s pose point (parallel-axis from the extent’s centre);
inffor a fixed body.>>> round(inertia(Body("b", width=4.0, height=2.0, origin=(0.0, 0.5))), 3) 45.333
- Return type:
- an.kinematics.bodies.local_offset(body, point)[source]#
The point’s offset from the body’s pose point, in the body’s own (unrotated) frame, scaled.
>>> local_offset(Body("b", width=10.0, height=4.0), Point("b", 1.0, 0.0)) (5.0, -2.0)
- an.kinematics.bodies.mass(body)[source]#
The body’s mass: density × scaled area;
inffor a fixed body.>>> mass(Body("b", width=3.0, height=2.0, scale=2.0)) 24.0 >>> mass(Body("b", fixed=True)) inf
- Return type:
- an.kinematics.bodies.point_world(body, point)[source]#
The point’s position in the body’s frame of reference (the world, for a body posed in it); a
WORLDpoint is returned as is.>>> b = Body("b", x=1.0, y=1.0, rotation=math.pi / 2, width=2.0, height=2.0) >>> tuple(round(c, 9) for c in point_world(b, Point("b", 1.0, 0.5))) (1.0, 2.0)