5
#include "CollisionPairInserter.h"
11
using namespace cnoid;
15
const bool HIRUKAWA_DEBUG = false;
17
/* used in normal_test */
18
enum { NOT_INTERSECT = 0,
19
EDGE1_NOT_INTERSECT = 1,
20
EDGE2_NOT_INTERSECT = 2,
21
EDGE3_NOT_INTERSECT = 3 };
23
/* used in cross_test */
24
const int INTERSECT = 1;
28
/**********************************************************
29
separability test by the supporting plane of a triangle
32
1 : f1 or e1 doesn't intersect
33
2 : f2 or e2 doesn't intersect
34
3 : f3 or e3 doesn't intersect
35
**********************************************************/
36
static int separability_test_by_face(const Vector3& nm)
38
if(nm[0] < 0.0 && nm[1] < 0.0 && nm[2] < 0.0 ||
39
nm[0] > 0.0 && nm[1] > 0.0 && nm[2] > 0.0){
42
if(nm[0] < 0.0 && nm[1] < 0.0 && nm[2] > 0.0 ||
43
nm[0] > 0.0 && nm[1] > 0.0 && nm[2] < 0.0){
44
return EDGE1_NOT_INTERSECT;
46
if(nm[0] < 0.0 && nm[1] > 0.0 && nm[2] > 0.0 ||
47
nm[0] > 0.0 && nm[1] < 0.0 && nm[2] < 0.0){
48
return EDGE2_NOT_INTERSECT;
50
if(nm[0] > 0.0 && nm[1] < 0.0 && nm[2] > 0.0 ||
51
nm[0] < 0.0 && nm[1] > 0.0 && nm[2] < 0.0){
52
return EDGE3_NOT_INTERSECT;
58
/**********************************************************
60
normal vector is cross product of ei*fj
61
***********************************************************/
62
static int triangle_inside_test(
71
double ef1P1 = ef1.dot(P1); /*project P1 on ef1*/
72
double ef1P3 = ef1.dot(P3); /*project P3 on ef1*/
73
double ef1Q = ef1.dot(Q); /*project Q on ef1*/
75
double ef2P2 = ef2.dot(P2); /*project P2 on ef2*/
76
double ef2P1 = ef2.dot(P1); /*project P1 on ef2*/
77
double ef2Q = ef2.dot(Q); /*project Q on ef2*/
79
double ef3P3 = ef3.dot(P3); /*project P3 on ef3*/
80
double ef3P2 = ef3.dot(P2); /*project P2 on ef3*/
81
double ef3Q = ef3.dot(Q); /*project Q on ef3*/
83
if((ef1P3 > ef1P1 && ef1Q > ef1P1 ||
84
ef1P3 < ef1P1 && ef1Q < ef1P1 )
86
(ef2P1 > ef2P2 && ef2Q > ef2P2 ||
87
ef2P1 < ef2P2 && ef2Q < ef2P2 )
89
(ef3P2 > ef3P3 && ef3Q > ef3P3 ||
90
ef3P2 < ef3P3 && ef3Q < ef3P3 )) {
98
static void find_intersection_pt(
105
if(mn1 == mn2) /*exit(0);*/ return;
107
if(mn1 >0 && mn2 < 0){
108
ipt = (-(mn2*x1) + mn1*x2)/(mn1-mn2);
109
}else if(mn1 < 0 && mn2 > 0){
110
ipt = (mn2*x1 - mn1*x2)/(-mn1+mn2);
115
static inline void find_intersection_pt(
121
ipt = (1.0 - p) * x1 + p * x2;
124
cout << "v1 = " << x1[0] << ", " << x1[1] << ", " << x1[2] << endl;
125
cout << "v2 = " << x2[0] << ", " << x2[1] << ", " << x2[2] << endl;
126
cout << "edge = " << x2[0]-x1[0] << ", " << x2[1]-x1[1] << ", "
127
<< x2[2]-x1[2] << endl;
128
cout << "common pt = " << ipt[0] << " " << ipt[1] << " " << ipt[2] << endl;
134
// Calculate the depth of the intersection between two triangles
136
static inline double calc_depth(
144
cout << "calc_depth 1 = " << (ip1 - ip2).dot(n) << endl;
147
return fabs((ip1 - ip2).dot(n));
151
static double calc_depth(
157
double d1 = fabs((ip - pt1).dot(n));
158
double d2 = fabs((ip - pt2).dot(n));
159
double depth = (d1 < d2) ? d1 : d2;
162
cout << "calc_depth 2 = " << depth << endl;
169
static double calc_depth(
177
// when a triangle penetrates another triangle at two intersection points
178
// and the separating plane is the supporting plane of the penetrated triangle
182
double d1 = fabs((ip1 - pt1).dot(n));
183
double d2 = fabs((ip2 - pt2).dot(n));
184
double d3 = fabs((ip1 - pt3).dot(n)); // ip1 can be either ip1 or ip2
186
double depth = (d1 < d2) ? d2 : d1;
192
cout << "calc_depth 3 = " << depth << endl;
199
static void find_foot(
208
u = pt2[0] - pt1[0]; v = pt2[1] - pt1[1]; w = pt2[2] - pt1[2];
210
p = u * (ip[0] - pt1[0]) + v * (ip[1] - pt1[1]) + w * (ip[2] - pt1[2]);
211
p /= u * u + v * v + w * w;
213
f[0] = pt1[0] + u * p; f[1] = pt1[1] + v * p; f[2] = pt1[2] + w * p;
216
const Vector3 pt = pt2 - pt1;
217
const double p = pt.dot(ip - pt1) / pt.dot(pt);
222
static double calc_depth(
229
Vector3 f12, f23, f31;
231
find_foot(ip, pt1, pt2, f12);
232
find_foot(ip, pt2, pt3, f23);
233
find_foot(ip, pt3, pt1, f31);
236
cout << "ip = " << ip[0] << " " << ip[1] << " " << ip[2] << endl;
237
cout << "f12 = " << f12[0] << " " << f12[1] << " " << f12[2] << endl;
238
cout << "f23 = " << f23[0] << " " << f23[1] << " " << f23[2] << endl;
239
cout << "f31 = " << f31[0] << " " << f31[1] << " " << f31[2] << endl;
242
// fabs() is taken to cope with numerical error of find_foot()
243
const double d1 = fabs((f12 - ip).dot(n));
244
const double d2 = fabs((f23 - ip).dot(n));
245
const double d3 = fabs((f31 - ip).dot(n));
247
// cout << "d1 d2 d3 = " << d1 << " " << d2 << " " << d3 << endl;
248
// dsum = fabs(d1)+fabs(d2)+fabs(d3);
249
// if(d1<0.0) d1=dsum; if(d2<0.0) d2=dsum; if(d3<0.0) d3=dsum;
251
double depth = (d1 < d2) ? d1 : d2;
257
cout << "calc_depth 4 = " << depth << endl;
264
static double calc_depth2(
272
// when a triangle penetrates another triangle at two intersecting points
273
// and the separating plane is the supporting plane of the penetrating triangle
275
const Vector3 nn(n); // vecNormalize(nn);
277
const double depth1 = calc_depth(ip1, pt1, pt2, pt3, nn);
278
const double depth2 = calc_depth(ip2, pt1, pt2, pt3, nn);
280
// cout << "depth1 depth2 = " << depth1 << " " << depth2 << endl;
281
const double depth = (depth1 < depth2) ? depth2 : depth1;
284
cout << "calc_depth 5 = " << depth << endl;
291
static void calcNormal(
298
// find the vector from v1 to the mid point of v2 and v3 when 0<sgn
301
vec = -(v1 - 0.5 * (v2 + v3)).normalized();
303
vec = (v1 - 0.5 * (v2 + v3)).normalized();
308
static int find_common_perpendicular(
317
const Vector3& n_vector,
320
const double eps = 1.0e-3; // threshold to consider two edges are parallel
321
const double vn = 1.0e-2; // threshold to judge an intersecting point is near a vertex
323
const Vector3 e = p2 - p1;
324
const Vector3 f = q2 - q1;
326
const double c11 = e.dot(e);
327
const double c12 = - e.dot(f);
328
const double c21 = - c12;
329
const double c22 = - f.dot(f);
331
const double det = c11 * c22 - c12 * c21;
332
// cout << "det = " << det << endl;
337
const Vector3 g = q1 - p1;
338
const double a = e.dot(g);
339
const double b = f.dot(g);
340
const double t1 = ( c22 * a - c12 * b) / det;
341
const double t2 = (-c21 * a + c11 * b) / det;
343
// quit if the foot of the common perpendicular is not on an edge
344
if(t1<0 || 1<t1 || t2<0 || 1<t2) return 0;
346
// when two edges are in contact near a vertex of an edge
347
// if(t1<vn || 1.0-vn<t1 || t2<vn || 1.0-vn<t2) return 0;
349
// find_intersection_pt(v1, p1, p2, t1);
350
// find_intersection_pt(v2, q1, q2, t2);
352
dp = calc_depth(ip1, ip2, n_vector);
359
// for vertex-face contact
360
static inline int get_normal_vector_test(
368
// ip1 and ip2 are the intersecting points
369
// v1 and v2 are the vertices of the penetrating triangle
370
// note that (v1-ip1) (v2-ip2) lies on the penetrating triangle
372
// eps_applicability = 0.965926; // Cos(15) threshold to consider two triangles face
373
const double eps_applicability = 0.5; // Cos(60) threshold to consider two triangles face
375
// This condition should be checked mildly because the whole sole of a foot
376
// may sink inside the floor and then no collision is detected.
377
return (eps_applicability < n1.dot(m1)) ? 0 : 1;
381
// for edge-edge contact
382
static int get_normal_vector_test(
396
// ip is the intersecting point on triangle p1p2p3
397
// iq is the intersecting point on triangle q1q2q3
398
// v1 is the vertex of p1p2p3 which is not on the intersecting edge
399
// v2 is the vertex of q1q2q3 which is not on the intersecting edge
400
// note that (v1-ip) lies on triangle p1p2p3 and (v2-iq) on q1q2q3
402
const double eps_applicability = 0.0; // 1.52e-2; // threshold to consider two triangles face
403
const double eps_length = 1.0e-3; // 1mm: thereshold to consider the intersecting edge is short
404
const double eps_theta = 1.0e-1; // threshold to consider cos(theta) is too small
406
// quit if two triangles does not satifsy the applicability condition
407
// i.e. two triangles do not face each other
408
if(- eps_applicability < n1.dot(m1)) return 0;
410
const double ea_length = (va1 - va2).norm();
411
const double eb_length = (vb1 - vb2).norm();
413
// return the normal vector of a triangle if an intersecting edge is too short
414
if(ea_length < eps_length || eb_length < eps_length){
415
// cout << "edge is too short" << endl;
416
if(ea_length < eb_length) {
424
const Vector3 sv1 = v1 - ip;
425
const double sv1_norm = sv1.norm();
426
const Vector3 sv2 = v2 - iq;
427
const double sv2_norm = sv2.norm();
429
if(eps_length < sv1_norm && eps_length < sv2_norm){
430
// quit if two triangles do not satisfy the applicability conditions
431
if(- eps_applicability < sv1.dot(sv2) / (sv1_norm * sv2_norm)){
436
// now neither of two edges is not too short
437
Vector3 ef = ef0.normalized();
440
const double theta1 = ef.dot(n1) / n1.norm();
441
const double theta1_abs = fabs(theta1);
445
if(eps_length < sv1_norm){
446
theta2 = ef.dot(sv1) / sv1_norm;
447
theta2_abs = fabs(theta2);
454
const double theta3 = ef.dot(m1) / m1.norm();
455
const double theta3_abs = fabs(theta3);
459
if(eps_length < sv2_norm){
460
theta4 = ef.dot(sv2) / sv2_norm;
461
theta4_abs = fabs(theta4);
467
if(sv1_norm < eps_length || sv2_norm < eps_length){
468
// when sv1 or sv2 is too short
469
// cout << "sv is too short" << endl;
470
if(theta1_abs < theta3_abs){
478
if(theta2_abs < eps_theta && theta4_abs < eps_theta){
479
// when two triangles are coplanar
481
// ef = (va2-va1)x(vb2-vb1) (1)
484
// substituting (1) to (2),
485
// sv1 * (va2-va1) x (vb2-vb1) = 0
486
// (vb2 - vb1) * sv1 x (va2 - va1) = 0
487
// considering sv1 x (va2 - va1) = n,
488
// (vb2 - vb1) * n = 0
490
// (va2 - va1) * m = 0
493
if(theta1_abs < theta3_abs){
502
// return 0 if the plane which passes through ip with normal vector ef
503
// does not separate v1 and v2
504
if(-eps_applicability < theta2 * theta4) return 0;
510
if(theta1_abs < theta2_abs){
513
theta12 = -1.0 * theta1;
517
if(theta3_abs < theta4_abs){
518
theta34 = -1.0 * theta4;
524
if(fabs(theta12) < fabs(theta34)){
537
cout << "va1=" << va1[0] << " " << va1[1] << " " << va1[2] << endl;
538
cout << "va2=" << va2[0] << " " << va2[1] << " " << va2[2] << endl;
539
cout << "va3=" << v1[0] << " " << v1[1] << " " << v1[2] << endl;
540
cout << "vb1=" << vb1[0] << " " << vb1[1] << " " << vb1[2] << endl;
541
cout << "vb2=" << vb2[0] << " " << vb2[1] << " " << vb2[2] << endl;
542
cout << "vb3=" << v2[0] << " " << v2[1] << " " << v2[2] << endl;
543
cout << "n1=" << n1[0] << " " << n1[1] << " " << n1[2] << endl;
544
cout << "m1=" << m1[0] << " " << m1[1] << " " << m1[2] << endl;
545
cout << "ef=" << ef[0] << " " << ef[1] << " " << ef[2] << endl;
546
cout << "sv1=" << sv1[0] << " " << sv1[1] << " " << sv1[2] << endl;
547
cout << "sv2=" << sv2[0] << " " << sv2[1] << " " << sv2[2] << endl;
551
if(n_vector.dot(sv1) < eps_applicability || - eps_applicability < n_vector.dot(sv2)){
552
// when the separating plane separates the outsides of the triangles
561
// find the collision info when a vertex penetrates a face
563
static int find_collision_info(
580
Vector3& ip5, /* unused ? */
581
Vector3& ip6, /* unused ? */
582
collision_data* col_p, double pq)
585
find_intersection_pt(ip1, p1, p2, mp0, mp1);
587
find_intersection_pt(ip2, p3, p1, mp2, mp0);
589
if(get_normal_vector_test(ip1, p2, ip2, p3, m1, n1)){
592
calcNormal(vec, p1, p2, p3, mp0);
594
col_p->n_vector = m1 * pq;
597
// The depth is estimated in InsertCollisionPair.cpp
598
// The following depth calculation is done only for debugging purpose
600
col_p->depth = calc_depth(ip1, ip2, p2, p3, p1, col_p->n_vector);
601
const Vector3 nv = -n1 * pq;
602
const double dp = calc_depth2(ip1, ip2, q1, q2, q3, nv);
603
if(dp < col_p->depth){
607
ip3 = ip1; ip4 = ip2;
608
col_p->num_of_i_points = 2;
618
// find the collision info when an edges penetrate a face each other
620
static int find_collision_info(
636
collision_data *col_p)
639
find_intersection_pt(ip1, q1, q2, nq0, nq1);
641
find_intersection_pt(ip2, p1, p2, mp0, mp1);
644
if(get_normal_vector_test(col_p->n_vector, ef11, ip2, ip1, p3, q3, n1, m1, p1, p2, q1, q2) &&
645
find_common_perpendicular(p1, p2, q1, q2, ip1, ip2, n1, m1, col_p->n_vector, dp)){
647
ip3 = ip1; ip4 = ip2;
648
col_p->num_of_i_points = 2;
657
// very robust triangle intersection test
659
// works on coplanar triangles
668
collision_data* col_p,
669
CollisionPairInserter* collisionPairInserter)
672
One triangle is (p1,p2,p3). Other is (q1,q2,q3).
673
Edges are (e1,e2,e3) and (f1,f2,f3).
674
Normals are n1 and m1
675
Outwards are (g1,g2,g3) and (h1,h2,h3).
677
We assume that the triangle vertices are in the same coordinate system.
679
First thing we do is establish a new c.s. so that p1 is at (0,0,0).
686
// Vector3 g1, g2, g3;
687
// Vector3 h1, h2, h3;
693
int edf1, edf2, edf3, ede1, ede2, ede3;
695
Vector3 ef11, ef12, ef13;
696
Vector3 ef21, ef22, ef23;
697
Vector3 ef31, ef32, ef33;
699
/* intersection point R is a flag which tri P & Q correspond or not */
700
Vector3 ip,ip3,ip4,ip5,ip6;
703
const int FV = 1; // face-vertex contact type
704
const int VF = 2; // vertex-face contact type
705
const int EE = 3; // edge-edge contact type
728
// now begin the series of tests
730
/*************************************
731
separability test by face
732
************************************/
737
triQ = separability_test_by_face(nq);
739
if(triQ == NOT_INTERSECT) return 0;
741
double mq = m1.dot(q1);
742
mp[0] = m1.dot(p1) - mq;
743
mp[1] = m1.dot(p2) - mq;
744
mp[2] = m1.dot(p3) - mq;
745
triP = separability_test_by_face(mp);
746
if(triP == NOT_INTERSECT) return 0;
758
edf1 = 0; edf2 = 0; edf3 = 0; ede1 = 0; ede2 = 0; ede3 = 0;
760
/********************************
762
*********************************/
768
case EDGE1_NOT_INTERSECT:
769
edf2 = triangle_inside_test(ef12,ef22,ef32,p3,p1,p2,q2);
770
edf3 = triangle_inside_test(ef13,ef23,ef33,p3,p1,p2,q3);
773
case EDGE2_NOT_INTERSECT:
774
edf1 = triangle_inside_test(ef11,ef21,ef31,p3,p1,p2,q1);
775
edf3 = triangle_inside_test(ef13,ef23,ef33,p3,p1,p2,q3);
778
case EDGE3_NOT_INTERSECT:
779
edf1 = triangle_inside_test(ef11,ef21,ef31,p3,p1,p2,q1);
780
edf2 = triangle_inside_test(ef12,ef22,ef32,p3,p1,p2,q2);
784
int num_of_edges = edf1 + edf2 + edf3;
785
if(num_of_edges == 3){
790
if(num_of_edges < 2){
793
case EDGE1_NOT_INTERSECT:
794
ede2 = triangle_inside_test(ef21, ef22, ef23, q3, q1, q2, p2);
795
ede3 = triangle_inside_test(ef31, ef32, ef33, q3, q1, q2, p3);
796
if(ede2 + ede3 == 2){
797
edf1 = NOT_INTERSECT;
798
edf2 = NOT_INTERSECT;
799
edf3 = NOT_INTERSECT;
803
case EDGE2_NOT_INTERSECT:
804
ede1 = triangle_inside_test(ef11, ef12, ef13, q3, q1, q2, p1);
805
ede3 = triangle_inside_test(ef31, ef32, ef33, q3, q1, q2, p3);
806
if(ede1 + ede3 == 2){
807
edf1 = NOT_INTERSECT;
808
edf2 = NOT_INTERSECT;
809
edf3 = NOT_INTERSECT;
813
case EDGE3_NOT_INTERSECT:
814
ede1 = triangle_inside_test(ef11, ef12, ef13, q3, q1, q2, p1);
815
ede2 = triangle_inside_test(ef21, ef22, ef23, q3, q1, q2, p2);
816
if(ede1 + ede2 == 2){
817
edf1 = NOT_INTERSECT;
818
edf2 = NOT_INTERSECT;
819
edf3 = NOT_INTERSECT;
823
if(num_of_edges == 0 && (ede1 + ede2 + ede3) == 3){
829
int num = edf1 + edf2 + edf3 + ede1 + ede2 + ede3;
831
// cout << "no edge intersect" << endl;
835
printf("err of edge detection....");
843
/*********************************
844
find intersection points
845
**********************************/
847
if(edf1 == INTERSECT){
848
find_intersection_pt(ip, q1, q2, nq[0], nq[1]);
850
col_p->n_vector = -n1;
854
} else if(edf2 == INTERSECT){
855
find_intersection_pt(ip, q2, q3, nq[1], nq[2]);
857
col_p->n_vector = -n1;
861
} else if(edf3 == INTERSECT){
862
find_intersection_pt(ip, q3, q1, nq[2], nq[0]);
864
col_p->n_vector = -n1;
868
} else if(ede1 == INTERSECT){
869
find_intersection_pt(ip, p1, p2, mp[0], mp[1]);
871
col_p->n_vector = m1;
875
} else if(ede2 == INTERSECT){
876
find_intersection_pt(ip, p2, p3, mp[1], mp[2]);
878
col_p->n_vector = m1;
882
} else if(ede3 == INTERSECT){
883
find_intersection_pt(ip, p3, p1, mp[2], mp[0]);
885
col_p->n_vector = m1;
889
col_p->num_of_i_points = 1;
891
} else if(num == 2) {
892
if(edf1 == INTERSECT && edf2 == INTERSECT){
893
if(HIRUKAWA_DEBUG) cout << "f1 f2" << endl;
895
if(!find_collision_info(q2,q1,q3,nq[1],nq[0],nq[2],p1,p2,p3,e1,e2,e3,
896
m1,n1,ip3,ip4,ip5,ip6,col_p,-1.0)){
899
} else if(edf1 == INTERSECT && edf3 == INTERSECT){
900
if(HIRUKAWA_DEBUG) cout << "f1 f3" << endl;
902
if(!find_collision_info(q1,q2,q3,nq[0],nq[1],nq[2],p1,p2,p3,e1,e2,e3,
903
m1,n1,ip3,ip4,ip5,ip6,col_p,-1.0)){
906
} else if(ede1 == INTERSECT && edf1 == INTERSECT){
907
if(HIRUKAWA_DEBUG) cout << "e1 f1" << endl;
909
if(!find_collision_info(p1,p2,p3,mp[0],mp[1],q1,q2,q3,nq[0],nq[1],ef11,
910
n1,m1,ip3,ip4,col_p)){
913
} else if(ede2 == INTERSECT && edf1 == INTERSECT){
914
if(HIRUKAWA_DEBUG) cout << "e2 f1" << endl;
916
if(!find_collision_info(p2,p3,p1,mp[1],mp[2],q1,q2,q3,nq[0],nq[1],ef21,
917
n1,m1,ip3,ip4,col_p)){
920
} else if(ede3 == INTERSECT && edf1 == INTERSECT){
921
if(HIRUKAWA_DEBUG) cout << "e3 f1" << endl;
923
if(!find_collision_info(p3,p1,p2,mp[2],mp[0],q1,q2,q3,nq[0],nq[1],ef31,
924
n1,m1,ip3,ip4,col_p)){
927
} else if(edf2 == INTERSECT && edf3 == INTERSECT){
928
if(HIRUKAWA_DEBUG) cout << "f2 f3" << endl;
930
if(!find_collision_info(q3,q2,q1,nq[2],nq[1],nq[0],p1,p2,p3,e1,e2,e3,
931
m1,n1,ip3,ip4,ip5,ip6,col_p,-1.0)){
934
} else if(ede1 == INTERSECT && edf2 == INTERSECT){
935
if(HIRUKAWA_DEBUG) cout << "e1 f2" << endl;
937
if(!find_collision_info(p1,p2,p3,mp[0],mp[1],q2,q3,q1,nq[1],nq[2],ef12,
938
n1,m1,ip3,ip4,col_p)){
941
} else if(ede2 == INTERSECT && edf2 == INTERSECT){
942
if(HIRUKAWA_DEBUG) cout << "e2 f2" << endl;
944
if(!find_collision_info(p2,p3,p1,mp[1],mp[2],q2,q3,q1,nq[1],nq[2],ef22,
945
n1,m1,ip3,ip4,col_p)){
948
} else if(ede3 == INTERSECT && edf2 == INTERSECT){
949
if(HIRUKAWA_DEBUG) cout << "e3 f2" << endl;
951
if(!find_collision_info(p3,p1,p2,mp[2],mp[0],q2,q3,q1,nq[1],nq[2],ef32,
952
n1,m1,ip3,ip4,col_p)){
955
} else if(ede1 == INTERSECT && edf3 == INTERSECT){
956
if(HIRUKAWA_DEBUG) cout << "e1 f3" << endl;
958
if(!find_collision_info(p1,p2,p3,mp[0],mp[1],q3,q1,q2,nq[2],nq[0],ef13,
959
n1,m1,ip3,ip4,col_p)){
962
} else if(ede2 == INTERSECT && edf3 == INTERSECT){
963
if(HIRUKAWA_DEBUG) cout << "e2 f3" << endl;
965
if(!find_collision_info(p2,p3,p1,mp[1],mp[2],q3,q1,q2,nq[2],nq[0],ef23,
966
n1,m1,ip3,ip4,col_p)){
969
} else if(ede3 == INTERSECT && edf3 == INTERSECT){
970
if(HIRUKAWA_DEBUG) cout << "e3 f3" << endl;
972
if(!find_collision_info(p3,p1,p2,mp[2],mp[0],q3,q1,q2,nq[2],nq[0],ef33,
973
n1,m1,ip3,ip4,col_p)){
976
} else if(ede1 == INTERSECT && ede2 == INTERSECT){
977
if(HIRUKAWA_DEBUG) cout << "e1 e2" << endl;
979
if(!find_collision_info(p2,p1,p3,mp[1],mp[0],mp[2],q1,q2,q3,f1,f2,f3,
980
n1,m1,ip3,ip4,ip5,ip6,col_p,1.0)){
983
} else if(ede1 == INTERSECT && ede3 == INTERSECT){
984
if(HIRUKAWA_DEBUG) cout << "e1 e3" << endl;
986
if(!find_collision_info(p1,p2,p3,mp[0],mp[1],mp[2],q1,q2,q3,f1,f2,f3,
987
n1,m1,ip3,ip4,ip5,ip6,col_p,1.0)){
990
} else if(ede2 == INTERSECT && ede3 == INTERSECT){
991
if(HIRUKAWA_DEBUG) cout << "e2 e3" << endl;
993
if(!find_collision_info(p3,p2,p1,mp[2],mp[1],mp[0],q1,q2,q3,f1,f2,f3,
994
n1,m1,ip3,ip4,ip5,ip6,col_p,1.0)){
1000
if(col_p->num_of_i_points == 1){
1001
col_p->i_points[0] = ip3 + P1;
1003
else if(col_p->num_of_i_points == 2){
1004
col_p->i_points[0] = ip3 + P1;
1005
col_p->i_points[1] = ip4 + P1;
1007
else if(col_p->num_of_i_points == 3){
1008
col_p->i_points[0] = ip3 + P1;
1009
col_p->i_points[1] = ip4 + P1;
1010
col_p->i_points[2] = ip5 + P1;
1012
else if(col_p->num_of_i_points == 4){
1013
col_p->i_points[0] = ip3 + P1;
1014
col_p->i_points[1] = ip4 + P1;
1015
col_p->i_points[2] = ip5 + P1;
1016
col_p->i_points[3] = ip5 + P1;
1024
CollisionPairInserter& c = *collisionPairInserter;
1026
Vector3 p1w = c.CD_s2 * (c.CD_Rot2 * P1 + c.CD_Trans2);
1027
Vector3 p2w = c.CD_s2 * (c.CD_Rot2 * P2 + c.CD_Trans2);
1028
Vector3 p3w = c.CD_s2 * (c.CD_Rot2 * P3 + c.CD_Trans2);
1029
Vector3 q1w = c.CD_s2 * (c.CD_Rot2 * Q1 + c.CD_Trans2);
1030
Vector3 q2w = c.CD_s2 * (c.CD_Rot2 * Q2 + c.CD_Trans2);
1031
Vector3 q3w = c.CD_s2 * (c.CD_Rot2 * Q3 + c.CD_Trans2);
1032
cout << "P1 = " << p1w[0] << " " << p1w[1] << " " << p1w[2] << endl;
1033
cout << "P2 = " << p2w[0] << " " << p2w[1] << " " << p2w[2] << endl;
1034
cout << "P3 = " << p3w[0] << " " << p3w[1] << " " << p3w[2] << endl;
1035
cout << "Q1 = " << q1w[0] << " " << q1w[1] << " " << q1w[2] << endl;
1036
cout << "Q2 = " << q2w[0] << " " << q2w[1] << " " << q2w[2] << endl;
1037
cout << "Q3 = " << q3w[0] << " " << q3w[1] << " " << q3w[2] << endl;
1039
for(int i=0; i<col_p->num_of_i_points; i++){
1040
i_pts_w[i] = c.CD_s2 * ((c.CD_Rot2 * col_p->i_points[i]) + c.CD_Trans2);
1041
cout << i << "-th intersecting point = ";
1042
cout << i_pts_w[i][0] << " " << i_pts_w[i][1] << " " << i_pts_w[i][2] << endl;
1045
cout << "n1 = " << n1[0] << " " << n1[1] << " " << n1[2] << endl;
1046
cout << "m1 = " << m1[0] << " " << m1[1] << " " << m1[2] << endl;
1047
cout << "mp[0] mp[1] mp[2] = " << mp[0] << " " << mp[1] << " " << mp[2] << endl;
1048
cout << "nq[0] nq[1] nq[2] = " << nq[0] << " " << nq[1] << " " << nq[2] << endl;
1049
cout << "n_vector = " << col_p->n_vector[0] << " " << col_p->n_vector[1]
1050
<< " " << col_p->n_vector[2] << endl;
1051
cout << "depth = " << col_p->depth << endl << endl;;
1056
printf("intersect point...in tri_contact..\n");
1057
printf(" ip1x = %f ip1y = %f ip1z = %f\n ip2x = %f ip2y = %f ip2z = %f\n",
1058
col_p->i_points[0][0],col_p->i_points[0][1],col_p->i_points[0][2],
1059
col_p->i_points[1][0],col_p->i_points[1][1],col_p->i_points[1][2]);
1061
printf("normal vector....it tri_conctact..\n");
1062
printf("N[0] = %f,N[1] = %f,N[2] = %f\n",col_p->n_vector[0],col_p->n_vector[1],col_p->n_vector[2]);