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?
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.