Compare commits

...

10 Commits

Author SHA1 Message Date
michael 7cef4e55fb install openGJK/openGJK.h to /usr/local/include
missed this in the dylib inst commit; I broke the install() command into 2
2023-06-14 13:53:32 -07:00
michael 73cfe1e1cd remove another merge msg from gitignore 2023-06-14 13:53:23 -07:00
michael c58f582f79 Change unix dest dir
Allows for installation on macOS with SIP, plus general good practice
2023-06-13 14:01:23 -07:00
michael 3b88fa8f01 ignore dynamic libraries 2023-06-13 13:58:43 -07:00
michael 56f9a8db32 remove merge resolution output from .gitignore 2023-06-13 13:57:53 -07:00
Mattia Montanari cdc4efde80 Bugfix 2023-05-23 21:59:45 +02:00
Mattia Montanari 4b2d30e1ca Bugfix merge 2023-05-23 21:57:52 +02:00
Mattia Montanari 5b6a2c456a Bugfix 2023-05-23 21:55:16 +02:00
Mattia Montanari 47df2d76ea Remove unused macro 2023-04-25 16:56:29 +02:00
Mattia Montanari 82c625bbc8 Limit legacy diff 2023-04-25 14:44:46 +02:00
3 changed files with 38 additions and 88 deletions

31
.gitignore vendored
View File

@ -2,10 +2,7 @@
build*/* build*/*
*.so *.so
public/ public/
<<<<<<< HEAD
*.exe *.exe
=======
>>>>>>> master
# Eclispe setting --- do not ignore *.cproject and *.project # Eclispe setting --- do not ignore *.cproject and *.project
*/**/.settings */**/.settings
@ -95,11 +92,7 @@ DocProject/Help/Html2
DocProject/Help/html DocProject/Help/html
# Cmake, make and compiled objects on unix # Cmake, make and compiled objects on unix
<<<<<<< HEAD
#*.cmake #*.cmake
=======
*.cmake
>>>>>>> master
*.c.o *.c.o
*/CMakeFiles/* */CMakeFiles/*
*/Makefile */Makefile
@ -149,20 +142,6 @@ Assets/AssetStoreTools*
# Visual Studio cache directory # Visual Studio cache directory
.vs/ .vs/
<<<<<<< HEAD
=======
# Visual Studio Code cache directory
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
>>>>>>> master
# Autogenerated VS/MD/Consulo solution and project files # Autogenerated VS/MD/Consulo solution and project files
ExportedObj/ ExportedObj/
.consulo/ .consulo/
@ -237,8 +216,8 @@ callgrind.out.*
.cache .cache
.pytest_cache .pytest_cache
.mypy_cache .mypy_cache
<<<<<<< HEAD
======= *.so
======= *.dylib
>>>>>>> master *.dll
>>>>>>> cmakeWin

View File

@ -99,10 +99,13 @@ endif(BUILD_EXAMPLE)
# Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
if (UNIX) if (UNIX)
set(DESTDIR "/usr") set(DESTDIR "/usr/local")
INSTALL(TARGETS opengjk_ce INSTALL(TARGETS opengjk_ce
LIBRARY DESTINATION "${DESTDIR}/lib" LIBRARY DESTINATION "${DESTDIR}/lib"
PUBLIC_HEADER DESTINATION "${DESTDIR}/include" PERMISSIONS WORLD_WRITE
)
INSTALL(TARGETS obj_openGJK
PUBLIC_HEADER DESTINATION "${DESTDIR}/include/openGJK"
PERMISSIONS WORLD_WRITE PERMISSIONS WORLD_WRITE
) )
endif (UNIX) endif (UNIX)

View File

@ -168,12 +168,11 @@ crossProduct(const gkFloat* restrict a, const gkFloat* restrict b, gkFloat* rest
inline static void inline static void
projectOnLine(const gkFloat* restrict p, const gkFloat* restrict q, gkFloat* restrict v) { projectOnLine(const gkFloat* restrict p, const gkFloat* restrict q, gkFloat* restrict v) {
gkFloat pq[3]; gkFloat pq[3];
gkFloat tmp;
pq[0] = p[0] - q[0]; pq[0] = p[0] - q[0];
pq[1] = p[1] - q[1]; pq[1] = p[1] - q[1];
pq[2] = p[2] - q[2]; pq[2] = p[2] - q[2];
tmp = dotProduct(p, pq) / dotProduct(pq, pq); const gkFloat tmp = dotProduct(p, pq) / dotProduct(pq, pq);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
v[i] = p[i] - pq[i] * tmp; v[i] = p[i] - pq[i] * tmp;
@ -183,7 +182,6 @@ projectOnLine(const gkFloat* restrict p, const gkFloat* restrict q, gkFloat* res
inline static void inline static void
projectOnPlane(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r, gkFloat* restrict v) { projectOnPlane(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r, gkFloat* restrict v) {
gkFloat n[3], pq[3], pr[3]; gkFloat n[3], pq[3], pr[3];
gkFloat tmp;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
pq[i] = p[i] - q[i]; pq[i] = p[i] - q[i];
@ -193,7 +191,7 @@ projectOnPlane(const gkFloat* restrict p, const gkFloat* restrict q, const gkFlo
} }
crossProduct(pq, pr, n); crossProduct(pq, pr, n);
tmp = dotProduct(n, p) / dotProduct(n, n); const gkFloat tmp = dotProduct(n, p) / dotProduct(n, n);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
v[i] = n[i] * tmp; v[i] = n[i] * tmp;
@ -218,7 +216,6 @@ inline static int
hff2(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) { hff2(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) {
gkFloat ntmp[3]; gkFloat ntmp[3];
gkFloat n[3], pq[3], pr[3]; gkFloat n[3], pq[3], pr[3];
gkFloat tmp = 0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
pq[i] = q[i] - p[i]; pq[i] = q[i] - p[i];
@ -230,21 +227,12 @@ hff2(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restri
crossProduct(pq, pr, ntmp); crossProduct(pq, pr, ntmp);
crossProduct(pq, ntmp, n); crossProduct(pq, ntmp, n);
for (int i = 0; i < 3; i++) { return dotProduct(p, n) < 0; // Discard r if true
tmp = tmp + (p[i] * n[i]);
}
if (tmp < 0) {
return 1; // Discard r
}
return 0;
} }
inline static int inline static int
hff3(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) { hff3(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restrict r) {
gkFloat n[3], pq[3], pr[3]; gkFloat n[3], pq[3], pr[3];
gkFloat tmp = 0;
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
pq[i] = q[i] - p[i]; pq[i] = q[i] - p[i];
@ -254,16 +242,7 @@ hff3(const gkFloat* restrict p, const gkFloat* restrict q, const gkFloat* restri
} }
crossProduct(pq, pr, n); crossProduct(pq, pr, n);
return dotProduct(p, n) <= 0; // discard s if true
for (int i = 0; i < 3; i++) {
tmp = tmp + (p[i] * n[i]);
}
if (tmp > 0) {
return 0; // discard s
}
return 1;
} }
inline static void inline static void
@ -282,17 +261,17 @@ S1D(gkSimplex* s, gkFloat* v) {
inline static void inline static void
S2D(gkSimplex* s, gkFloat* v) { S2D(gkSimplex* s, gkFloat* v) {
gkFloat* s1p = s->vrtx[2]; const gkFloat* s1p = s->vrtx[2];
gkFloat* s2p = s->vrtx[1]; const gkFloat* s2p = s->vrtx[1];
gkFloat* s3p = s->vrtx[0]; const gkFloat* s3p = s->vrtx[0];
int hff1f_s12 = hff1(s1p, s2p); const int hff1f_s12 = hff1(s1p, s2p);
int hff1f_s13 = hff1(s1p, s3p); const int hff1f_s13 = hff1(s1p, s3p);
if (hff1f_s12) { if (hff1f_s12) {
int hff2f_23 = !hff2(s1p, s2p, s3p); const int hff2f_23 = !hff2(s1p, s2p, s3p);
if (hff2f_23) { if (hff2f_23) {
if (hff1f_s13) { if (hff1f_s13) {
int hff2f_32 = !hff2(s1p, s3p, s2p); const int hff2f_32 = !hff2(s1p, s3p, s2p);
if (hff2f_32) { if (hff2f_32) {
projectOnPlane(s1p, s2p, s3p, v); // Update s, no need to update c projectOnPlane(s1p, s2p, s3p, v); // Update s, no need to update c
return; // Return V{1,2,3} return; // Return V{1,2,3}
@ -311,7 +290,7 @@ S2D(gkSimplex* s, gkFloat* v) {
return; // Return V{1,2} return; // Return V{1,2}
} }
} else if (hff1f_s13) { } else if (hff1f_s13) {
int hff2f_32 = !hff2(s1p, s3p, s2p); const int hff2f_32 = !hff2(s1p, s3p, s2p);
if (hff2f_32) { if (hff2f_32) {
projectOnPlane(s1p, s2p, s3p, v); // Update s, no need to update v projectOnPlane(s1p, s2p, s3p, v); // Update s, no need to update v
return; // Return V{1,2,3} return; // Return V{1,2,3}
@ -354,13 +333,8 @@ S3D(gkSimplex* s, gkFloat* v) {
return; return;
} }
gkFloat det134 = determinant(s1s3, s1s4, s1s2); const gkFloat det134 = determinant(s1s3, s1s4, s1s2);
int sss; const int sss = (det134 <= 0);
if (det134 > 0) {
sss = 0;
} else {
sss = 1;
}
testPlaneTwo = hff3(s1, s3, s4) - sss; testPlaneTwo = hff3(s1, s3, s4) - sss;
testPlaneTwo = testPlaneTwo * testPlaneTwo; testPlaneTwo = testPlaneTwo * testPlaneTwo;
@ -664,21 +638,17 @@ subalgorithm(gkSimplex* s, gkFloat* v) {
gkFloat gkFloat
compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* restrict s) { compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* restrict s) {
int k = 0; /**< Iteration counter */ unsigned int k = 0; /**< Iteration counter */
int i; /**< General purpose counter */ const int mk = 25; /**< Maximum number of GJK iterations */
int mk = 25; /**< Maximum number of iterations of the GJK algorithm */ const gkFloat eps_rel = eps_rel22; /**< Tolerance on relative */
int absTestin; const gkFloat eps_tot = eps_tot22; /**< Tolerance on absolute distance */
const gkFloat eps_rel2 = eps_rel * eps_rel;
unsigned int i;
gkFloat w[3];
gkFloat v[3];
gkFloat vminus[3];
gkFloat norm2Wmax = 0; gkFloat norm2Wmax = 0;
gkFloat tesnorm;
gkFloat v[3]; /**< Search direction */
gkFloat vminus[3]; /**< Search direction * -1 */
gkFloat w[3]; /**< Vertex on CSO boundary given by the difference of support
functions on both bodies */
gkFloat eps_rel = eps_rel22; /**< Tolerance on relative */
gkFloat eps_rel2 = eps_rel * eps_rel;
gkFloat eps_tot = eps_tot22;
gkFloat exeedtol_rel; /**< Test for 1st exit condition */
int nullV = 0;
/* Initialise search direction */ /* Initialise search direction */
v[0] = bd1.coord[0][0] - bd2.coord[0][0]; v[0] = bd1.coord[0][0] - bd2.coord[0][0];
@ -717,13 +687,12 @@ compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* restrict s)
/* Test first exit condition (new point already in simplex/can't move /* Test first exit condition (new point already in simplex/can't move
* further) */ * further) */
exeedtol_rel = (norm2(v) - dotProduct(v, w)); gkFloat exeedtol_rel = (norm2(v) - dotProduct(v, w));
if (exeedtol_rel <= (eps_rel * norm2(v)) || exeedtol_rel < eps_tot22) { if (exeedtol_rel <= (eps_rel * norm2(v)) || exeedtol_rel < eps_tot22) {
break; break;
} }
nullV = norm2(v) < eps_rel2; if (norm2(v) < eps_rel2) { // it a null V
if (nullV) {
break; break;
} }
@ -739,14 +708,13 @@ compute_minimum_distance(gkPolytope bd1, gkPolytope bd2, gkSimplex* restrict s)
/* Test */ /* Test */
for (int jj = 0; jj < s->nvrtx; jj++) { for (int jj = 0; jj < s->nvrtx; jj++) {
tesnorm = norm2(s->vrtx[jj]); gkFloat tesnorm = norm2(s->vrtx[jj]);
if (tesnorm > norm2Wmax) { if (tesnorm > norm2Wmax) {
norm2Wmax = tesnorm; norm2Wmax = tesnorm;
} }
} }
absTestin = (norm2(v) <= (eps_tot * eps_tot * norm2Wmax)); if ((norm2(v) <= (eps_tot * eps_tot * norm2Wmax))) {
if (absTestin) {
break; break;
} }