Mobjects

This module provides custom Mobject subclasses that extend Manim’s built-in primitives with additional convenience features such as Chinese formula support, labelled dots, lines paired with formulas, and geometric construction helpers.

Inheritance diagram of manim_extensions.mobjects

class manim_extensions.mobjects.ChineseMathTex(*texts, font='Noto Serif CJK SC', tex_to_color_map={}, **kwargs)[source]

Bases: MathTex

A MathTex subclass that supports Chinese characters.

Automatically wraps Chinese characters in \text{} and configures xelatex with the xeCJK package so that CJK fonts are rendered correctly.

Inheritance diagram of manim_extensions.mobjects.ChineseMathTex

Parameters:
  • *texts (str) – LaTeX text strings to render.

  • font (str) – Name of the Chinese font to use. Defaults to "SimSun".

  • tex_to_color_map (dict) – Mapping from text substrings to colours. Defaults to {}.

  • **kwargs – Additional keyword arguments forwarded to MathTex.

Examples

Example: ChineseMathTexDocExample

../_images/ChineseMathTexDocExample-1.png
from manim import *
from manim_extensions import ChineseMathTex

class ChineseMathTexDocExample(Scene):
    def construct(self):
        formula = ChineseMathTex(
            r"\frac{1}{2} + \text{hello} = x",
            tex_to_color_map={r"\text{hello}": RED},
        )
        self.add(formula)
from manim import *
from manim_extensions import ChineseMathTex

class ChineseMathTexDocExample(Scene):
    def construct(self):
        formula = ChineseMathTex(
            r"\frac{1}{2} + \text{hello} = x",
            tex_to_color_map={r"\text{hello}": RED},
        )
        self.add(formula)

__init__(*texts, font='Noto Serif CJK SC', tex_to_color_map={}, **kwargs)[source]
class manim_extensions.mobjects.LabelDot(dot_label, dot_pos, label_pos=array([0., -1., 0.]), buff=0.1, **kwargs)[source]

Bases: VGroup

A dot with a MathTex label.

Creates a Dot at the given position and places a MathTex label next to it.

Inheritance diagram of manim_extensions.mobjects.LabelDot

Parameters:
  • dot_label (str) – Text content of the label.

  • dot_pos (ndarray) – Position of the dot.

  • label_pos (ndarray) – Direction of the label relative to the dot. Defaults to DOWN.

  • buff (float) – Buffer between the label and the dot. Defaults to 0.1.

  • **kwargs – Additional keyword arguments forwarded to VGroup.

dot

The underlying dot mobject.

Type:

Dot

dot_pos

The position of the dot.

Type:

numpy.ndarray

Examples

Example: LabelDotDocExample

../_images/LabelDotDocExample-1.png
from manim import *

from manim_extensions import LabelDot

class LabelDotDocExample(Scene):
    def construct(self):
        dot = LabelDot("A", [0, 0, 0], label_pos=UP, buff=0.2)
        self.add(dot)
from manim import *
from manim_extensions import LabelDot

class LabelDotDocExample(Scene):
    def construct(self):
        dot = LabelDot("A", [0, 0, 0], label_pos=UP, buff=0.2)
        self.add(dot)

__init__(dot_label, dot_pos, label_pos=array([0., -1., 0.]), buff=0.1, **kwargs)[source]
get_center()[source]

Return the center of the underlying dot.

Examples

Return type:

GenericAlias[double]

get_boundary_point(direction)[source]

Return the center of the underlying dot (boundary approximation).

Examples

Return type:

GenericAlias[double]

class manim_extensions.mobjects.MathTexLine(formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]

Bases: VGroup

A line segment paired with a MathTex formula.

Creates a Line and places a MathTex formula next to it in the specified direction.

Inheritance diagram of manim_extensions.mobjects.MathTexLine

Parameters:
  • formula (MathTex) – The formula to place beside the line.

  • direction (ndarray) – Direction of the formula relative to the line. Defaults to UP.

  • buff (float) – Buffer between the formula and the line. Defaults to 0.5.

  • **kwargs – Additional keyword arguments forwarded to Line.

Examples

Example: MathTexLineDocExample

../_images/MathTexLineDocExample-1.png
from manim import *

from manim_extensions import MathTexLine

class MathTexLineDocExample(Scene):
    def construct(self):
        line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
        self.add(line)
from manim import *
from manim_extensions import MathTexLine

class MathTexLineDocExample(Scene):
    def construct(self):
        line = MathTexLine(MathTex("y = x"), direction=UP, color=BLUE)
        self.add(line)

__init__(formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]
class manim_extensions.mobjects.MathTexBrace(target, formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]

Bases: VGroup

A brace with a MathTex formula.

Creates a Brace around a target mobject and places a MathTex formula next to the brace.

Inheritance diagram of manim_extensions.mobjects.MathTexBrace

Parameters:
  • target (Mobject) – The mobject to be braced (e.g. a line, rectangle, etc.).

  • formula (MathTex) – The formula to place beside the brace.

  • direction (ndarray) – Direction of the brace and formula relative to the target. Defaults to UP.

  • buff (float) – Buffer between the formula and the brace. Defaults to 0.5.

  • **kwargs – Additional keyword arguments forwarded to Brace.

Examples

Example: MathTexBraceDocExample

../_images/MathTexBraceDocExample-1.png
from manim import *

from manim_extensions import MathTexBrace

class MathTexBraceDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 2, RIGHT * 2)
        brace = MathTexBrace(line, MathTex(r"\Delta x"), direction=UP)
        self.add(line, brace)
from manim import *
from manim_extensions import MathTexBrace

class MathTexBraceDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 2, RIGHT * 2)
        brace = MathTexBrace(line, MathTex(r"\Delta x"), direction=UP)
        self.add(line, brace)

__init__(target, formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]
class manim_extensions.mobjects.MathTexDoublearrow(formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]

Bases: VGroup

A double arrow with a MathTex formula.

Creates a DoubleArrow and places a MathTex formula next to it in the specified direction.

Inheritance diagram of manim_extensions.mobjects.MathTexDoublearrow

Parameters:
  • formula (MathTex) – The formula to place beside the double arrow.

  • direction (ndarray) – Direction of the formula relative to the double arrow. Defaults to UP.

  • buff (float) – Buffer between the formula and the double arrow. Defaults to 0.5.

  • **kwargs – Additional keyword arguments forwarded to DoubleArrow.

Examples

Example: MathTexDoublearrowDocExample

../_images/MathTexDoublearrowDocExample-1.png
from manim import *

from manim_extensions import MathTexDoublearrow

class MathTexDoublearrowDocExample(Scene):
    def construct(self):
        arrow = MathTexDoublearrow(MathTex(r"\Leftrightarrow"), direction=UP)
        self.add(arrow)
from manim import *
from manim_extensions import MathTexDoublearrow

class MathTexDoublearrowDocExample(Scene):
    def construct(self):
        arrow = MathTexDoublearrow(MathTex(r"\Leftrightarrow"), direction=UP)
        self.add(arrow)

__init__(formula, direction=array([0., 1., 0.]), buff=0.5, **kwargs)[source]
class manim_extensions.mobjects.PerpendicularLine(point, line, **kwargs)[source]

Bases: Line

A perpendicular line segment from a point to a given line.

Computes the foot of the perpendicular from point onto line and creates a Line from point to that foot.

Inheritance diagram of manim_extensions.mobjects.PerpendicularLine

Parameters:
  • point (Union[ndarray, tuple, list, Mobject]) – The point from which the perpendicular is dropped. If an Mobject is given, its centre is used.

  • line (Line) – The target line.

  • **kwargs (Any) – Additional keyword arguments forwarded to Line.

point

The 3‑D point from which the perpendicular is drawn.

Type:

numpy.ndarray

target_line

The line onto which the perpendicular is dropped.

Type:

Line

foot

The foot of the perpendicular on target_line.

Type:

numpy.ndarray

Examples

Example: PerpendicularLineDocExample

../_images/PerpendicularLineDocExample-1.png
from manim import *

from manim_extensions import PerpendicularLine

class PerpendicularLineDocExample(Scene):
    def construct(self):
        base = Line(LEFT * 3, RIGHT * 3)
        perp = PerpendicularLine(UP * 1.5, base, color=YELLOW)
        self.add(base, perp)
from manim import *
from manim_extensions import PerpendicularLine

class PerpendicularLineDocExample(Scene):
    def construct(self):
        base = Line(LEFT * 3, RIGHT * 3)
        perp = PerpendicularLine(UP * 1.5, base, color=YELLOW)
        self.add(base, perp)

__init__(point, line, **kwargs)[source]
class manim_extensions.mobjects.ExtendedLine(line, extend_distance, **kwargs)[source]

Bases: Line

A line segment extended at both ends.

Takes an existing Line and extends it by extend_distance along its original direction on both sides. The style of the original line is preserved.

Inheritance diagram of manim_extensions.mobjects.ExtendedLine

Parameters:
  • line (Line) – The original line segment to extend.

  • extend_distance (float) – Distance to extend at each end.

  • **kwargs – Additional keyword arguments forwarded to Line.

Examples

Example: ExtendedLineDocExample

../_images/ExtendedLineDocExample-1.png
from manim import *

from manim_extensions import ExtendedLine

class ExtendedLineDocExample(Scene):
    def construct(self):
        base = Line(LEFT, RIGHT, color=BLUE)
        extended = ExtendedLine(base, extend_distance=1.0, color=RED)
        self.add(base, extended)
from manim import *
from manim_extensions import ExtendedLine

class ExtendedLineDocExample(Scene):
    def construct(self):
        base = Line(LEFT, RIGHT, color=BLUE)
        extended = ExtendedLine(base, extend_distance=1.0, color=RED)
        self.add(base, extended)

__init__(line, extend_distance, **kwargs)[source]
class manim_extensions.mobjects.PerpendicularSign(line1, line2, length=0.25, corner_direction=None, **kwargs)[source]

Bases: VGroup

A right‑angle (perpendicular) sign.

Draws a small L‑shaped corner at the intersection of two lines to indicate that they are perpendicular. The sign consists of two short line segments.

Inheritance diagram of manim_extensions.mobjects.PerpendicularSign

Parameters:
  • line1 (Line) – The first line.

  • line2 (Line) – The second line.

  • length (float) – Length of each leg of the corner. Defaults to 0.25.

  • corner_direction (Union[ndarray, tuple, list, None]) – A direction vector that selects on which side of the intersection the corner is drawn. If None (the default), the side that points toward the nearer endpoints of the two lines is chosen automatically.

  • **kwargs (Any) – Additional keyword arguments forwarded to VGroup.

intersection

The 3‑D intersection point of the two lines. If the lines are parallel this attribute is not set.

Type:

numpy.ndarray

Examples

Example: PerpendicularSignDocExample

../_images/PerpendicularSignDocExample-1.png
from manim import *

from manim_extensions import PerpendicularLine, PerpendicularSign

class PerpendicularSignDocExample(Scene):
    def construct(self):
        base = Line(LEFT * 3, RIGHT * 3)
        perp = PerpendicularLine(UP * 1.5, base, color=YELLOW)
        sign = PerpendicularSign(base, perp, length=0.25, color=WHITE)
        self.add(base, perp, sign)
from manim import *
from manim_extensions import PerpendicularLine, PerpendicularSign

class PerpendicularSignDocExample(Scene):
    def construct(self):
        base = Line(LEFT * 3, RIGHT * 3)
        perp = PerpendicularLine(UP * 1.5, base, color=YELLOW)
        sign = PerpendicularSign(base, perp, length=0.25, color=WHITE)
        self.add(base, perp, sign)

__init__(line1, line2, length=0.25, corner_direction=None, **kwargs)[source]