2020-05-04 04:40:13 -07:00
|
|
|
#include "openGJK/openGJK.h"
|
|
|
|
#include <pybind11/eigen.h>
|
|
|
|
#include <pybind11/pybind11.h>
|
|
|
|
namespace py = pybind11;
|
|
|
|
|
2022-07-09 14:10:45 -07:00
|
|
|
PYBIND11_MODULE(opengjkc, m) {
|
2020-05-04 04:40:13 -07:00
|
|
|
m.def("gjk",
|
2022-07-09 14:10:45 -07:00
|
|
|
[](Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor> &arr1,
|
|
|
|
Eigen::Array<double, Eigen::Dynamic, 3, Eigen::RowMajor> &arr2)
|
2020-05-04 04:40:13 -07:00
|
|
|
-> double {
|
2022-11-01 01:49:13 -07:00
|
|
|
gkSimplex s;
|
|
|
|
gkPolytope bd1;
|
|
|
|
gkPolytope bd2;
|
2020-05-04 04:40:13 -07:00
|
|
|
bd1.numpoints = arr1.rows();
|
2022-07-09 14:10:45 -07:00
|
|
|
std::vector<double *> arr1_rows(arr1.rows());
|
2020-05-04 04:40:13 -07:00
|
|
|
for (int i = 0; i < arr1.rows(); ++i)
|
|
|
|
arr1_rows[i] = arr1.row(i).data();
|
|
|
|
bd1.coord = arr1_rows.data();
|
|
|
|
|
|
|
|
bd2.numpoints = arr2.rows();
|
2022-07-09 14:10:45 -07:00
|
|
|
std::vector<double *> arr2_rows(arr2.rows());
|
2020-05-04 04:40:13 -07:00
|
|
|
for (int i = 0; i < arr2.rows(); ++i)
|
|
|
|
arr2_rows[i] = arr2.row(i).data();
|
|
|
|
bd2.coord = arr2_rows.data();
|
|
|
|
|
2022-11-01 01:49:13 -07:00
|
|
|
double a = compute_minimum_distance(bd1, bd2, &s);
|
2020-05-04 04:40:13 -07:00
|
|
|
|
|
|
|
return a;
|
|
|
|
});
|
2022-11-01 01:49:13 -07:00
|
|
|
}
|