diff --git a/arcade/math.py b/arcade/math.py index a35237fca..a32f1c606 100644 --- a/arcade/math.py +++ b/arcade/math.py @@ -421,7 +421,7 @@ def rotate_around_point(source: Point2, target: Point2, angle: float): dx = diff_x * c - diff_y * s dy = diff_x * s + diff_y * c - return target[0] + dx, target[1] + dy + return source[0] + dx, source[1] + dy def get_angle_degrees(x1: float, y1: float, x2: float, y2: float) -> float: diff --git a/tests/unit/test_math.py b/tests/unit/test_math.py index cd2551550..8ef43de8a 100644 --- a/tests/unit/test_math.py +++ b/tests/unit/test_math.py @@ -87,3 +87,16 @@ def test_rand_vec_spread_deg(): def test_rand_vec_magnitude(): """Smoke test""" rand_vec_magnitude(30.5, 3.3, 4.4) + + +def test_rotate_around_point(): + """The result is offset from the rotation center, not from the target.""" + from arcade.math import rotate_around_point + + x, y = rotate_around_point((3.0, 0.0), (5.0, 0.0), 90.0) + assert x == approx(3.0) + assert y == approx(2.0) + + # A full turn and a zero-length radius both leave the target where it is. + assert rotate_around_point((3.0, 0.0), (5.0, 0.0), 360.0) == (5.0, 0.0) + assert rotate_around_point((3.0, 0.0), (3.0, 0.0), 90.0) == (3.0, 0.0)