Liagson / ConcaveHullGenerator

Concave hull for C# (Comes with a Unity demo)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3D?

Godatplay opened this issue · comments

Do you have an idea what would be involved with adding 3D support for this?

Not much 😄
I currently don't have enough time to make the changes myself though, but I can help you if you are interested.
As far as I see, what you need to change in order to add a third dimension is:

  1. Add a Z axis in the Node.cs file (public double z;) (don't forget to add it in both constructors)
  2. Change the getLength(node1, node2) method in the Line.cs file to something like this (we need to measure now a 3d line):
    double length = Math.Pow(node1.y - node2.y, 2) + Math.Pow(node1.x - node2.x, 2) + Math.Pow(node1.z - node2.z, 2) ;
  3. Change the Init.cs file to add random heights to the points in the demo scene:
    From this:
    dot_list.Add(new Node(pseudorandom.Next(0, 100), pseudorandom.Next(0, 100), x));
    To this:
    dot_list.Add(new Node(pseudorandom.Next(0, 100), pseudorandom.Next(0, 100), pseudorandom.Next(0, 100), x));

This might be kind of a hack (it rather surprises me how few changes are needed), but it will indeed, I believe, add a hull (seen from above)

Note: I haven't run this changes (I don't even have Unity installed) and there might be some weird behaviors (and operations) due to the current program being built with only 2 dimensions in mind. If you try these changes please tell me if they work!

You will also need to change this method in Init.cs:

void OnDrawGizmos() {

            //Convex hull
            Gizmos.color = Color.yellow;
            for (int i = 0; i < Hull.hull_edges.Count; i++) {
                Vector3 left = new Vector3((float)Hull.hull_edges[i].nodes[0].x, (float)Hull.hull_edges[i].nodes[0].y, (float)Hull.hull_edges[i].nodes[0].z);
                Vector3 right = new Vector3((float)Hull.hull_edges[i].nodes[1].x, (float)Hull.hull_edges[i].nodes[1].y, (float)Hull.hull_edges[i].nodes[1].z);
                Gizmos.DrawLine(left, right);
            }
            //Concave hull
            Gizmos.color = Color.blue;
            for (int i = 0; i < Hull.hull_concave_edges.Count; i++) {
                Vector3 left = new Vector3((float)Hull.hull_concave_edges[i].nodes[0].x, (float)Hull.hull_concave_edges[i].nodes[0].y, (float)Hull.hull_concave_edges[i].nodes[0].z);
                Vector3 right = new Vector3((float)Hull.hull_concave_edges[i].nodes[1].x, (float)Hull.hull_concave_edges[i].nodes[1].y, (float)Hull.hull_concave_edges[i].nodes[1].z);
                Gizmos.DrawLine(left, right);
            }

            Gizmos.color = Color.red;
            for (int i = 0; i < dot_list.Count; i++) {
                Gizmos.DrawSphere(new Vector3((float)dot_list[i].x, (float)dot_list[i].y, (float)dot_list[i].z), 0.5f);
            }            
        }

I've just ran all the changes and it looks fine to me :)

I am wondering to use your concaveHull for 3d points. I applied the changes you have mentioned above, but It didn't work correctly. I set the sphere points as the input of the algorithm but the result was some curve of the sphere not all of it. here are the result figures.
https://drive.google.com/file/d/1YGfm0ubHeIr6SxZxVK4p77guhOVG9BPy/view?usp=sharing
https://drive.google.com/file/d/1Rwo8VNdBUD2BY_LXgpsEVcXyth1pi3br/view?usp=sharing

would you help me to add 3D support? How can I change line to triangle?

Hi @faeze-el .
Can you upload a file with the points that you are using? I'll give it a look to see what is going on.
About the 3d support here, if I understand you correctly, what you are looking for is actually a 3d mesh? If what you need is a mesh then I'm afraid that's way out of scope for this program.

Thanks for the quick reply.
Oh, Exactly I'm looking for a 3d mesh. :(