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

Triangle<f32>::area wildly inaccurate for degenerate triangles (compute in f64 please) #111

Open
wlinna opened this issue Dec 5, 2022 · 0 comments

Comments

@wlinna
Copy link
Contributor

wlinna commented Dec 5, 2022

When I compute the area of a triangle with the provided Triangle::area -function, the area can be very wrong.

    let tri = Triangle::new(
        na::Point3::new(1.811, -2.871, 17.464),
        na::Point3::new(1.811, 1.629, 17.464),
        na::Point3::new(1.811, -1.521, 17.464),
    );

    let area = tri.area();

    dbg!(area);

[src/main.rs:37] area = 0.0010679931

Since the triangle is degenerate, the area should be 0. Perhaps ironically, if I calculate with Heron's formula (which tends to give more inaccurate results for needle-like triangles) the resulting area is 0 as it should be. A f64-implementation of Triangle::area also works.

Now I'm not an expert of floating point mathematics nor mathematics in general, but I wonder if Kahan's formula could be replaced with something else? Something called Graham's determinant (f32) also produced 0 when I tried it, but I wonder how its accuracy compares with Kahan's in general. And of course it would be possible to use f64 internally.

This is not the most important issue to solve I think. After all, this is just how Kahan's formula works, and one can use parry-f64 or implement the formula with f64 instead.

@wlinna wlinna changed the title Triangle::area wildly inaccurate for degenerate triangles (compute in f64 please) Triangle<f32>::area wildly inaccurate for degenerate triangles (compute in f64 please) Dec 5, 2022
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

1 participant