Add a function to easily create a concave polygon from a concave hull#340
Add a function to easily create a concave polygon from a concave hull#340robinmoussu wants to merge 1 commit intodimforge:masterfrom
Conversation
| let indexes = { | ||
| let vertex_handle = face.as_triangle(); | ||
| let mut indexes = [0; 3]; | ||
| for i in 0..3 { | ||
| indexes[i] = vertex_handle[i].fix(); | ||
| } | ||
| indexes | ||
| }; |
There was a problem hiding this comment.
Note: this could be rewrote using the collect_tuple method of itertools:
let (a, b, c) = face
.as_triangle()
.iter()
.map(|vertex_handle| vertex_handle.fix())
.collect_tuple()
.unwrap();
But I don't know what is the best way to create an array by applying a function to another array.
There was a problem hiding this comment.
I didn't know about collect_tuple but that looks like an elegant solution.
| /// counter-clockwise convex polyline. | ||
| pub fn new_concave_polygon(isometry: Isometry<N>, hull: &[(N, N)]) -> Compound<N> | ||
| where | ||
| N: spade::SpadeFloat, |
There was a problem hiding this comment.
I don't like to have to leak that we internally uses spade here.
There was a problem hiding this comment.
Unfortunately, I don't think we have a viable alternative here. I am not sure why the SpadeFloat trait does not have a blanket impl in the first place…
|
|
||
| /// Creates a new 2D concave polygon from a set of points assumed to describe a | ||
| /// counter-clockwise convex polyline. | ||
| pub fn new_concave_polygon(isometry: Isometry<N>, hull: &[(N, N)]) -> Compound<N> |
There was a problem hiding this comment.
I don't know if new_concave_polygon should be added as a new constructor of Compound or if a new struct that implements the same traits as Compound should be created.
The issue with the current proposal is that the triangles used for the creation of the Compound shape are leaked, since it's possible to manipulate them with Compound::shapes() and then cast them with .as_shape::<ConvexPolygon<f64>>().
There was a problem hiding this comment.
I think that it is OK to have this method here for now. I would prefer the following signature:
#[cfg(all(feature = "dim2", feature = "spade"))]
pub fn from_convex_decomposition_of(position: Isometry<N>, vertices: &[Point2<N>]) -> Compound<N>I think that ultimately we will want to use a TriMesh for this instead of a Compound. However, using a TriMesh is not possible right now because ncollide only supports it in 3D.
|
|
||
| /// Creates a new 2D concave polygon from a set of points assumed to describe a | ||
| /// counter-clockwise convex polyline. | ||
| pub fn new_concave_polygon(isometry: Isometry<N>, hull: &[(N, N)]) -> Compound<N> |
There was a problem hiding this comment.
I think that it is OK to have this method here for now. I would prefer the following signature:
#[cfg(all(feature = "dim2", feature = "spade"))]
pub fn from_convex_decomposition_of(position: Isometry<N>, vertices: &[Point2<N>]) -> Compound<N>I think that ultimately we will want to use a TriMesh for this instead of a Compound. However, using a TriMesh is not possible right now because ncollide only supports it in 3D.
| /// counter-clockwise convex polyline. | ||
| pub fn new_concave_polygon(isometry: Isometry<N>, hull: &[(N, N)]) -> Compound<N> | ||
| where | ||
| N: spade::SpadeFloat, |
There was a problem hiding this comment.
Unfortunately, I don't think we have a viable alternative here. I am not sure why the SpadeFloat trait does not have a blanket impl in the first place…
| delaunay | ||
| .triangles() | ||
| .filter_map(|face| { | ||
| let indexes = { |
There was a problem hiding this comment.
| let indexes = { | |
| let indices = { |
| let indexes = { | ||
| let vertex_handle = face.as_triangle(); | ||
| let mut indexes = [0; 3]; | ||
| for i in 0..3 { | ||
| indexes[i] = vertex_handle[i].fix(); | ||
| } | ||
| indexes | ||
| }; |
There was a problem hiding this comment.
I didn't know about collect_tuple but that looks like an elegant solution.
| nalgebra = "0.21" | ||
| approx = { version = "0.3", default-features = false } | ||
| serde = { version = "1.0", optional = true, features = ["derive"]} | ||
| spade = "1.8.2" |
There was a problem hiding this comment.
| spade = "1.8.2" | |
| spade = { version = "1", optional = true } |
|
I tested it a bit more, and unfortunately the triangulation approach I took doesn't works. The hull is the black line, and the orange triangles are the one detected as being inside the hull, using the algorithm in this PR. As you can see:
So, … I need to restart from scratch. I think we can close this PR unfortunately. |
|
I just noticed that there is maybe a way to solve the issue by using |
1 similar comment
|
I just noticed that there is maybe a way to solve the issue by using |

Fix #338
This is an early POC to show how I am creating a concave polygon from a concave hull.
Remarks regarding this draft:
cargo run --example concave.cargo checkworks frombuild/ncollide2d, but not from the root directory.gnuplotas a dev-dependency, but it's just there to display how the concave polygon is created, and what points are tested. If this patch is ever merged, I am not sure it should be kept. I didn't check if anything was already used to display graphics on the screen.concave.rs) serve as unit test. If this PR is merged it should be transformed into a proper unit test. I did it this way to be able to display the polygon, and show that it works.f32/f64unfortunately this must be visible in the public API ofnew_concave_polygon. I am not happy about this.