A community-maintained Python framework for creating mathematical animations.
fix: correct Circle.point_at_angle calculation (#4236) (#4438)
Swarnlata73eeacb880e3
diff --git a/manim/mobject/geometry/arc.py b/manim/mobject/geometry/arc.pyindex 44485761b..7cedcfce4 100644--- a/manim/mobject/geometry/arc.py+++ b/manim/mobject/geometry/arc.py@@ -734,8 +734,7 @@ class Circle(Arc):self.add(circle, s1, s2)"""- start_angle = angle_of_vector(self.points[0] - self.get_center())- proportion = (angle - start_angle) / TAU+ proportion = angle / TAUproportion -= np.floor(proportion)return self.point_from_proportion(proportion)diff --git a/tests/module/mobject/geometry/test_unit_geometry.py b/tests/module/mobject/geometry/test_unit_geometry.pyindex 15c4acd2b..2de94a3b0 100644--- a/tests/module/mobject/geometry/test_unit_geometry.py+++ b/tests/module/mobject/geometry/test_unit_geometry.py@@ -202,3 +202,51 @@ def test_line_with_buff_and_path_arc():])np.testing.assert_allclose(line.points, expected_points)+++def test_Circle_point_at_angle():+ from manim import TAU++ # Test basic angles+ circle = Circle(radius=1.0)+ start_point = circle.points[0].copy()++ # Angle 0 should return start point+ p0 = circle.point_at_angle(0)+ np.testing.assert_array_almost_equal(p0, start_point, decimal=5)++ # Angle π/2 should return point 90° along arc+ p90 = circle.point_at_angle(TAU / 4)+ # Verify it's approximately at top of circle+ assert p90[1] > 0.9 # Y coordinate close to 1++ # Angle π should return point opposite to start+ p180 = circle.point_at_angle(TAU / 2)+ # Verify it's opposite to start point+ np.testing.assert_array_almost_equal(p180[:2], -start_point[:2], decimal=5)++ # Angle beyond 2π should wrap around+ p720 = circle.point_at_angle(2 * TAU)+ np.testing.assert_array_almost_equal(p720[:2], start_point[:2], decimal=5)++ # Negative angles should work+ p_neg = circle.point_at_angle(-TAU / 4)+ # Should be same as 3/4 TAU+ p270 = circle.point_at_angle(3 * TAU / 4)+ np.testing.assert_array_almost_equal(p_neg, p270, decimal=5)++ # Test with rotated circle+ rotated_circle = Circle(radius=1.0).rotate(TAU / 8)+ rotated_start = rotated_circle.points[0].copy()++ # Angle 0 should still return start point after rotation+ p_rotated_0 = rotated_circle.point_at_angle(0)+ np.testing.assert_array_almost_equal(p_rotated_0, rotated_start, decimal=5)++ # Test with reflected circle+ reflected_circle = Circle(radius=1.0).flip()+ reflected_start = reflected_circle.points[0].copy()++ # Angle 0 should return start point even after reflection+ p_reflected_0 = reflected_circle.point_at_angle(0)+ np.testing.assert_array_almost_equal(p_reflected_0, reflected_start, decimal=5)