Skip to content

Convex hull calculation returns incorrect points #372

Description

@guylapid

Hi,
Thanks for this wonderful crate 😄

I'm experiencing a strange behavior in convex hull calculation.
I'm creating a convex hull from a set of points (which indeed form a convex shape).
The first time the created hull's points are the original points (up to some minor acceptable float precision differences) as expected.
But when I take the points of this hull and create a second convex hull from them, the second hull has incorrect points.

An example that reproduces this behavior:

use ncollide3d::math::Point;
use ncollide3d::shape::ConvexHull;

let points = vec![
    Point::new(1., 0., 0.),
    Point::new(-2., 1., 1.),
    Point::new(2., 1., 1.),
    Point::new(2., 0., 2.),
    Point::new(-2., 0., 2.),
    Point::new(1., 1., 0.),
    Point::new(2., 0., 1.),
    Point::new(-2., 0., 1.),
    Point::new(-1., 0., 0.),
    Point::new(-2., 1., 2.),
    Point::new(2., 1., 2.),
    Point::new(-1., 1., 0.),
];

let hull_1 = ConvexHull::try_from_points(&points).unwrap();
println!("hull_1:");
// This prints pretty much the expected points (up to an acceptable float precision):
for point in hull_1.points() {
    println!("({}, {}, {})", point.x, point.y, point.z);
}

let hull_2 = ConvexHull::try_from_points(hull_1.points()).unwrap();
println!("hull_2:");
// This prints incorrect points:
for point in hull_2.points() {
    println!("({}, {}, {})", point.x, point.y, point.z);
}

In the above code, all of the points of hull_2 are completely different from the original point. For example, a point (2, 0.6875000000000018, 3.66666666666667) is somehow added, which is actually pretty far "outside" of the first convex hull.

I expected the second convex hull to have the same points as the first one (again, up to an acceptable minor float precision difference).

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions