- //cout<<"HasIntersection3"<<endl;
- //cout<<" PC("<<PC.X()<<","<<PC.Y()<<","<<PC.Z()<<")"<<endl;
- //cout<<" P("<<P.X()<<","<<P.Y()<<","<<P.Z()<<")"<<endl;
- //cout<<" P1("<<P1.X()<<","<<P1.Y()<<","<<P1.Z()<<")"<<endl;
- //cout<<" P2("<<P2.X()<<","<<P2.Y()<<","<<P2.Z()<<")"<<endl;
- //cout<<" P3("<<P3.X()<<","<<P3.Y()<<","<<P3.Z()<<")"<<endl;
- gp_Vec VP1(P1,P2);
- gp_Vec VP2(P1,P3);
- IntAna_Quadric IAQ(gp_Pln(P1,VP1.Crossed(VP2)));
- IntAna_IntConicQuad IAICQ(gp_Lin(PC,gp_Dir(gp_Vec(PC,P))),IAQ);
- if(IAICQ.IsDone()) {
- if( IAICQ.IsInQuadric() )
- return false;
- if( IAICQ.NbPoints() == 1 ) {
- gp_Pnt PIn = IAICQ.Point(1);
- const double preci = 1.e-10 * P.Distance(PC);
- // check if this point is internal for segment [PC,P]
- bool IsExternal =
- ( (PC.X()-PIn.X())*(P.X()-PIn.X()) > preci ) ||
- ( (PC.Y()-PIn.Y())*(P.Y()-PIn.Y()) > preci ) ||
- ( (PC.Z()-PIn.Z())*(P.Z()-PIn.Z()) > preci );
- if(IsExternal) {
- return false;
- }
- // check if this point is internal for triangle (P1,P2,P3)
- gp_Vec V1(PIn,P1);
- gp_Vec V2(PIn,P2);
- gp_Vec V3(PIn,P3);
- if( V1.Magnitude()<preci ||
- V2.Magnitude()<preci ||
- V3.Magnitude()<preci ) {
- Pint = PIn;
- return true;
- }
- const double angularTol = 1e-6;
- gp_Vec VC1 = V1.Crossed(V2);
- gp_Vec VC2 = V2.Crossed(V3);
- gp_Vec VC3 = V3.Crossed(V1);
- if(VC1.Magnitude()<gp::Resolution()) {
- if(VC2.IsOpposite(VC3,angularTol)) {
- return false;
- }
- }
- else if(VC2.Magnitude()<gp::Resolution()) {
- if(VC1.IsOpposite(VC3,angularTol)) {
- return false;
- }
- }
- else if(VC3.Magnitude()<gp::Resolution()) {
- if(VC1.IsOpposite(VC2,angularTol)) {
- return false;
- }
- }
- else {
- if( VC1.IsOpposite(VC2,angularTol) || VC1.IsOpposite(VC3,angularTol) ||
- VC2.IsOpposite(VC3,angularTol) ) {
- return false;
- }
- }
- Pint = PIn;
- return true;
- }
- }