Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Created a more accessible way to create Angles with line.py angle function - Angle.from_three_points (#2684)

Jonathan Alpertbef8302be3fb
diff --git a/manim/mobject/geometry/line.py b/manim/mobject/geometry/line.py
index 76e17cc28..cb8d7188d 100644
--- a/manim/mobject/geometry/line.py
+++ b/manim/mobject/geometry/line.py
@@ -1015,6 +1015,46 @@ class Angle(VMobject, metaclass=ConvertToOpenGL):
return self.angle_value / DEGREES
return self.angle_value
+ @staticmethod
+ def from_three_points(
+ A: np.ndarray, B: np.ndarray, C: np.ndarray, **kwargs
+ ) -> Angle:
+ """The angle between the lines AB and BC.
+
+ This constructs the angle :math:`\angle ABC`.
+
+ Parameters
+ ----------
+ A
+ The endpoint of the first angle leg
+ B
+ The vertex of the angle
+ C
+ The endpoint of the second angle leg
+
+ **kwargs
+ Further keyword arguments are passed to :class:`.Angle`
+
+ Returns
+ -------
+ The Angle calculated from the three points
+
+ Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8),
+ Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),
+
+ Examples
+ --------
+ .. manim:: AngleFromThreePointsExample
+ :save_last_frame:
+
+ class AngleFromThreePointsExample(Scene):
+ def construct(self):
+ sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT)
+ red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True)
+ self.add(red_angle, sample_angle)
+ """
+ return Angle(Line(B, A), Line(B, C), **kwargs)
+
class RightAngle(Angle):
"""An elbow-type mobject representing a right angle between two lines.
diff --git a/tests/test_graphical_units/control_data/geometry/three_points_Angle.npz b/tests/test_graphical_units/control_data/geometry/three_points_Angle.npz
new file mode 100644
index 000000000..a084129e8
Binary files /dev/null and b/tests/test_graphical_units/control_data/geometry/three_points_Angle.npz differ
diff --git a/tests/test_graphical_units/test_geometry.py b/tests/test_graphical_units/test_geometry.py
index 51e6817d7..6f6ab72e1 100644
--- a/tests/test_graphical_units/test_geometry.py
+++ b/tests/test_graphical_units/test_geometry.py
@@ -168,6 +168,35 @@ def test_Angle(scene):
scene.add(a)
+@frames_comparison
+def test_three_points_Angle(scene):
+ # acute angle
+ acute = Angle.from_three_points(
+ np.array([10, 0, 0]), np.array([0, 0, 0]), np.array([10, 10, 0])
+ )
+ # obtuse angle
+ obtuse = Angle.from_three_points(
+ np.array([-10, 1, 0]), np.array([0, 0, 0]), np.array([10, 1, 0])
+ )
+ # quadrant 1 angle
+ q1 = Angle.from_three_points(
+ np.array([10, 10, 0]), np.array([0, 0, 0]), np.array([10, 1, 0])
+ )
+ # quadrant 2 angle
+ q2 = Angle.from_three_points(
+ np.array([-10, 1, 0]), np.array([0, 0, 0]), np.array([-1, 10, 0])
+ )
+ # quadrant 3 angle
+ q3 = Angle.from_three_points(
+ np.array([-10, -1, 0]), np.array([0, 0, 0]), np.array([-1, -10, 0])
+ )
+ # quadrant 4 angle
+ q4 = Angle.from_three_points(
+ np.array([10, -1, 0]), np.array([0, 0, 0]), np.array([1, -10, 0])
+ )
+ scene.add(VGroup(acute, obtuse, q1, q2, q3, q4).arrange(RIGHT))
+
+
@frames_comparison
def test_RightAngle(scene):
l1 = Line(ORIGIN, RIGHT)