Skip to content

Bug: rand_vec_spread_deg incorrectly passes degrees to Vec2.from_polar which requires radians #2648

Closed

Description

@Tobinaer

The rand_vec_spread_deg function in the Python Arcade library's math module (arcade/math.py) has a bug where it passes angles in degrees to Vec2.from_polar(), which expects angles in radians.

Current, incorrect implementation:

def rand_vec_spread_deg(angle: float, half_angle_spread: float, length: float) -> Point2:
    a = rand_angle_spread_deg(angle, half_angle_spread)
    vel = Vec2.from_polar(a, length)  # Bug: 'a' is in degrees but from_polar expects radians
    return vel.x, vel.y

Vec2.from_polar's source code:

@staticmethod
def from_polar(angle: float, length: float = 1.0) -> Vec2:
    """Create a new vector from the given polar coordinates.

    Args:
      angle: The angle, in radians.  # <-- Expects radians
      length: The desired length
    """
    return Vec2(length * _math.cos(angle), length * _math.sin(angle))

Activity

  1. added theissue type on Apr 18, 2025
  2. Ibrahim2750mi commented on Jul 16, 2025

    @Ibrahim2750mi
    Contributor

    The fix should be this? Or am I missing something?

    def rand_vec_spread_deg(angle: float, half_angle_spread: float, length: float) -> Point2:
        a = rand_angle_spread_deg(angle, half_angle_spread)
        vel = Vec2.from_polar(a*math.pi/180, length)  # Bug: 'a' is in degrees but from_polar expects radians
        return vel.x, vel.y
  3. Raahi-18 commented on Jul 16, 2025

    @Raahi-18

    The fix should be this? Or am I missing something?

    def rand_vec_spread_deg(angle: float, half_angle_spread: float, length: float) -> Point2:
    a = rand_angle_spread_deg(angle, half_angle_spread)
    vel = Vec2.from_polar(a*math.pi/180, length) # Bug: 'a' is in degrees but from_polar expects radians
    return vel.x, vel.y

    To me it seems like that would work, another method could also be using the built in radians() function that's already part of the math library instead of manually converting.

    def rand_vec_spread_deg(angle: float, half_angle_spread: float, length: float) -> Point2:
        a = rand_angle_spread_deg(angle, half_angle_spread)
        vel = Vec2.from_polar(math.radians(a), length)
        return vel.x, vel.y
    
  4. Barry-Lenhart commented on Sep 24, 2026

    @Barry-Lenhart

    This still reproduces on development: rand_vec_spread_deg(90, 5, 1.0) returns directions like -23°, -109° and 155°, which also makes emitter_10 in the particle_systems example spray randomly.

    I see #2755 had this fix (thanks @Raahi-18) but was closed during the math module freeze. Since #2878 was merged recently for rotate_around_point, would a focused PR for this one be welcome? I have one ready: the math.radians() fix, a real unit test replacing the smoke test (it checks the direction stays within the spread), and a CHANGELOG entry.

    I left out rand_vec_magnitude's radians→degrees change (suggested in the #2755 review), since that changes the public API, but I'm happy to include it if you'd like.

  5. added a commit that references this issue on Sep 24, 2026
    42555c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions