-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Vector2.angle
and Vector2.angle_rad
properties
#3195
Comments
Hi @aatle, Optional setters: Allow setting angle (in degrees) or angle_rad (in radians) to change the vector's direction, normalizing values outside their intervals. Tell me if I don't understand the issue. |
@AntoineMamou, sure you can work on this feature request, anyone can work on it. |
@aatle, I began to add the two functions |
Yeah you usually make a pull request for that. Also, the issue was requesting properties (Vector2.angle), not functions, but at the same time it's your PR so you're free. |
About property vs methods: |
Proposal:
Add properties
angle
andangle_rad
topygame.Vector2
with getter and possibly a setter.(These angles are normalized: degrees within interval (-180, 180], even if set to an angle outside this range.)
The zero vector has an angle of 0.
Reasons:
In math, the angle of a vector is often relative to the positive x-axis (increasing angle from 0 goes towards positive y-axis).
For example, polar coordinates and trigonometry functions are connected to vectors through their angle to positive x-axis.
vec == Vector2(r * cos(theta), r * sin(theta))
The current ways to get these angles are indirect and less readable, for such an (IMO) important aspect of vectors. See above. In
as_polar()
result, the length is available viavec.length
, but the angle is not directly available.In a codebase, it's convenient to only have to store one float (angle to +x axis) to mark the direction of something, rather than another vector (especially when the distance between two points is unnecessary/inapplicable). Many physics libraries or engines use angles like this heavily, usually using radians. Even if angles are technically only relative, to store them conveniently there has to be 'absolute' angles.
Example uses:
Calculate the angle of one position to another position, in degrees.
Find the angle between two vectors, in radians.
Rotate a vector in-place at the direction of a given angle (from +x axis), in degrees.
The text was updated successfully, but these errors were encountered: