1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
struct bd {
int numpoints; /**< Number of points defining the body. */
double **coord; /** points' coordinates. */
double s [3]; /**< Support mapping computed last. */
};
[code/]
And my main problem is to transform my c++ vector to be given to **coord variable:
[code]
double **cdata1 = nullptr, **cdata2 = nullptr;
struct bd bd1{8, cdata1};
struct bd bd2{8, cdata2};;
double (**vrtx1) = nullptr,
(**vrtx2) = nullptr;
cdata1 = (double **) malloc(8 * sizeof(double *));
for (int32_t i = 0; i < 8; i++)
{
cdata1[i] = (double *) malloc(3 * sizeof(double));
}
cdata2 = (double **) malloc(24 * sizeof(double *));
for (int32_t i = 0; i < 8; i++)
{
cdata2[i] = (double *) malloc(3 * sizeof(double));
}
std::vector<std::vector<double>> cppdata1 = {{0, 0, 0},
{1, 1, 1},
{2, 2, 2},
{3, 3, 3},
{4, 4, 4},
{5, 5, 5},
{6, 6, 6},
{7, 7, 7}};
std::vector<std::vector<double>> cppdata2 = {{10, 10, 10},
{11, 11, 11},
{12, 12, 12},
{13, 13, 13},
{14, 14, 14},
{15, 15, 15},
{16, 16, 16},
{17, 17, 17}};
for (int32_t i = 0; i < 8; i++)
{
for (int32_t j = 0; j < 3; j++)
{
cdata1[i][j] = cppdata1[i][j];
}
}
for (int32_t i = 0; i < 8; i++)
{
for (int32_t j = 0; j < 3; j++)
{
cdata2[i][j] = cppdata2[i][j];
}
}
/* Initialise simplex as empty */
s.nvrtx = 0;
// the input should be given to the main function, which is actually written in C... can it be the problem?..
dd = gjk(bd1, bd2, &s);
printf("Distance between bodies %f\n", dd);
for (int32_t i = 0; i < 3; i++)
{
free(cdata1[i]);
}
free(cdata1);
for (int32_t i = 0; i < 3; i++)
{
free(cdata2[i]);
}
free(cdata2);
|