forked from humanoid-path-planner/hpp-fcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_fcl_geometric_shapes.cpp
3718 lines (2979 loc) · 118 KB
/
test_fcl_geometric_shapes.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2011-2014, Willow Garage, Inc.
* Copyright (c) 2014-2015, Open Source Robotics Foundation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Open Source Robotics Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/** \author Jia Pan */
#define BOOST_TEST_MODULE FCL_GEOMETRIC_SHAPES
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include <boost/utility/binary.hpp>
#include <hpp/fcl/narrowphase/narrowphase.h>
#include <hpp/fcl/collision.h>
#include "test_fcl_utility.h"
#include <iostream>
using namespace fcl;
FCL_REAL extents [6] = {0, 0, 0, 10, 10, 10};
FCL_REAL tol_gjk = 0.01;
GJKSolver_indep solver1;
GJKSolver_indep solver2;
#define BOOST_CHECK_FALSE(p) BOOST_CHECK(!(p))
template <typename S1, typename S2>
void printComparisonError(const std::string& comparison_type,
const S1& s1, const Transform3f& tf1,
const S2& s2, const Transform3f& tf2,
GJKSolverType solver_type,
const Vec3f& contact_or_normal,
const Vec3f& expected_contact_or_normal,
bool check_opposite_normal,
FCL_REAL tol)
{
std::cout << "Disagreement between " << comparison_type
<< " and expected_" << comparison_type << " for "
<< getNodeTypeName(s1.getNodeType()) << " and "
<< getNodeTypeName(s2.getNodeType()) << " with '"
<< getGJKSolverName(solver_type) << "' solver." << std::endl
<< "tf1.quaternion: " << tf1.getQuatRotation() << std::endl
<< "tf1.translation: " << tf1.getTranslation().transpose() << std::endl
<< "tf2.quaternion: " << tf2.getQuatRotation() << std::endl
<< "tf2.translation: " << tf2.getTranslation().transpose() << std::endl
<< comparison_type << ": " << contact_or_normal.transpose() << std::endl
<< "expected_" << comparison_type << ": " << expected_contact_or_normal.transpose();
if (check_opposite_normal)
std::cout << " or " << -expected_contact_or_normal.transpose();
std::cout << std::endl
<< "difference: " << (contact_or_normal - expected_contact_or_normal).norm() << std::endl
<< "tolerance: " << tol << std::endl;
}
template <typename S1, typename S2>
void printComparisonError(const std::string& comparison_type,
const S1& s1, const Transform3f& tf1,
const S2& s2, const Transform3f& tf2,
GJKSolverType solver_type,
FCL_REAL depth,
FCL_REAL expected_depth,
FCL_REAL tol)
{
std::cout << "Disagreement between " << comparison_type
<< " and expected_" << comparison_type << " for "
<< getNodeTypeName(s1.getNodeType()) << " and "
<< getNodeTypeName(s2.getNodeType()) << " with '"
<< getGJKSolverName(solver_type) << "' solver." << std::endl
<< "tf1.quaternion: " << tf1.getQuatRotation() << std::endl
<< "tf1.translation: " << tf1.getTranslation() << std::endl
<< "tf2.quaternion: " << tf2.getQuatRotation() << std::endl
<< "tf2.translation: " << tf2.getTranslation() << std::endl
<< "depth: " << depth << std::endl
<< "expected_depth: " << expected_depth << std::endl
<< "difference: " << std::fabs(depth - expected_depth) << std::endl
<< "tolerance: " << tol << std::endl;
}
template <typename S1, typename S2>
void compareContact(const S1& s1, const Transform3f& tf1,
const S2& s2, const Transform3f& tf2,
GJKSolverType solver_type,
const Vec3f& contact, Vec3f* expected_point,
FCL_REAL depth, FCL_REAL* expected_depth,
const Vec3f& normal, Vec3f* expected_normal, bool check_opposite_normal,
FCL_REAL tol)
{
if (expected_point)
{
bool contact_equal = isEqual(contact, *expected_point, tol);
BOOST_CHECK(contact_equal);
if (!contact_equal)
printComparisonError("contact", s1, tf1, s2, tf2, solver_type, contact, *expected_point, false, tol);
}
if (expected_depth)
{
bool depth_equal = std::fabs(depth - *expected_depth) < tol;
BOOST_CHECK(depth_equal);
if (!depth_equal)
printComparisonError("depth", s1, tf1, s2, tf2, solver_type, depth, *expected_depth, tol);
}
if (expected_normal)
{
bool normal_equal = isEqual(normal, *expected_normal, tol);
if (!normal_equal && check_opposite_normal)
normal_equal = isEqual(normal, -(*expected_normal), tol);
BOOST_CHECK(normal_equal);
if (!normal_equal)
printComparisonError("normal", s1, tf1, s2, tf2, solver_type, normal, *expected_normal, check_opposite_normal, tol);
}
}
template <typename S1, typename S2>
void testShapeIntersection(const S1& s1, const Transform3f& tf1,
const S2& s2, const Transform3f& tf2,
GJKSolverType solver_type,
bool expected_res,
Vec3f* expected_point = NULL,
FCL_REAL* expected_depth = NULL,
Vec3f* expected_normal = NULL,
bool check_opposite_normal = false,
FCL_REAL tol = 1e-9)
{
CollisionRequest request;
request.gjk_solver_type = solver_type;
CollisionResult result;
Vec3f contact;
FCL_REAL depth;
Vec3f normal; // normal direction should be from object 1 to object 2
bool res;
request.enable_contact = false;
result.clear();
res = (collide(&s1, tf1, &s2, tf2, request, result) > 0);
BOOST_CHECK_EQUAL(res, expected_res);
request.enable_contact = true;
result.clear();
res = (collide(&s1, tf1, &s2, tf2, request, result) > 0);
BOOST_CHECK_EQUAL(res, expected_res);
if (expected_res)
{
BOOST_CHECK_EQUAL(result.numContacts(), 1);
if (result.numContacts() == 1)
{
Contact contact = result.getContact(0);
compareContact(s1, tf1, s2, tf2, solver_type, contact.pos, expected_point, contact.penetration_depth, expected_depth, contact.normal, expected_normal, check_opposite_normal, tol);
}
}
}
BOOST_AUTO_TEST_CASE (shapeIntersection_cylinderbox)
{
Cylinder s1 (0.029, 0.1);
Box s2 (1.6, 0.6, 0.025);
Transform3f tf1
(Quaternion3f (0.5279170511703305, -0.50981118132505521,
-0.67596178682051911, 0.0668715876735793),
Vec3f (0.041218354748013122, 1.2022554710435607, 0.77338855025700015));
Transform3f tf2
(Quaternion3f (0.70738826916719977, 0, 0, 0.70682518110536596),
Vec3f (-0.29936284351096382, 0.80023864435868775, 0.71750000000000003));
GJKSolver_indep solver;
FCL_REAL distance;
Vec3f p1, p2, normal;
bool res = solver.shapeDistance (s1, tf1, s2, tf2, distance, p1, p2, normal);
BOOST_CHECK ((res && distance > 0) || (!res && distance <= 0));
// If objects are not colliding, p2 should be outside the cylinder and
// p1 should be outside the box
Vec3f p2Loc (inverse (tf1).transform (p2));
bool p2_in_cylinder ((fabs (p2Loc [2]) <= .5*s1.lz) &&
(p2Loc [0] * p2Loc [0] + p2Loc [1] * p2Loc [1]
<= s1.radius));
Vec3f p1Loc (inverse (tf2).transform (p1));
bool p1_in_box ((fabs (p1Loc [0]) <= .5 * s2.side [0]) &&
(fabs (p1Loc [1]) <= .5 * s2.side [1]) &&
(fabs (p1Loc [2]) <= .5 * s2.side [2]));
std::cout << "p2 in cylinder = (" << p2Loc.transpose () << ")" << std::endl;
std::cout << "p1 in box = (" << p1Loc.transpose () << ")" << std::endl;
BOOST_CHECK ((res && !p2_in_cylinder && !p1_in_box) ||
(!res && p2_in_cylinder && p1_in_box));
res = solver.shapeDistance (s2, tf2, s1, tf1, distance, p2, p1, normal);
BOOST_CHECK ((res && distance > 0) || (!res && distance <= 0));
// If objects are not colliding, p2 should be outside the cylinder and
// p1 should be outside the box
p2Loc = inverse (tf1).transform (p2);
p2_in_cylinder = (fabs (p2Loc [2]) <= .5*s1.lz) &&
(p2Loc [0] * p2Loc [0] + p2Loc [1] * p2Loc [1]
<= s1.radius);
p1Loc = inverse (tf2).transform (p1);
p1_in_box = (fabs (p1Loc [0]) <= .5 * s2.side [0]) &&
(fabs (p1Loc [1]) <= .5 * s2.side [1]) &&
(fabs (p1Loc [2]) <= .5 * s2.side [2]);
std::cout << "p2 in cylinder = (" << p2Loc.transpose () << ")" << std::endl;
std::cout << "p1 in box = (" << p1.transpose () << ")" << std::endl;
BOOST_CHECK ((res && !p2_in_cylinder && !p1_in_box) ||
(!res && p2_in_cylinder && p1_in_box));
s1 = Cylinder (0.06, 0.1);
tf1.setTranslation (Vec3f (-0.66734052046473924, 0.22219183277457269,
0.76825248755616293));
tf1.setQuatRotation (Quaternion3f (0.52613359459338371,
0.32189408354839893,
0.70415587451837913,
-0.35175580165512249));
res = solver.shapeDistance (s1, tf1, s2, tf2, distance, p1, p2, normal);
}
BOOST_AUTO_TEST_CASE(shapeIntersection_spheresphere)
{
Sphere s1(20);
Sphere s2(10);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(40, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(40, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(30, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(30.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(30.01, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(29.9, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(29.9, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f();
normal.setZero(); // If the centers of two sphere are at the same position, the normal is (0, 0, 0)
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform;
normal.setZero(); // If the centers of two sphere are at the same position, the normal is (0, 0, 0)
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-29.9, 0, 0));
normal << -1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(-29.9, 0, 0));
normal = transform.getRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-30.0, 0, 0));
normal << -1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-30.01, 0, 0));
normal << -1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(-30.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
}
bool compareContactPoints(const Vec3f& c1,const Vec3f& c2)
{
return c1[2] < c2[2];
} // Ascending order
void testBoxBoxContactPoints(const Matrix3f& R)
{
Box s1(100, 100, 100);
Box s2(10, 20, 30);
// Vertices of s2
std::vector<Vec3f> vertices(8);
vertices[0] << 1, 1, 1;
vertices[1] << 1, 1, -1;
vertices[2] << 1, -1, 1;
vertices[3] << 1, -1, -1;
vertices[4] << -1, 1, 1;
vertices[5] << -1, 1, -1;
vertices[6] << -1, -1, 1;
vertices[7] << -1, -1, -1;
for (int i = 0; i < 8; ++i)
{
vertices[i][0] *= 0.5 * s2.side[0];
vertices[i][1] *= 0.5 * s2.side[1];
vertices[i][2] *= 0.5 * s2.side[2];
}
Transform3f tf1 = Transform3f(Vec3f(0, 0, -50));
Transform3f tf2 = Transform3f(R);
Vec3f normal;
Vec3f point;
double penetration;
// Make sure the two boxes are colliding
bool res = solver1.shapeIntersect(s1, tf1, s2, tf2, &point, &penetration, &normal);
BOOST_CHECK(res);
// Compute global vertices
for (int i = 0; i < 8; ++i)
vertices[i] = tf2.transform(vertices[i]);
// Sort the vertices so that the lowest vertex along z-axis comes first
std::sort(vertices.begin(), vertices.end(), compareContactPoints);
// The lowest vertex along z-axis should be the contact point
BOOST_CHECK(isEqual(vertices[0], point));
}
BOOST_AUTO_TEST_CASE(shapeIntersection_boxbox)
{
Box s1(20, 40, 50);
Box s2(10, 10, 10);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
Quaternion3f q;
q = Eigen::AngleAxis<double>((FCL_REAL)3.140 / 6, Vec3f(0, 0, 1));
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position. The current result is (1, 0, 0).
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, 0x0);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position. The current result is (1, 0, 0).
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, 0x0);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(15, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(15.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(q);
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, 0x0);
tf1 = transform;
tf2 = transform * Transform3f(q);
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, 0x0);
FCL_UINT32 numTests = 1e+2;
for (FCL_UINT32 i = 0; i < numTests; ++i)
{
Transform3f tf;
generateRandomTransform(extents, tf);
testBoxBoxContactPoints(tf.getRotation());
}
}
BOOST_AUTO_TEST_CASE(shapeIntersection_spherebox)
{
Sphere s1(20);
Box s2(5, 5, 5);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position. The current result is (-1, 0, 0).
normal << -1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(22.50001, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(22.501, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(22.4, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(22.4, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
}
BOOST_AUTO_TEST_CASE(shapeIntersection_spherecapsule)
{
Sphere s1(20);
Capsule s2(5, 10);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(24.9, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(24.9, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(25, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(24.999999, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(25.1, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(25.1, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
}
BOOST_AUTO_TEST_CASE(shapeIntersection_cylindercylinder)
{
Cylinder s1(5, 15);
Cylinder s2(5, 15);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(0, 9.9, 0));
normal << 0, 1, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(9.9, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(9.9, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(10.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(10.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
}
/*
BOOST_AUTO_TEST_CASE(shapeIntersection_conecone)
{
Cone s1(5, 10);
Cone s2(5, 10);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(9.9, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(9.9, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, tol_gjk);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(10.001, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(10.001, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(0, 0, 9.9));
normal << 0, 0, 1;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(0, 0, 9.9));
normal = transform.getRotation() * Vec3f(0, 0, 1);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
}
*/
/*
BOOST_AUTO_TEST_CASE(shapeIntersection_conecylinder)
{
Cylinder s1(5, 10);
Cone s2(5, 10);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
// Vec3f point;
// FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = transform;
tf2 = transform;
// TODO: Need convention for normal when the centers of two objects are at same position.
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, NULL);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(9.9, 0, 0));
normal << 1, 0, 0;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, 0.061);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(9.9, 0, 0));
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal, false, 0.46);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(10.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(10.01, 0, 0));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(0, 0, 9.9));
normal << 0, 0, 1;
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(0, 0, 9.9));
normal = transform.getRotation() * Vec3f(0, 0, 1);
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, true, NULL, NULL, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(0, 0, 10.01));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(0, 0, 10.01));
testShapeIntersection(s1, tf1, s2, tf2, GST_INDEP, false);
}
*/
BOOST_AUTO_TEST_CASE(shapeIntersection_spheretriangle)
{
Sphere s(10);
Vec3f t[3];
t[0] << 20, 0, 0;
t[1] << -20, 0, 0;
t[2] << 0, 20, 0;
Transform3f transform;
generateRandomTransform(extents, transform);
Vec3f c1, c2, normal;
FCL_REAL distance;
bool res;
res = solver1.shapeTriangleInteraction
(s, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction(s, transform, t[0], t[1], t[2],
transform, distance, c1, c2, normal);
BOOST_CHECK(res);
t[0] << 30, 0, 0;
t[1] << 9.9, -20, 0;
t[2] << 9.9, 20, 0;
res = solver1.shapeTriangleInteraction
(s, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(s, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(s, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, Vec3f(1, 0, 0), 1e-9));
res = solver1.shapeTriangleInteraction
(s, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, transform.getRotation() * Vec3f(1, 0, 0), 1e-9));
}
BOOST_AUTO_TEST_CASE(shapeIntersection_halfspacetriangle)
{
Halfspace hs(Vec3f(1, 0, 0), 0);
Vec3f t[3];
t[0] << 20, 0, 0;
t[1] << -20, 0, 0;
t[2] << 0, 20, 0;
Transform3f transform;
generateRandomTransform(extents, transform);
Vec3f c1, c2;
FCL_REAL distance;
Vec3f normal;
bool res;
res = solver1.shapeTriangleInteraction
(hs, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
t[0] << 20, 0, 0;
t[1] << 0, -20, 0;
t[2] << 0, 20, 0;
res = solver1.shapeTriangleInteraction
(hs, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(hs, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, Vec3f(1, 0, 0), 1e-9));
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, transform.getRotation() * Vec3f(1, 0, 0), 1e-9));
}
BOOST_AUTO_TEST_CASE(shapeIntersection_planetriangle)
{
Plane hs(Vec3f(1, 0, 0), 0);
Vec3f t[3];
t[0] << 20, 0, 0;
t[1] << -20, 0, 0;
t[2] << 0, 20, 0;
Transform3f transform;
generateRandomTransform(extents, transform);
Vec3f c1, c2;
FCL_REAL distance;
Vec3f normal;
bool res;
res = solver1.shapeTriangleInteraction
(hs, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
t[0] << 20, 0, 0;
t[1] << -0.1, -20, 0;
t[2] << -0.1, 20, 0;
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
res = solver1.shapeTriangleInteraction
(hs, Transform3f(), t[0], t[1], t[2], Transform3f(), distance, c1, c2,
normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, Vec3f(1, 0, 0), 1e-9));
res = solver1.shapeTriangleInteraction
(hs, transform, t[0], t[1], t[2], transform, distance, c1, c2, normal);
BOOST_CHECK(res);
BOOST_CHECK(isEqual(normal, transform.getRotation() * Vec3f(1, 0, 0), 1e-9));
}
BOOST_AUTO_TEST_CASE(shapeIntersection_halfspacesphere)
{
Sphere s(10);
Halfspace hs(Vec3f(1, 0, 0), 0);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
Vec3f contact;
FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
contact << -5, 0, 0;
depth = 10;
normal << -1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform;
contact = transform.transform(Vec3f(-5, 0, 0));
depth = 10;
normal = transform.getQuatRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(5, 0, 0));
contact << -2.5, 0, 0;
depth = 15;
normal << -1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(5, 0, 0));
contact = transform.transform(Vec3f(-2.5, 0, 0));
depth = 15;
normal = transform.getQuatRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-5, 0, 0));
contact << -7.5, 0, 0;
depth = 5;
normal << -1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(-5, 0, 0));
contact = transform.transform(Vec3f(-7.5, 0, 0));
depth = 5;
normal = transform.getQuatRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-10.1, 0, 0));
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, false);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(-10.1, 0, 0));
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, false);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(10.1, 0, 0));
contact << 0.05, 0, 0;
depth = 20.1;
normal << -1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(10.1, 0, 0));
contact = transform.transform(Vec3f(0.05, 0, 0));
depth = 20.1;
normal = transform.getQuatRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
}
BOOST_AUTO_TEST_CASE(shapeIntersection_planesphere)
{
Sphere s(10);
Plane hs(Vec3f(1, 0, 0), 0);
Transform3f tf1;
Transform3f tf2;
Transform3f transform;
generateRandomTransform(extents, transform);
Vec3f contact;
FCL_REAL depth;
Vec3f normal;
tf1 = Transform3f();
tf2 = Transform3f();
contact.setZero();
depth = 10;
normal << 1, 0, 0; // (1, 0, 0) or (-1, 0, 0)
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform;
contact = transform.transform(Vec3f(0, 0, 0));
depth = 10;
normal = transform.getRotation() * Vec3f(1, 0, 0); // (1, 0, 0) or (-1, 0, 0)
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(5, 0, 0));
contact << 5, 0, 0;
depth = 5;
normal << 1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(5, 0, 0));
contact = transform.transform(Vec3f(5, 0, 0));
depth = 5;
normal = transform.getRotation() * Vec3f(1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-5, 0, 0));
contact << -5, 0, 0;
depth = 5;
normal << -1, 0, 0;
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = transform;
tf2 = transform * Transform3f(Vec3f(-5, 0, 0));
contact = transform.transform(Vec3f(-5, 0, 0));
depth = 5;
normal = transform.getRotation() * Vec3f(-1, 0, 0);
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, true, &contact, &depth, &normal);
tf1 = Transform3f();
tf2 = Transform3f(Vec3f(-10.1, 0, 0));
testShapeIntersection(s, tf1, hs, tf2, GST_INDEP, false);