示例#1
0
int main()
{
  double V0[] = {1,0,0,1,0,0};
  std::vector<double> Vertices0(V0, V0+6);
  Triangle<2>::SetGlobalCoordinatesArray(Vertices0);
  Triangle<2> P10(1,2,3);
  ShapesP12D::Bulk P10Shapes(&P10);
  
  std::cout << "Parametric triangle\n";
  PrintData(P10Shapes);

  std::cout << "\nTwice Parametric triangle\n";

  double V1[] = {2,0,0,2,0,0};
  std::vector<double> Vertices1(V1, V1+6);
  Triangle<2>::SetGlobalCoordinatesArray(Vertices1);
  Triangle<2> P11(1,2,3);
  ShapesP12D::Bulk P11Shapes(&P11);

  PrintData(P11Shapes);

  std::cout << "\nReordered nodes of  twice parametric triangle\n";

  double V2[] = {0,0,2,0,0,2};
  std::vector<double> Vertices2(V2, V2+6);
  Triangle<2>::SetGlobalCoordinatesArray(Vertices2);
  Triangle<2> P12(1,2,3);
  ShapesP12D::Bulk P12Shapes(&P12);

  PrintData(P12Shapes);

  std::cout << "\n Equilateral triangle with area sqrt(3)\n";

  double V3[] = {0,0,2,0,1,sqrt(3)};
  std::vector<double> Vertices3(V3, V3+6);
  Triangle<2>::SetGlobalCoordinatesArray(Vertices3);
  Triangle<2> P13(1,2,3);
  ShapesP12D::Bulk P13Shapes(&P13);

  PrintData(P13Shapes);

  std::cout << "\n Irregular triangle with area sqrt(3)\n";

  double V4[] = {0,0,2,0,2.5,sqrt(3)};
  std::vector<double> Vertices4(V4, V4+6);
  Triangle<2>::SetGlobalCoordinatesArray(Vertices4);
  Triangle<2> P14(1,2,3);
  ShapesP12D::Bulk P14Shapes(&P14);

  PrintData(P14Shapes);

}
示例#2
0
__CD__BEGIN

Vector3D my_tri_tri_intersect(const Triangle& t1, const Triangle& t2)
{
    Plane p1(t1.v1,t1.v2,t1.v3);
    int other_side=0;
    {
        float f1=p1.Classify(t2.v1);
        float f2=p1.Classify(t2.v2);
        float f3=p1.Classify(t2.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    Plane p2(t2.v1,t2.v2,t2.v3);
    Vector3D n12(p1.normal+p2.normal);
    TriangleDesc td2(t2,p2);
    const Vector3D& a2=td2[other_side+1];
    const Vector3D& b2=td2[other_side];
    const Vector3D& c2=td2[other_side+2];
    float t21=-(p1.d+p2.d+a2*n12)/((b2-a2)*n12);
    TriangleDesc td1(t1,p1);
    Vector3D P21(a2+t21*(b2-a2));
    if (td1.pointInTri(P21)) return P21;
    float t22=-(p1.d+p2.d+c2*n12)/((b2-c2)*n12);
    Vector3D P22(c2+t22*(b2-c2));
    if (td1.pointInTri(P22)) return P22;

    {
        float f1=p2.Classify(t1.v1);
        float f2=p2.Classify(t1.v2);
        float f3=p2.Classify(t1.v3);
        float f12=f1*f2;
        float f23=f2*f3;
        if (f12>0.0f && f23>0.0f) return Vector3D::Zero;
        other_side=(f12<0.0f?(f23<0.0f?1:0):2);
    }
    const Vector3D& a1=td1[other_side+1];
    const Vector3D& b1=td1[other_side];
    const Vector3D& c1=td1[other_side+2];
    float t11=-(p1.d+p2.d+a1*n12)/((b1-a1)*n12);
    Vector3D P11(a1+t11*(b1-a1));
    if (td2.pointInTri(P11)) return P11;
    float t12=-(p1.d+p2.d+c1*n12)/((b1-c1)*n12);
    Vector3D P12(c1+t12*(b1-c1));
    if (td2.pointInTri(P12)) return P12;
    return Vector3D::Zero;
}
示例#3
0
int main() {

  Point center(41,29);

  // The numbering of the nodes corresponds to gslib's output order
  Node P5(38,28,0.5740);
  Node P8(45,29,1.2110);
  Node P4(41,26,2.1270);
  Node P3(39,31,8.3400);
  Node P6(38,31,18.6420);
  Node P2(39,30,7.9380);
  Node P7(39,32,2.2840);
  Node P1(40,31,2.5090);
  Node P9(37,20,0.5740);
  Node P10(25,28,1.2110);
  Node P11(39,26,2.1270);
  Node P12(32,31,8.3400);
  Node P13(30,34,18.6420);
  Node P14(33,35,7.9380);
  Node P15(42,32,2.2840);
  Node P16(31,23,2.5090);

  neighborhood voisin;
  voisin.add_node(P1);
  voisin.add_node(P2);
  voisin.add_node(P3);
  voisin.add_node(P4);
  voisin.add_node(P5);
  voisin.add_node(P6);
  voisin.add_node(P7);
  voisin.add_node(P8);
  voisin.add_node(P9);
  voisin.add_node(P10);
  voisin.add_node(P11);
  voisin.add_node(P12);
  voisin.add_node(P13);
  voisin.add_node(P14);
  voisin.add_node(P15);
  voisin.add_node(P16);
  


  

  typedef matrix_lib_traits<TNT_lib<double> >::Vector TNTvector;

  covariance covar;
  
  //______________________________
  // Simple Kriging
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Simple kriging"
	    << std::endl << std::endl;

  TNTvector SK_weights;
  SK_constraints SK;
  OK_constraints OK;
  double sk_variance;
  

  TNT::stopwatch chrono;
  chrono.start();
  for(int count = 0 ; count < 50000 ; count ++) {
    int change=1;
    if(drand48() <0.5) change = -1;
    (voisin[0].location())[0] += change;
    kriging_weights<GSTL_TNT_lib>(SK_weights,
				  center, voisin,
				  covar, OK );
  }

  chrono.stop();
  std::cout << "time elapsed using Gauss: " << chrono.read() << std::endl;
  
  chrono.reset();
  chrono.start();
  for(int count = 0 ; count < 50000 ; count ++) {
    int change=1;
    if(drand48() <0.5) change = -1;
    voisin[0].property_value() = 0.5*count;
    kriging_weights(SK_weights, 
		    center, voisin,
		    covar, OK );
  }

  chrono.stop();
  std::cout << "time elapsed using LU: " << chrono.read() << std::endl;
  
  
  /*
  //______________________________
  // Ordinary Kriging
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Ordinary kriging"
	    << std::endl << std::endl;

  TNTvector OK_weights;
  OK_constraints OK;
  double ok_variance;
  status = kriging_weights(OK_weights, ok_variance,
			   center, voisin,
			   covar, OK);
						   
  std::cout << "Here are the weights:" << std::endl
	    << OK_weights << std::endl;

  
  

  //______________________________
  // Kriging with Trend
  //______________________________

  std::cout << std::endl <<std::endl;
  std::cout << "____________________________________________" 
	    << std::endl
	    << "Kriging with Trend"
	    << std::endl << std::endl;
  
  TNTvector KT_weights;
  KT_constraints<functIter> KT(functArray.begin(),functArray.end());
  double kt_variance;
  status = kriging_weights(KT_weights, kt_variance,
			   center, voisin,
			   covar, KT);

						  
  std::cout << "Here are the weights:" << std::endl
	    << KT_weights << std::endl;

  */

  return 0;


}