【问题标题】:Is there a way to find all the edges of a 3D shape given its vertices?有没有办法在给定顶点的情况下找到 3D 形状的所有边缘?
【发布时间】:2022-01-04 03:44:35
【问题描述】:

我有一个简单 3D 形状的顶点列表,如金字塔、立方体或十二面体,是否有算法可以找到构成面部的“外部顶点”之间的所有连接? 脸是常规的 2d 形状(正方形代表立方体,三角形代表金字塔......)

例如,一旦将金字塔投影到 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));
                                    }
                                }
                            }
                        }

这仅适用于金字塔,我想知道是否有一种方法可以计算代表投影 3D 形状的给定 [n][2] 组坐标的所有边缘。

【问题讨论】:

    标签: java linear-algebra shapes


    【解决方案1】:

    一组顶点的面

    如果你有边缘列表,你可以申请the graph algorithm for faces,但我试着猜测了一下。

    如果你的形状是凸的,你可以find the convex hull的顶点。

    如果你的形状不是凸的,并且你的网格足够“精细”

    您可以推动边迭代V * (V - 1) / 2 对顶点的列表,这些顶点对按距离增加排序;如果 (1) 它没有创建新面或 (2) 新创建的面中使用的边都不会在两个以上面的轮廓中,则将顶点添加到网格中。

    球体的边

    您的问题没有唯一答案,请查看Four ways to crate a mesh for a sphere

    这里我翻译第一种方法,类似于地理坐标,基于经纬度。

    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
       }
    }
    

    添加球面线的功能

    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。

    【讨论】:

    • 谢谢,但我不确定这是我要搜索的内容,如果我理解正确的话,使用这种方法会有一堆正方形
    • 抱歉再次阅读我发现我第一次阅读时被误导了。我编辑了问题,指出了您想要的三个猜测。
    猜你喜欢
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-18
    • 1970-01-01
    相关资源
    最近更新 更多