Geometry

This module contains pure geometric calculation functions that operate on Manim primitives (Circle, Line, Arc) without creating any on-screen mobjects. They are useful for analytic geometry tasks inside a Scene.

manim_extensions.geometry.CircleInt(circle1, circle2)[source]

Compute the intersection points of two circles.

Solves the geometric intersection of two circles in the XY‑plane.

Parameters:
  • circle1 (Circle) – The first circle.

  • circle2 (Circle) – The second circle.

Returns:

A tuple (point1, point2) where each point is [x, y, 0] if the circles intersect; otherwise None.

Return type:

Optional[Tuple[list[float], list[float]]]

Examples

Example: CircleIntDocExample

../_images/CircleIntDocExample-1.png
from manim import *
from manim_extensions import CircleInt, LabelDot

class CircleIntDocExample(Scene):
    def construct(self):
        c1 = Circle(radius=2, color=BLUE).shift(LEFT)
        c2 = Circle(radius=2, color=GREEN).shift(RIGHT)
        pts = CircleInt(c1, c2)

        self.add(c1, c2)
        if pts:
            for i, p in enumerate(pts):
                self.add(LabelDot(f"P{i+1}", p, label_pos=UP, buff=0.1))
from manim import *
from manim_extensions import CircleInt, LabelDot

class CircleIntDocExample(Scene):
    def construct(self):
        c1 = Circle(radius=2, color=BLUE).shift(LEFT)
        c2 = Circle(radius=2, color=GREEN).shift(RIGHT)
        pts = CircleInt(c1, c2)

        self.add(c1, c2)
        if pts:
            for i, p in enumerate(pts):
                self.add(LabelDot(f"P{i+1}", p, label_pos=UP, buff=0.1))

manim_extensions.geometry.LineCircleInt(line, circle)[source]

Compute the intersection points of a line segment and a circle.

Only points that lie within the segment parameter range [0, 1] are returned.

Parameters:
  • line (Line) – The line segment.

  • circle (Circle) – The circle.

Returns:

  • Two intersection points as a tuple if the segment cuts the circle twice.

  • A single numpy.ndarray if the segment is tangent to the circle.

  • None if there is no intersection.

Return type:

Union[Tuple[ndarray, ndarray], ndarray, None]

Examples

Example: LineCircleIntDocExample

../_images/LineCircleIntDocExample-1.png
from manim import *
from manim_extensions import LineCircleInt, LabelDot

class LineCircleIntDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 3, RIGHT * 3)
        circle = Circle(radius=1, color=BLUE)
        pts = LineCircleInt(line, circle)

        self.add(line, circle)
        if pts:
            for p in (pts if isinstance(pts, tuple) else [pts]):
                self.add(LabelDot("P", p, label_pos=UP, buff=0.1))
from manim import *
from manim_extensions import LineCircleInt, LabelDot

class LineCircleIntDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 3, RIGHT * 3)
        circle = Circle(radius=1, color=BLUE)
        pts = LineCircleInt(line, circle)

        self.add(line, circle)
        if pts:
            for p in (pts if isinstance(pts, tuple) else [pts]):
                self.add(LabelDot("P", p, label_pos=UP, buff=0.1))

manim_extensions.geometry.LineInt(line1, line2)[source]

Compute the intersection of two (infinitely extended) lines.

Calculates the intersection point in the 2‑D plane. The result is not restricted to the segment endpoints.

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

  • line2 (Line) – The second line.

Returns:

The intersection point [x, y, 0] if the lines are not parallel; otherwise None.

Return type:

Optional[list[float]]

Examples

Example: LineIntDocExample

../_images/LineIntDocExample-1.png
from manim import *
from manim_extensions import LineInt, LabelDot

class LineIntDocExample(Scene):
    def construct(self):
        l1 = Line(LEFT * 3, RIGHT * 3)
        l2 = Line(DOWN * 2, UP * 2)
        p = LineInt(l1, l2)

        self.add(l1, l2)
        if p is not None:
            self.add(LabelDot("P", p, label_pos=UR, buff=0.1))
from manim import *
from manim_extensions import LineInt, LabelDot

class LineIntDocExample(Scene):
    def construct(self):
        l1 = Line(LEFT * 3, RIGHT * 3)
        l2 = Line(DOWN * 2, UP * 2)
        p = LineInt(l1, l2)

        self.add(l1, l2)
        if p is not None:
            self.add(LabelDot("P", p, label_pos=UR, buff=0.1))

manim_extensions.geometry.LineArcInt(line, arc)[source]

Compute the intersection points of a line segment and an arc.

The function checks whether each candidate intersection point actually lies within the angular span of the arc.

Parameters:
  • line (Line) – The line segment.

  • arc (Arc) – The arc.

Returns:

  • A tuple of two points ([x1, y1, 0], [x2, y2, 0]) for two intersections.

  • A single point [x, y, 0] for one intersection.

  • None if there is no intersection.

Return type:

Union[Tuple[list[float], list[float]], list[float], None]

Examples

Example: LineArcIntDocExample

../_images/LineArcIntDocExample-1.png
from manim import *
from manim_extensions import LineArcInt, LabelDot

class LineArcIntDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 2, RIGHT * 2)
        arc = Arc(start_angle=PI/4, angle=PI, radius=1.5, color=BLUE)
        pts = LineArcInt(line, arc)

        self.add(line, arc)
        if pts:
            for p in (pts if isinstance(pts, tuple) else [pts]):
                self.add(LabelDot("P", p, label_pos=UP, buff=0.1))
from manim import *
from manim_extensions import LineArcInt, LabelDot

class LineArcIntDocExample(Scene):
    def construct(self):
        line = Line(LEFT * 2, RIGHT * 2)
        arc = Arc(start_angle=PI/4, angle=PI, radius=1.5, color=BLUE)
        pts = LineArcInt(line, arc)

        self.add(line, arc)
        if pts:
            for p in (pts if isinstance(pts, tuple) else [pts]):
                self.add(LabelDot("P", p, label_pos=UP, buff=0.1))

manim_extensions.geometry.MobjectInt(mob1, mob2)[source]

Compute all intersection points between two mobjects.

Exact formulas are used for Circle, Line and Arc combinations. For arbitrary VMobject instances, the boundary is approximated by a polygonal chain and segment–segment intersections are reported. Groups and VGroup instances are processed recursively over their submobjects.

Parameters:
  • mob1 (Mobject) – First mobject.

  • mob2 (Mobject) – Second mobject.

Returns:

A list of all intersection points (each a 3-D point). Returns an empty list if the objects do not intersect.

Return type:

list

Examples

Example: MobjectIntDocExample

../_images/MobjectIntDocExample-1.png
from manim import *
from manim_extensions import MobjectInt, LabelDot

class MobjectIntDocExample(Scene):
    def construct(self):
        c1 = Circle(radius=1.5, color=BLUE).shift(LEFT)
        c2 = Circle(radius=1.5, color=GREEN).shift(RIGHT)
        line = Line(UP * 2, DOWN * 2, color=RED)

        pts = []
        pts.extend(MobjectInt(c1, c2))
        pts.extend(MobjectInt(c1, line))

        self.add(c1, c2, line)
        for i, p in enumerate(pts):
            self.add(LabelDot(f"P{i+1}", p, label_pos=UP, buff=0.1))
from manim import *
from manim_extensions import MobjectInt, LabelDot

class MobjectIntDocExample(Scene):
    def construct(self):
        c1 = Circle(radius=1.5, color=BLUE).shift(LEFT)
        c2 = Circle(radius=1.5, color=GREEN).shift(RIGHT)
        line = Line(UP * 2, DOWN * 2, color=RED)

        pts = []
        pts.extend(MobjectInt(c1, c2))
        pts.extend(MobjectInt(c1, line))

        self.add(c1, c2, line)
        for i, p in enumerate(pts):
            self.add(LabelDot(f"P{i+1}", p, label_pos=UP, buff=0.1))

manim_extensions.geometry.TangentPoint(p1, p2, line_start, line_end)[source]

Compute the tangent point of a circle through two points and a line.

Given two points p1 and p2 that lie on a circle, and a line segment defined by line_start and line_end, this function finds the point on the line segment where the circle is tangent to the line.

Parameters:
  • p1 (Union[ndarray, tuple, list]) – First point on the circle, as (x, y) or (x, y, z).

  • p2 (Union[ndarray, tuple, list]) – Second point on the circle, as (x, y) or (x, y, z).

  • line_start (Union[ndarray, tuple, list]) – Start point of the line segment, as (x, y) or (x, y, z).

  • line_end (Union[ndarray, tuple, list]) – End point of the line segment, as (x, y) or (x, y, z).

Returns:

The tangent point (x, y, 0) as a numpy.ndarray, or None if no valid tangent point exists.

Return type:

Optional[ndarray]

Examples

Example: TangentPointDocExample

../_images/TangentPointDocExample-1.png
from manim import *
from manim_extensions import TangentPoint, LabelDot

class TangentPointDocExample(Scene):
    def construct(self):
        p1 = Dot([1, 0, 0], color=BLUE)
        p2 = Dot([-1, 0, 0], color=BLUE)
        line = Line([0, -2, 0], [0, 2, 0])
        tangent = TangentPoint(
            p1.get_center(), p2.get_center(),
            line.get_start(), line.get_end(),
        )

        self.add(p1, p2, line)
        if tangent is not None:
            self.add(LabelDot("T", tangent, label_pos=RIGHT, buff=0.1))
from manim import *
from manim_extensions import TangentPoint, LabelDot

class TangentPointDocExample(Scene):
    def construct(self):
        p1 = Dot([1, 0, 0], color=BLUE)
        p2 = Dot([-1, 0, 0], color=BLUE)
        line = Line([0, -2, 0], [0, 2, 0])
        tangent = TangentPoint(
            p1.get_center(), p2.get_center(),
            line.get_start(), line.get_end(),
        )

        self.add(p1, p2, line)
        if tangent is not None:
            self.add(LabelDot("T", tangent, label_pos=RIGHT, buff=0.1))