-
Notifications
You must be signed in to change notification settings - Fork 161
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
Vec2/3's angle_between
function is unclear/misleading
#514
Comments
Does https://docs.rs/glam/latest/glam/f32/struct.Quat.html#method.from_rotation_arc do what you are after? If it does, one thing that can be done is adding some metadata to docs so angle_between or between would find the quat method. |
Functionally from_rotation_arc does what I am looking for, thank you. I saw it in the sidebar but it wasn't evident from the name that it took two vectors as arg. I'm not sure what you mean by metadata in the docs; I know one can reference other structs but I don't know if that's what you mean |
On the subject of docs it's also not apparent that "invalid" under matrix inverse comments should be checked with
in mathbench. |
It is possible to add doc aliases so if someone searches for something it will match the doc alias. For example there is a doc alias on length methods for magnitude as this is a common alternative name for this method - https://docs.rs/glam/latest/src/glam/f32/sse2/vec4.rs.html#439. I don't know if you used the search function when you were looking but if you did potentially a doc alias would help here (e.g. if you searched for I'm happy to clarify docs, if you want to submit a PR go for it (it will require running codegen) otherwise I'll try get to it sometime. |
I was not searching for a function with this name, rather I was scanning the sidebar under From a documentation pov, I think the main problem is the gotcha suggested by docstring for
compare with the docstring for the same such named method under
The similarities give users every reason to believe that they are eachothers' analog, while Vec2's documentation clearly states that it returns the complete rotational information to go from one vector to another by stating the output range. To realize that these two methods are fundamentally different, one must look at the method return signature and remember that a single float cannot complete describe a rotation vector in 3D. There's just a small hint where the range More generally, it makes sense that both I hope this clarifies my issue, that it wasn't just that I didn't find the function I was looking for. |
I had to do some digging to work out when these were added, it was very early in glam's life 2e5ec77. I think they are fundamentally different because of the differences between 2D and 3D coordinate systems. In 3D we can have left or right handed coordinate systems. glam is coordinate system agnostic, it doesn't assume one or the other. So a 3D Given these methods have been around a long time, most likely they are in use, it's always hard to know with an open source project. I think my preference here would be to improve the docs over renaming at this stage. Describing the ranges and the different behaviour between the 2D and 3D cases might help avoid some confusion when moving between 2D and 3D coordinate systems in glam. |
a +/-ve rotation in 3D wouldn't capture the complete rotation. Even if assuming right or left handed coordinate system the axis of rotation is still left unspecified. If The table below summarizes what I think would make sense to name a set of related methods
Glam's |
I want to try and understand how these are currently used by glam users since they aren't methods that I use myself, if possible, before making any changes. I can see the 2D version is used in bevy for example, but only once. They also have their own 2D rotation type which has an The tricky part with changing the meaning of a function like you are proposing here is it can't be deprecated, it just changes the behaviour of existing code which silently breaks things. I can bump the version number in glam to indicated a breaking change but that can still catch people out if they don't pay attention to the release notes. It's not something I do lightly. |
yeah, I think just improving the docs at this point is a perfectly adequate way to address this. To be clear I only wanted to document/communicate clearly what I think is misleading about the way it is currently. |
angle_between
function is unclear/misleading
All good, I agree it's confusing. |
One way I could introduce this change would be to rename the 2D version as you have suggested here and not add a 2D |
That sounds like a good way to introduce what would otherwise be silently breaking change. I haven't put that much thought into the names. The ones I came up with was only meant to help communicate the issue. For one I'm not sure whether the function actually computes the angle_from or the angle_to. Another thing is that a name like I'm ok to have this issue sit awhile and see if theres anymore input, too. |
Naming wise, there is currently a // the angle returned by angle_to can be used to rotate the input vector to the destination vector
assert_approx_eq!(
Vec2::from_angle(Vec2::X.angle_to(Vec2::Y)).rotate(Vec2::X),
Vec2::Y
);
I actually have to make another breaking change so it's a good time to try and get this change in. There currently isn't a See draft PR #524 |
sounds good! |
What about adding something like a |
I also have the use case that needs a Scalar angle, not a Quat. I have implemented that same Stackoverflow post previously as a work-around. no matter what happens to the documentation of the Quat function, I would appreciate if this Scalar version would be added too. +1 What happened was: Using IDE-completions for my prompt In Unity, the `SignedAngle` function requires the caller to provide the axis/plane normal, which is what I've been using successfully so farThis code happens to use /// note: all vectors must both be non-zero for a meaningful result.
fn signed_angle_across_axis(a: Vec3, b: Vec3, axis: Vec3) -> Option<f32> {
if a == Vec3::ZERO || b == Vec3::ZERO || axis == Vec3::ZERO {
return None;
}
// https://stackoverflow.com/questions/5188561/signed-angle-between-two-3d-vectors-with-same-origin-within-the-same-plane
let n = axis.normalize();
return Some(b.cross(a).dot(n).atan2(a.dot(b)));
} |
# Objective `glam` has opted to rename `Vec2::angle_between` to `Vec2::angle_to` because of the difference in semantics compared to `Vec3::angle_between` and others which return an unsigned angle `[0, PI]` where `Vec2::angle_between` returns a signed angle `[-PI, PI]`. We should follow suit for `Rot2` in 0.15 to avoid further confusion. Links: - bitshifter/glam-rs#514 (comment) - bitshifter/glam-rs#524 ## Migration Guide `Rot2::angle_between` has been deprecated, use `Rot2::angle_to` instead, the semantics of `Rot2::angle_between` will change in the future. --------- Co-authored-by: Joona Aalto <[email protected]>
# Objective `glam` has opted to rename `Vec2::angle_between` to `Vec2::angle_to` because of the difference in semantics compared to `Vec3::angle_between` and others which return an unsigned angle `[0, PI]` where `Vec2::angle_between` returns a signed angle `[-PI, PI]`. We should follow suit for `Rot2` in 0.15 to avoid further confusion. Links: - bitshifter/glam-rs#514 (comment) - bitshifter/glam-rs#524 ## Migration Guide `Rot2::angle_between` has been deprecated, use `Rot2::angle_to` instead, the semantics of `Rot2::angle_between` will change in the future. --------- Co-authored-by: Joona Aalto <[email protected]>
# Objective `glam` has opted to rename `Vec2::angle_between` to `Vec2::angle_to` because of the difference in semantics compared to `Vec3::angle_between` and others which return an unsigned angle `[0, PI]` where `Vec2::angle_between` returns a signed angle `[-PI, PI]`. We should follow suit for `Rot2` in 0.15 to avoid further confusion. Links: - bitshifter/glam-rs#514 (comment) - bitshifter/glam-rs#524 ## Migration Guide `Rot2::angle_between` has been deprecated, use `Rot2::angle_to` instead, the semantics of `Rot2::angle_between` will change in the future. --------- Co-authored-by: Joona Aalto <[email protected]>
# Objective `glam` has opted to rename `Vec2::angle_between` to `Vec2::angle_to` because of the difference in semantics compared to `Vec3::angle_between` and others which return an unsigned angle `[0, PI]` where `Vec2::angle_between` returns a signed angle `[-PI, PI]`. We should follow suit for `Rot2` in 0.15 to avoid further confusion. Links: - bitshifter/glam-rs#514 (comment) - bitshifter/glam-rs#524 ## Migration Guide `Rot2::angle_between` has been deprecated, use `Rot2::angle_to` instead, the semantics of `Rot2::angle_between` will change in the future. --------- Co-authored-by: Joona Aalto <[email protected]>
I ran off into a fruitless tangent just now wondering why Vec3's angle_between wouldn't give me a signed angle (was using Vec3 in a 2d context).
I think a
quat_between
method for Vec3 would be a good addition. It is a better analog to Vec2'sangle_between
than Vec3's currentangle_between
, which isn't the complete rotational information in 3D as it is for Vec2 in 2D.I could probably work on a PR if the idea sounds good to the maintainers.
The text was updated successfully, but these errors were encountered: