[英]Is there a way to find all the edges of a 3D shape given its vertices?
我有一個簡單的 3D 形狀的頂點列表,如金字塔、立方體或十二面體,是否有一種算法可以找到構成面的“外部頂點”之間的所有連接?
例如,一旦將金字塔投影到 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));
}
}
}
}
這僅適用於金字塔,我想知道是否有一種方法可以計算給定 [n][2] 組坐標的所有邊緣,這些坐標表示投影的 3D 形狀。
您的問題沒有唯一答案,請查看為球體創建網格的四種方法
這里我翻譯第一種方法,也就是類似於地理坐標,基於經緯度。
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
}
}
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)
);
}
既然您提到您將金字塔投影到 2D,我想您也可以將這些任意線投影到 2D。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.