[英]Is there a way to find all the edges of a 3D shape given its vertices?
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?我有一个简单的 3D 形状的顶点列表,如金字塔、立方体或十二面体,是否有一种算法可以找到构成面的“外部顶点”之间的所有连接?
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例如,一旦将金字塔投影到 2D 我有一个每个顶点的 8 个坐标 x,y 的矩阵:
int[] coords = new int [8][2]
并想出了这种计算它们的方法
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.这仅适用于金字塔,我想知道是否有一种方法可以计算给定 [n][2] 组坐标的所有边缘,这些坐标表示投影的 3D 形状。
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 function添加球面线
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.既然您提到您将金字塔投影到 2D,我想您也可以将这些任意线投影到 2D。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.