Skip to content

Commit bef8302

Browse files
jbalperthickmott99behacklpre-commit-ci[bot]Darylgolden
authored
Created a more accessible way to create Angles with line.py angle function - Angle.from_three_points (#2684)
* fixed style * fixed style * fixed formatting * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fixed formatting comments and added tests that can visualize graphic better * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * added additional example * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * Update manim/mobject/geometry/line.py Co-authored-by: Benjamin Hackl <[email protected]> * example has been changed! * fixed name change * reverted change to not include Vgroup Co-authored-by: hickmott99 <[email protected]> Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Darylgolden <[email protected]>
1 parent 584d802 commit bef8302

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

manim/mobject/geometry/line.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,46 @@ def construct(self):
10151015
return self.angle_value / DEGREES
10161016
return self.angle_value
10171017

1018+
@staticmethod
1019+
def from_three_points(
1020+
A: np.ndarray, B: np.ndarray, C: np.ndarray, **kwargs
1021+
) -> Angle:
1022+
"""The angle between the lines AB and BC.
1023+
1024+
This constructs the angle :math:`\angle ABC`.
1025+
1026+
Parameters
1027+
----------
1028+
A
1029+
The endpoint of the first angle leg
1030+
B
1031+
The vertex of the angle
1032+
C
1033+
The endpoint of the second angle leg
1034+
1035+
**kwargs
1036+
Further keyword arguments are passed to :class:`.Angle`
1037+
1038+
Returns
1039+
-------
1040+
The Angle calculated from the three points
1041+
1042+
Angle(line1, line2, radius=0.5, quadrant=(-1,1), stroke_width=8),
1043+
Angle(line1, line2, radius=0.7, quadrant=(-1,-1), color=RED, other_angle=True),
1044+
1045+
Examples
1046+
--------
1047+
.. manim:: AngleFromThreePointsExample
1048+
:save_last_frame:
1049+
1050+
class AngleFromThreePointsExample(Scene):
1051+
def construct(self):
1052+
sample_angle = Angle.from_three_points(UP, ORIGIN, LEFT)
1053+
red_angle = Angle.from_three_points(LEFT + UP, ORIGIN, RIGHT, radius=.8, quadrant=(-1,-1), color=RED, stroke_width=8, other_angle=True)
1054+
self.add(red_angle, sample_angle)
1055+
"""
1056+
return Angle(Line(B, A), Line(B, C), **kwargs)
1057+
10181058

10191059
class RightAngle(Angle):
10201060
"""An elbow-type mobject representing a right angle between two lines.
Binary file not shown.

tests/test_graphical_units/test_geometry.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,35 @@ def test_Angle(scene):
168168
scene.add(a)
169169

170170

171+
@frames_comparison
172+
def test_three_points_Angle(scene):
173+
# acute angle
174+
acute = Angle.from_three_points(
175+
np.array([10, 0, 0]), np.array([0, 0, 0]), np.array([10, 10, 0])
176+
)
177+
# obtuse angle
178+
obtuse = Angle.from_three_points(
179+
np.array([-10, 1, 0]), np.array([0, 0, 0]), np.array([10, 1, 0])
180+
)
181+
# quadrant 1 angle
182+
q1 = Angle.from_three_points(
183+
np.array([10, 10, 0]), np.array([0, 0, 0]), np.array([10, 1, 0])
184+
)
185+
# quadrant 2 angle
186+
q2 = Angle.from_three_points(
187+
np.array([-10, 1, 0]), np.array([0, 0, 0]), np.array([-1, 10, 0])
188+
)
189+
# quadrant 3 angle
190+
q3 = Angle.from_three_points(
191+
np.array([-10, -1, 0]), np.array([0, 0, 0]), np.array([-1, -10, 0])
192+
)
193+
# quadrant 4 angle
194+
q4 = Angle.from_three_points(
195+
np.array([10, -1, 0]), np.array([0, 0, 0]), np.array([1, -10, 0])
196+
)
197+
scene.add(VGroup(acute, obtuse, q1, q2, q3, q4).arrange(RIGHT))
198+
199+
171200
@frames_comparison
172201
def test_RightAngle(scene):
173202
l1 = Line(ORIGIN, RIGHT)

0 commit comments

Comments
 (0)