You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: rand_vec_spread_deg incorrectly passes degrees to Vec2.from_polar which requires radians #2648
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))
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
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.
Activity
Ibrahim2750mi commentedon Jul 16, 2025
The fix should be this? Or am I missing something?
Raahi-18 commentedon Jul 16, 2025
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.
Barry-Lenhart commentedon Sep 24, 2026
This still reproduces on
development:rand_vec_spread_deg(90, 5, 1.0)returns directions like -23°, -109° and 155°, which also makesemitter_10in theparticle_systemsexample 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: themath.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.Fix rand_vec_spread_deg passing degrees to Vec2.from_polar
Fix rand_vec_spread_deg directions, large GL reads, and pixel test he…