VRatchetJoint

Qualified name: manim\_pymunk.constraints.VRatchetJoint

class VRatchetJoint(a_mob, b_mob, phase=0.0, ratchet=1.5707963267948966, indicator_line_class=<class 'manim.mobject.geometry.line.Arrow'>, indicator_line_config={'color': ManimColor('#58C4DD'), 'stroke_width': 2}, indicator_line_length=0.4, connect_line_class=None, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)[source]

Bases: VConstraint

Initializes a Ratchet Joint constraint between two Mobjects.

A Ratchet Joint acts like a rotary pawl, allowing relative rotation only in discrete increments and in one direction. It is perfect for simulating winding mechanisms, clockwork, or unidirectional gears.

Parameters

a_mob

The first Mobject (the base or reference body).

b_mob

The second Mobject (the body subject to the ratchet effect).

phase

The initial angular offset of the ratchet teeth.

ratchet

The angular distance between each “tooth” (in radians). For example, PI/2 means the joint locks at every 90-degree interval.

indicator_line_class

The Manim class used to visualize the current rotation or ratchet direction.

indicator_line_config

Configuration dictionary for the styling of the indicator arrow.

indicator_line_length

The visual length of the indicator line.

connect_line_class

The Manim class used to draw a line between the centers of the two objects. Set to None to disable.

connect_line_config

Configuration dictionary for the styling of the connection line.

Examples

Example: VRatchetJointExample

from manim import *

from manim_pymunk import *

class VRatchetJointExample(SpaceScene):
    def construct(self):
        floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2)

        static_dot1 = Dot(UP * 2)
        static_dot2 = Dot(UP * 2 + RIGHT * 4)

        square_1 = Square().move_to(static_dot1)
        square_2 = Square().move_to(static_dot2)

        constraints = [
            VRatchetJoint(
                square_1,
                square_2,
                phase=PI / 4,
                ratchet=PI,
            ),
            VPinJoint(static_dot1, square_1),
            VPinJoint(static_dot2, square_2),
        ]

        self.add_static_body(floor, static_dot1, static_dot2)
        self.add_dynamic_body(square_1, angular_velocity=PI * 2)
        self.add_dynamic_body(square_2)

        self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2)
        self.add_constraints(*constraints)
        self.wait(3)
from manim_pymunk import *

class VRatchetJointExample(SpaceScene):
    def construct(self):
        floor = Line(LEFT * 10, RIGHT * 10).shift(DOWN * 2)

        static_dot1 = Dot(UP * 2)
        static_dot2 = Dot(UP * 2 + RIGHT * 4)

        square_1 = Square().move_to(static_dot1)
        square_2 = Square().move_to(static_dot2)

        constraints = [
            VRatchetJoint(
                square_1,
                square_2,
                phase=PI / 4,
                ratchet=PI,
            ),
            VPinJoint(static_dot1, square_1),
            VPinJoint(static_dot2, square_2),
        ]

        self.add_static_body(floor, static_dot1, static_dot2)
        self.add_dynamic_body(square_1, angular_velocity=PI * 2)
        self.add_dynamic_body(square_2)

        self.add_shapes_filter(static_dot1, static_dot2, square_1, square_2, group=2)
        self.add_constraints(*constraints)
        self.wait(3)

Methods

install

Installs physical constraints into the Pymunk physical space.

mob_updater

Visual control updater

Attributes

always

Call a method on a mobject every frame.

animate

Used to animate the application of any method of self.

animation_overrides

color

depth

The depth of the mobject.

fill_color

If there are multiple colors (for gradient) this returns the first one

height

The height of the mobject.

n_points_per_curve

sheen_factor

stroke_color

width

The width of the mobject.

__check_data()

Verify the validity of constraint parameters.

_abc_impl = <_abc._abc_data object>
_bezier_t_values: npt.NDArray[float]
_original__init__(a_mob, b_mob, phase=0.0, ratchet=1.5707963267948966, indicator_line_class=<class 'manim.mobject.geometry.line.Arrow'>, indicator_line_config={'color': ManimColor('#58C4DD'), 'stroke_width': 2}, indicator_line_length=0.4, connect_line_class=None, connect_line_config={'color': ManimColor('#F7D96F'), 'stroke_width': 2}, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • a_mob (Mobject)

  • b_mob (Mobject)

  • phase (float)

  • ratchet (float)

  • indicator_line_class (Line | None)

  • indicator_line_config (dict)

  • connect_line_class (Line | None)

  • connect_line_config (dict)

animation_overrides = {}
background_image: Image | str | None
background_stroke_color: ManimColor
background_stroke_opacity: float
background_stroke_width: float
cap_style: CapStyleType
close_new_points: bool
connect_line: VMobject | None
constraint: RatchetJoint | None
install(space)[source]

Installs physical constraints into the Pymunk physical space. This method should be overridden by subclasses to implement the following:

  1. Create Pymunk constraint objects

  2. Initialize the vision component

  3. Add constraints to the physical space

  4. Bind an updater to keep the vision synchronized.

Parameters:

space (Space)

joint_type: LineJointType
make_smooth_after_applying_functions: bool
mob_updater(mob, dt)[source]

Visual control updater

n_points_per_cubic_curve: int
pre_function_handle_to_anchor_scale_factor: float
shade_in_3d: bool
submobjects: list[VMobject]
tolerance_for_point_equality: float
Parameters:
  • a_mob (Mobject)

  • b_mob (Mobject)

  • phase (float)

  • ratchet (float)

  • indicator_line_class (Line | None)

  • indicator_line_config (dict)

  • connect_line_class (Line | None)

  • connect_line_config (dict)