将三角形和点分成对,从点到三角形平面的距离最小

时间:2019-05-18 19:29:20

标签: c algorithm

给出了空间中三个三角形的三个点和坐标。将它们分成几对(点-三角形),从点到三角形平面的距离最小。

不知道如何将它们分成几对。

import

1 个答案:

答案 0 :(得分:0)

void SplitInPairs(double distances[3][3]) {
    double min = 99999;
    int i, j, l;
    int indexi = 1, indexj = 1;

    for (l = 0; l < 3; l++) {
        for (i = 0; i < 3; i++) {
            for (j = 0; j < 3; j++) {
                if (distances[i][j] < min && distances[i][j] != 0) {
                    min = distances[i][j];
                    indexi = i, indexj = j;
                }
            }
        }

        for (j = 0; j < 3; j++) {
            distances[indexi][j] = 0;
            distances[j][indexj] = 0;
        }

        printf("The point %d has the shortest distance to the %d triangle - %.2f\n", indexi + 1, indexj + 1, min);
        min = 999999;
    }
}