0

I have a list of vertices of a simple 3D shape like a pyramid, a cube or a dodecahedron, is there an algorithm to find all the connections between the "outer vertices" that make up a face? Face being the regular 2d shape (square for a cube, triagles for a pyramid...)

for example, once projected a pyramid to 2D I have a matrix of 8 coordinates x,y for each vertice: int[] coords = new int [8][2] and came up with this way of calculating them

for(int i = 0; i<4; i++){
    for(int a = 1; a<=4; a++){
        if(i+a!=3){
            if(a>i){
                edges.add(new Line( coords[i][0] * GROWTH + displacement ,
                                    coords[i][1] * GROWTH + displacement,
                                    coords[a][0] * GROWTH + displacement,
                                    coords[a][1] * GROWTH + displacement));
                                    }
                                }
                            }
                        }

This only works with pyramids, I wonder if there's a way of calculating all the edges of a given [n][2] set of coordinates representing a projected 3D shape.

Mes
  • 13
  • 4

1 Answers1

0

Faces from a set of vertices

If you have a list of edges you can apply the graph algorithm for faces, but I tried to guess a little.

If your shape is convex you can find the convex hull of the vertices.

If your shape is not convex, and your mesh is "fine" enough

You can push the edges iterate over the list of V * (V - 1) / 2 pairs of vertices ordered by increasing distance; you add the vertex to the mesh if (1) it does not create a new face or (2) none of the edges used in the newly created faces will be in the contour of more than two faces.

Edges for a sphere

There is no unique answer to your question, check Four ways to crate a mesh for a sphere

Here I translate the first approach, that is similar to geographical coordinates, based on latitude and longitude.

for(int i = 0; i<num_parallels; i++){
    for(int a = 1; a<=4; num_meridians++){
        double y1 = PI * i / num_parallels;
        double y2 = l1 + PI / num_parallels;
        double x1 = 2.0 * PI * i / num_meridians;
        double x2 = x1 + 2.0 * PI / num_meridians;
        add_sphere_line(x1, y1, x1, y2); // a parallel
        add_sphere_line(x1, y1, x2, y1); // a meridian
   }
}

The function to add a sphere line

void add_sphere_line(double x1, double y1, double x2, double y2){
  add_3d_line(
   // starting point in 3D coordinates
   Math.cos(x1) * Math.sin(y1), Math.cos(y1), Math.sin(x1) * Math.sin(y1),
   // end point in 3D coordinates
   Math.cos(x2) * Math.sin(y2), Math.cos(y2), Math.sin(x2) * Math.sin(y2)
  );
}

Since you mention you projected the pyramid to 2D I imagine you can workout the projection of these arbitrary lines to 2D as well.

Bob
  • 13,867
  • 1
  • 5
  • 27
  • Thank you, but I'm not sure this is what I was searching, with this method there will be a bunch of squares if I understood this right – Mes Jan 09 '22 at 04:43
  • Sorry reading again I see that I was mislead when I first read it. I edited the question pointing three guesses for what you want. – Bob Jan 09 '22 at 10:42