Skip to content

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

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

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