Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 生成三角形边的代码_C++_Geometry_Trigonometry - Fatal编程技术网

C++ 生成三角形边的代码

C++ 生成三角形边的代码,c++,geometry,trigonometry,C++,Geometry,Trigonometry,我正在使用我发现的一些代码来测试两个三角形的交点。我遇到问题的代码部分是: /*tr_tri_intersect3D - C1 is a vertex of triangle A. P1,P2 are the two edges originating from this vertex. D1 is a vertex of triangle B. P1,P2 are the two edges originating from this vertex. Returns zero for disj

我正在使用我发现的一些代码来测试两个三角形的交点。我遇到问题的代码部分是:

/*tr_tri_intersect3D - C1 is a vertex of triangle A. P1,P2 are the two edges originating from this vertex.
D1 is a vertex of triangle B. P1,P2 are the two edges originating from this vertex.
Returns zero for disjoint triangles and non-zero for intersection.*/

int tr_tri_intersect3D (double *C1, double *P1, double *P2,
double *D1, double *Q1, double *Q2);
我不明白的是,如果我有两个三角形的三个顶点,我需要做什么来产生这个函数的输入

完整的源代码可在以下位置找到:

源代码有一个测试函数,它是:

对于(i=0;i,从示例代码看,它所指的边似乎是从起始顶点到结束顶点的向量。
对于具有三个顶点C1、C2、C3的三角形,两条输入边将是P1=C2-C1,P2=C3-C1

读取测试代码,看起来C和D是两个[3][3]数组,包含9个双精度点,分别是点1、2和3及其三维x、y、z坐标

P1和P2是点2和3与三角形C中点1之间的x、y、z距离,Q1和Q2是三角形D中点2和3与点1之间的x、y、z距离。(编辑:byebyebryan说得更好,这是点1到点2和3之间的x、y、z向量)。这两个向量都是[3]双精度数组(基本上是边界框信息)


不知道为什么Ps和Qs不是在函数内部计算的,除非vars还以某种方式保存返回值。

如中所示,如何调用函数?我假设您已经将六个垂直方向传递给它。从代码中的注释来看,它似乎在问我P1、P2、Q1和Q2中的边。这与f没有区别吗rom一个顶点?一条边是由两个顶点组成的。你不能通过一条边,因为没有边,只有两个点组成一条线,我们称之为边。@David是的,这就是我的想法。我只是在我的帖子中放了文件中的测试代码,这有帮助吗?一点也没有。不过,出了什么问题?好的,太棒了。算法有问题esn似乎并不适用于所有三角形的组合,但您在如何输入方面是正确的。
The source code had a test function, it was:

for (i = 0; i<10000; i++){
        for (j = 0; j<3; j++){
            for (k = 0; k<3; k++){
                PS[i][j][k] = drand48();
                QS[i][j][k] = drand48();
            }
        }
        for (j = 0; j<2; j++){
            for (k = 0; k<3; k++){
                EPS[i][j][k] = PS[i][j + 1][k] - PS[i][0][k];
                EQS[i][j][k] = QS[i][j + 1][k] - PS[i][0][k];
            }
        }
    }
    double sum = 0;
    int t0 = clock();
    int sums[100] = { 0 };
    for (j = 0; j<1000; j++)
        for (i = 0; i<10000; i++){
        int res = tr_tri_intersect3D(PS[i][0], EPS[i][0], EPS[i][1],
            QS[j][0], EQS[j][0], EQS[j][1]);
        sums[res]++;
        }