Skip to content

Commit

Permalink
Removed ccdGJKDist() and related functions and tests.
Browse files Browse the repository at this point in the history
It is unfinished implementation of distance computation using GJK
algorithm. This functionality was moved to gjk-dist branch until it is
finished and properly tested.
  • Loading branch information
danfis committed Jan 12, 2014
1 parent c4a3a31 commit 46391af
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 233 deletions.
123 changes: 0 additions & 123 deletions src/ccd.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,6 @@ static int doSimplex2(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex3(ccd_simplex_t *simplex, ccd_vec3_t *dir);
static int doSimplex4(ccd_simplex_t *simplex, ccd_vec3_t *dir);

/** Reduces the 4-point simplex to a triangle that is nearest to the
* origin.
* It is assumed that the last (fourth) point in the simplex was an
* expansion towards the origin of the triangle formed by the first three
* points. And the second arguemnt is a precomputed distance of the
* triangle. So it is only checked whether the fourth point can improve
* the previous triangle.
* Returns a distance from the origin of the new triangle and via the
* witness parameter the point nearest to the origin.
*/
static ccd_real_t simplexReduceToTriangle(ccd_simplex_t *simplex,
ccd_real_t dist,
ccd_vec3_t *witness);

/** d = a x b x c */
_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d);
Expand Down Expand Up @@ -219,82 +205,6 @@ int ccdGJKPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
}


ccd_real_t ccdGJKDist(const void *obj1, const void *obj2, const ccd_t *ccd)
{
unsigned long iterations;
ccd_simplex_t simplex;
ccd_support_t last; // last support point
ccd_vec3_t dir; // direction vector
ccd_real_t dist, last_dist;

// first find an intersection
if (__ccdGJK(obj1, obj2, ccd, &simplex) == 0)
return -CCD_ONE;

last_dist = CCD_REAL_MAX;

for (iterations = 0UL; iterations < ccd->max_iterations; ++iterations) {
// get a next direction vector
// we are trying to find out a point on the minkowski difference
// that is nearest to the origin, so we obtain a point on the
// simplex that is nearest and try to exapand the simplex towards
// the origin
if (ccdSimplexSize(&simplex) == 1){
ccdVec3Copy(&dir, &ccdSimplexPoint(&simplex, 0)->v);
dist = ccdVec3Len2(&ccdSimplexPoint(&simplex, 0)->v);
dist = CCD_SQRT(dist);
}else if (ccdSimplexSize(&simplex) == 2){
dist = ccdVec3PointSegmentDist2(ccd_vec3_origin,
&ccdSimplexPoint(&simplex, 0)->v,
&ccdSimplexPoint(&simplex, 1)->v,
&dir);
dist = CCD_SQRT(dist);
}else if(ccdSimplexSize(&simplex) == 3){
dist = ccdVec3PointTriDist2(ccd_vec3_origin,
&ccdSimplexPoint(&simplex, 0)->v,
&ccdSimplexPoint(&simplex, 1)->v,
&ccdSimplexPoint(&simplex, 2)->v,
&dir);
dist = CCD_SQRT(dist);
}else{ // ccdSimplexSize(&simplex) == 4
dist = simplexReduceToTriangle(&simplex, last_dist, &dir);
}

// touching contact -- do we really need this?
// maybe __ccdGJK() solve this alredy.
if (ccdIsZero(dist))
return -CCD_ONE;

// check whether we improved for at least a minimum tolerance
if ((last_dist - dist) < ccd->dist_tolerance)
return dist;

// point direction towards the origin
ccdVec3Scale(&dir, -CCD_ONE);
ccdVec3Normalize(&dir);

// find out support point
__ccdSupport(obj1, obj2, &dir, ccd, &last);

// record last distance
last_dist = dist;

// check whether we improved for at least a minimum tolerance
// this is here probably only for a degenerate cases when we got a
// point that is already in the simplex
dist = ccdVec3Len2(&last.v);
dist = CCD_SQRT(dist);
if (CCD_FABS(last_dist - dist) < ccd->dist_tolerance)
return last_dist;

// add a point to simplex
ccdSimplexAdd(&simplex, &last);
}

return -CCD_REAL(1.);
}


static int __ccdGJK(const void *obj1, const void *obj2,
const ccd_t *ccd, ccd_simplex_t *simplex)
{
Expand Down Expand Up @@ -628,39 +538,6 @@ static int doSimplex(ccd_simplex_t *simplex, ccd_vec3_t *dir)
}
}

static ccd_real_t simplexReduceToTriangle(ccd_simplex_t *simplex,
ccd_real_t dist,
ccd_vec3_t *best_witness)
{
ccd_real_t newdist;
ccd_vec3_t witness;
int best = -1;
int i;

// try the fourth point in all three positions
for (i = 0; i < 3; i++){
newdist = ccdVec3PointTriDist2(ccd_vec3_origin,
&ccdSimplexPoint(simplex, (i == 0 ? 3 : 0))->v,
&ccdSimplexPoint(simplex, (i == 1 ? 3 : 1))->v,
&ccdSimplexPoint(simplex, (i == 2 ? 3 : 2))->v,
&witness);
newdist = CCD_SQRT(newdist);

// record the best triangle
if (newdist < dist){
dist = newdist;
best = i;
ccdVec3Copy(best_witness, &witness);
}
}

if (best >= 0){
ccdSimplexSet(simplex, best, ccdSimplexPoint(simplex, 3));
}
ccdSimplexSetSize(simplex, 3);

return dist;
}

_ccd_inline void tripleCross(const ccd_vec3_t *a, const ccd_vec3_t *b,
const ccd_vec3_t *c, ccd_vec3_t *d)
Expand Down
11 changes: 0 additions & 11 deletions src/ccd/ccd.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,6 @@ int ccdGJKSeparate(const void *obj1, const void *obj2, const ccd_t *ccd,
int ccdGJKPenetration(const void *obj1, const void *obj2, const ccd_t *ccd,
ccd_real_t *depth, ccd_vec3_t *dir, ccd_vec3_t *pos);


/**
* Computes a distance between given objects.
* The function uses .dist_tolerance parameter for convergence checking (the
* improvement in one step must be at least .dist_tolerance).
*
* Returns a distance between given objects or a negative number if
* objects intersect.
*/
ccd_real_t ccdGJKDist(const void *obj1, const void *obj2, const ccd_t *ccd);

/**
* Returns true if two given objects intersect - MPR algorithm is used.
*/
Expand Down
51 changes: 0 additions & 51 deletions src/testsuites/boxbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,54 +465,3 @@ TEST(boxboxPenetration)
recPen(depth, &dir, &pos, stdout, "Pen 8");
//TOSVT();
}


TEST(boxboxDist)
{
ccd_t ccd;
CCD_BOX(box1);
CCD_BOX(box2);
ccd_real_t dist;
ccd_vec3_t axis;
ccd_quat_t rot;

fprintf(stderr, "\n\n\n---- boxboxDist ----\n\n\n");

box1.x = box1.y = box1.z = 1.;
box2.x = 0.5;
box2.y = 1.;
box2.z = 1.5;

CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;

ccdVec3Set(&box2.pos, 0.1, 0., 0.);

dist = ccdGJKDist(&box1, &box2, &ccd);
assertTrue(dist < 0.);

ccdVec3Set(&box2.pos, 0.76, 0., 0.);
dist = ccdGJKDist(&box1, &box2, &ccd);
assertTrue(ccdEq(dist, 0.01));

ccdVec3Set(&box2.pos, -0.76, 0., 0.);
dist = ccdGJKDist(&box1, &box2, &ccd);
assertTrue(ccdEq(dist, 0.01));

ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdQuatMul(&box2.quat, &rot);
ccdVec3Set(&box2.pos, 0.55, 0.55, 0.);
dist = ccdGJKDist(&box1, &box2, &ccd);
assertTrue(dist > 0.f);

ccdVec3Set(&axis, 0., 0., 1.);
ccdQuatSetAngleAxis(&rot, M_PI / 4., &axis);
ccdQuatMul(&box1.quat, &rot);
ccdQuatMul(&box2.quat, &rot);
ccdVec3Set(&box2.pos, 0.4, 0.4, 0.);
dist = ccdGJKDist(&box1, &box2, &ccd);
assertFalse(dist > 0.f);
}
4 changes: 0 additions & 4 deletions src/testsuites/boxbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ TEST(boxboxRot);
TEST(boxboxSeparate);
TEST(boxboxPenetration);

TEST(boxboxDist);

TEST_SUITE(TSBoxBox) {
TEST_ADD(boxboxSetUp),

Expand All @@ -27,8 +25,6 @@ TEST_SUITE(TSBoxBox) {
TEST_ADD(boxboxSeparate),
TEST_ADD(boxboxPenetration),

TEST_ADD(boxboxDist),

TEST_ADD(boxboxTearDown),
TEST_SUITE_CLOSURE
};
Expand Down
6 changes: 0 additions & 6 deletions src/testsuites/regressions/TSBoxBox.err
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@
---- boxboxPenetration ----





---- boxboxDist ----


34 changes: 0 additions & 34 deletions src/testsuites/spheresphere.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,37 +97,3 @@ TEST(spheresphereAlignedZ)
s1.pos.v[2] += 0.1;
}
}

TEST(spheresphereDist)
{
ccd_t ccd;
CCD_SPHERE(s1);
CCD_SPHERE(s2);
size_t i;
ccd_real_t dist, real_dist;

CCD_INIT(&ccd);
ccd.support1 = ccdSupport;
ccd.support2 = ccdSupport;
ccd.dist_tolerance = 1E-8;

s1.radius = 0.35;
s2.radius = .5;

ccdVec3Set(&s1.pos, 0., 0., -5.);
for (i = 0; i < 100; i++){
dist = ccdGJKDist(&s1, &s2, &ccd);

if (i < 42 || i > 58){
assertTrue(dist > 0.f);

real_dist = CCD_SQRT(ccdVec3Dist2(&s1.pos, &s2.pos));
real_dist = real_dist - (s1.radius + s2.radius);
assertTrue(CCD_FABS(dist - real_dist) < 1E-6);
}else{
assertTrue(dist < 0.f);
}

s1.pos.v[2] += 0.1;
}
}
4 changes: 0 additions & 4 deletions src/testsuites/spheresphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ TEST(spheresphereAlignedX);
TEST(spheresphereAlignedY);
TEST(spheresphereAlignedZ);

TEST(spheresphereDist);

TEST_SUITE(TSSphereSphere) {
TEST_ADD(spheresphereSetUp),

TEST_ADD(spheresphereAlignedX),
TEST_ADD(spheresphereAlignedY),
TEST_ADD(spheresphereAlignedZ),

TEST_ADD(spheresphereDist),

TEST_ADD(spheresphereTearDown),
TEST_SUITE_CLOSURE
};
Expand Down

0 comments on commit 46391af

Please sign in to comment.