Skip to content
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

Poor accuracy in Vector2D::angle_from_x_axis #497

Open
willhansen opened this issue Feb 16, 2023 · 1 comment
Open

Poor accuracy in Vector2D::angle_from_x_axis #497

willhansen opened this issue Feb 16, 2023 · 1 comment

Comments

@willhansen
Copy link

I expected this to be a lot closer to 45 degrees

default::Vector2D::new(0.5, 0.5).angle_from_x_axis().to_degrees() = 44.98835851188444

@nical
Copy link
Contributor

nical commented Feb 17, 2023

angle_from_x_axis is implemented on top of a faster but less precise atan2.

    let v = Vector2D::new(0.5, 0.5);
    let a1: f32 = v.angle_from_x_axis().radians; // 0.785195
    let a2 = v.y.atan2(v.x);                     // 0.7853982
    let a3 = std::f32::consts::PI / 4.0;         // 0.7853982
    let error = (a1 - a3).abs()                  // 0.00020319223

It would maybe make sense for the function to be slower and more precise by default and provide fast_angle_from_x_axis on the side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants