Package com.nr.cg

Examples of com.nr.cg.Point


public class Sphcirc {
  public Point center;
  public double radius;
 
  public Sphcirc(final int dim) {
    center = new Point(dim);
  }
View Full Code Here


    boxes = new Boxnode[nboxes];
    coords = new double[DIM*npts];
    for (j=0, kk=0; j<DIM; j++, kk += npts) {
      for (k=0; k<npts; k++) coords[kk+k] = pts[k].x[j];
    }
    Point lo = new Point(DIM, new double[]{-BIG,-BIG,-BIG});
    Point hi = new Point(DIM, new double[]{BIG,BIG,BIG});
    boxes[0] = new Boxnode(lo, hi, 0, 0, 0, 0, npts-1);
    jbox = 0;
    taskmom[1] = 0;
    taskdim[1] = 0;
    nowtask = 1;
    while (nowtask!=0) {
      tmom = taskmom[nowtask];
      tdim = taskdim[nowtask--];
      ptlo = boxes[tmom].ptlo;
      pthi = boxes[tmom].pthi;
      //hp = &ptindx[ptlo];
      //cp = &coords[tdim*npts];
      np = pthi - ptlo + 1;
      kk = (np-1)/2;
      selecti(kk,ptindx,ptlo,np,coords,tdim*npts);
     
      // XXX = change to copyAssign
      hi.copyAssign(boxes[tmom].hi);
      lo.copyAssign(boxes[tmom].lo);
     
      hi.x[tdim] = lo.x[tdim] = coords[tdim*npts + ptindx[ptlo+kk]];
      boxes[++jbox] = new Boxnode(boxes[tmom].lo,hi,tmom,0,0,ptlo,ptlo+kk);
      boxes[++jbox] = new Boxnode(lo,boxes[tmom].hi,tmom,0,0,ptlo+kk+1,pthi);
View Full Code Here

    System.out.println("Testing Voredge");

    Ran myran=new Ran(17);
    Point[] points=new Point[NPTS];
    for (i=0;i<NPTS;i++)
      points[i]=new Point(myran.doub(),myran.doub());

    Voronoi.Voredge v = new Voronoi.Voredge(points[0],points[1],2);

    localflag = dist(v.p[0],points[0]) > sbeps;
    globalflag = globalflag || localflag;
View Full Code Here

  @Test
  public void test() {
    int i,nwind,N=14;
    double x0[]={-1.0,-1.0,1.0,1.0,-0.75,-0.75,0.75,0.75,-0.5,-0.5,0.5,0.5,0.0,0.0};
    double x1[]={0.0,1.0,1.0,-1.0,-1.0,0.75,0.75,-0.75,-0.75,0.5,0.5,-0.5,-0.5,0.0};
    Point test=new Point(2);
    Point[] poly=new Point[N];
    for(i=0;i<N;i++)
      poly[i]= new Point(2);
    boolean localflag, globalflag=false;

    // Test polywind
    System.out.println("Testing polywind (note: CW = Clockwise)");
View Full Code Here

    // Test Qotree in 2D
    Qotree qotree2 = new Qotree(2,N,N,5);

    // Test setouterbox in 2D
    Point lo2=new Point(0.0,0.0),hi2=new Point(1.0,1.0);
    qotree2.setouterbox(lo2,hi2);

    // Test qobox in 2D
    Box b2=new Box(2);
    b2=qotree2.qobox(1);
//    System.out.printf(dist(b2.lo,lo2));
    localflag = dist(b2.lo,lo2) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Outer box lower corner improperly set");
     
    }

//    System.out.printf(dist(b2.hi,hi2));
    localflag = dist(b2.hi,hi2) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Outer box upper corner improperly set");
     
    }

    Point half=new Point(hi2.x[0]/2.0,hi2.x[1]/2.0);

    b2=qotree2.qobox(2);
//    System.out.printf(dist(b2.hi,half));
    localflag = dist(b2.hi,half) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Box 2 upper corner should be in center of outer box");
     
    }

    b2=qotree2.qobox(5);
//    System.out.printf(dist(b2.lo,half));
    localflag = dist(b2.lo,half) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Box 5 lower corner should be in center of outer box");
     
    }

    // Test qowhichbox in 2D
    Sphcirc s2 = new Sphcirc(2);
    s2.center=new Point(5.5/16.0,10.5/16.0);
    int ans[]={1,4,15,239};
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      nbox=qotree2.qowhichbox(s2);
//      System.out.printf(s2.radius << " %f\n", nbox);

      localflag = (nbox != ans[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,2D: Method qowhichbox() identified wrong box for specified circle");
       
      }
    }

    // Test qostore in 2D
    s2.center=new Point(5.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      nbox=qotree2.qostore(s2);
//      System.out.println("box: %f\n", nbox);

      localflag = (nbox != ans[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,2D: Method qostore() stored specified circle in wrong box");
       
      }
    }

    // Test qoerase in 2D
    s2.center=new Point(5.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      nbox=qotree2.qoerase(s2);
//      System.out.printf(nbox);

      localflag = (nbox != ans[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,2D: Method qoerase() removed circle from wrong box");
       
      }
    }

    // Store 16 circles in the tree
    s2.center=new Point(5.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      qotree2.qostore(s2);
    }
    s2.center=new Point(10.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      qotree2.qostore(s2);
    }
    s2.center=new Point(10.5/16.0,5.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      qotree2.qostore(s2);
    }
    s2.center=new Point(5.5/16.0,5.5/16.0);
    for (i=0;i<4;i++) {
      s2.radius=0.25/pow(2.0,i);
      qotree2.qostore(s2);
    }

    // Test qoget in 2D
    Sphcirc[]list2=new Sphcirc[N];
    nlist=qotree2.qoget(1,list2,N);
    System.out.println(nlist);
    for (i=0;i<nlist;i++)
      System.out.printf( "%f %f  %f\n", list2[i].center.x[0], list2[i].center.x[1] , list2[i].radius);

    localflag = (nlist != 4);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Method qoget() found the wrong number of circles in Box 1");
     
    }

    localflag=false;
    for (i=0;i<nlist;i++) {
      nbox=qotree2.qowhichbox(list2[i]);
      localflag = localflag || (nbox != 1);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Method qoget() returned a circle that is not in Box 1");
     
    }
   
    // Test qodump in 2D
    int[] klist2=new int[N];
    nlist=qotree2.qodump(klist2,list2,N);
//    System.out.printf(nlist);

    localflag = (nlist != 16);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Method qodump() did not find all 16 circles in the tree");
     
    }
   
    // Test qocontainspt in 2D
    Point p2=new Point(5.5/16.0,10.5/16.0);
    nlist=qotree2.qocontainspt(p2,list2,N);
//    System.out.printf(nlist);

    localflag = (nlist != 4);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Method qodump() did not find all 4 circles with the given point");
     
    }

    for (i=0;i<nlist;i++) {
      localflag = dist(p2,list2[i].center) > list2[i].radius;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,2D: Method qodump() returned a circle that does not contain the given point");
       
      }
    }

    // Test qocollides in 2D
    s2.center=new Point(0.75,0.75);
    s2.radius=0.10;
    nlist=qotree2.qocollides(s2,list2,N);
//    System.out.printf(nlist);

    localflag = (nlist != 3);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,2D: Method qocollides() did not find 3 circles that collide with target");
     
    }

    for (i=0;i<nlist;i++) {
      localflag = (dist(list2[i].center,s2.center) > list2[i].radius+s2.radius);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,2D: Incorrect collision detection by method qocollides()");
       
      }  
    }

    // Test Qotree in 3D
    Qotree qotree3=new Qotree(3,N,N,5);

    // Test setouterbox in 3D
    Point lo3=new Point(0.0,0.0,0.0),hi3=new Point(1.0,1.0,1.0);
    qotree3.setouterbox(lo3,hi3);

    // Test qobox in 3D
    Box b3=new Box(3);
    b3=qotree3.qobox(1);
//    System.out.printf(dist(b3.lo,lo3));
    localflag = dist(b3.lo,lo3) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Outer box lower corner improperly set");
     
    }

//    System.out.printf(dist(b3.hi,hi3));
    localflag = dist(b3.hi,hi3) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Outer box upper corner improperly set");
     
    }

    Point half3=new Point(hi3.x[0]/2.0,hi3.x[1]/2.0,hi3.x[2]/2.0);

    b3=qotree3.qobox(2);
//    System.out.printf(dist(b3.hi,half3));
    localflag = dist(b3.hi,half3) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Box 2 upper corner should be in center of outer box");
     
    }

    b3=qotree3.qobox(9);
//    System.out.printf(dist(b3.lo,half3));
    localflag = dist(b3.lo,half3) > sbeps;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Box 9 lower corner should be in center of outer box");
     
    }

    // Test qowhichbox in 3D
    Sphcirc s3=new Sphcirc(3);
    int ans3[]={1,8,59,3771};
    s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      nbox=qotree3.qowhichbox(s3);
//      System.out.printf(s3.radius << " %f\n", nbox);

      localflag = (nbox != ans3[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,3D: Method qowhichbox() identified wrong box for specified sphere");
       
      }
    }
   
    // Test qostore in 3D
    s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      nbox=qotree3.qostore(s3);
//      System.out.println("box: %f\n", nbox);

      localflag = (nbox != ans3[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,3D: Method qostore() stored specified sphere in wrong box");
       
      }
    }

    // Test qoerase in 3D
    s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
    for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      nbox=qotree3.qoerase(s3);
//      System.out.printf(nbox);

      localflag = (nbox != ans3[i]);
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,3D: Method qoerase() removed sphere from wrong box");
       
      }
    }

    // Store 32 circles in the tree
    s3.center=new Point(5.5/16.0,5.5/16.0,5.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(5.5/16.0,5.5/16.0,10.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(5.5/16.0,10.5/16.0,5.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(10.5/16.0,5.5/16.0,5.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(10.5/16.0,5.5/16.0,10.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(10.5/16.0,10.5/16.0,5.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }
    s3.center=new Point(10.5/16.0,10.5/16.0,10.5/16.0);
      for (i=0;i<4;i++) {
      s3.radius=0.25/pow(2.0,i);
      qotree3.qostore(s3);
    }

    // Test qoget in 3D
    Sphcirc[] list3=new Sphcirc[N];
    nlist=qotree3.qoget(1,list3,N);
//    System.out.printf(nlist);
//    for (i=0;i<nlist;i++)
//      System.out.printf(list3[i].center.x[0] << " %f\n", list3[i].center.x[1] << " %f\n", list3[i].center.x[2] << " %f\n", list3[i].radius);
//    System.out.printf(endl;

    localflag = (nlist != 8);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Method qoget() found the wrong number of spheres in Box 1");
     
    }

    localflag=false;
    for (i=0;i<nlist;i++) {
      nbox=qotree3.qowhichbox(list3[i]);
      localflag = localflag || (nbox != 1);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Method qoget() returned a sphere that is not in Box 1");
     
    }
   
    // Test qodump in 3D
    int[] klist3=new int[N];
    nlist=qotree3.qodump(klist3,list3,N);
//    System.out.printf(nlist);

    localflag = (nlist != 32);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Method qodump() did not find all 32 spheres in the tree");
     
    }

    // Test qocontainspt in 3D
    Point p3=new Point(5.5/16.0,10.5/16.0,10.5/16.0);
    nlist=qotree3.qocontainspt(p3,list3,N);
//    System.out.printf(nlist);

    localflag = (nlist != 4);
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Qotree,3D: Method qodump() did not find all 4 spheres with the given point");
     
    }

    for (i=0;i<nlist;i++) {
      localflag = dist(p3,list3[i].center) > list3[i].radius;
      globalflag = globalflag || localflag;
      if (localflag) {
        fail("*** Qotree,3D: Method qodump() returned a sphere that does not contain the given point");
       
      }
    }

    // Test qocollides in 3D
    s3.center=new Point(0.75,0.75,0.75);
    s3.radius=0.10;
    nlist=qotree3.qocollides(s3,list3,N);
//    System.out.printf(nlist);

    localflag = (nlist != 3);
View Full Code Here

    Boxnode boxes2[]=new Boxnode[NBOX];
    Point[] points2=new Point[2*NBOX];

    Ran myran=new Ran(17);
    for (i=0;i<NBOX;i++) {
      Point plo=new Point(myran.doub(),myran.doub());
      Point phi=new Point(myran.doub(),myran.doub());
      d1=phi.x[0]-plo.x[0];
      d2=phi.x[1]-plo.x[1];
      points2[2*i]=new Point(plo.x[0]+0.3*d1,plo.x[1]+0.3*d2);
      points2[2*i+1]=new Point(plo.x[0]+0.6*d1,plo.x[1]+0.6*d2);
      boxes2[i]=new Boxnode(plo,phi,(i-1)/2,2*i+1,2*i+2,2*i,2*i+1);
    }

//    for (i=0;i<NBOX;i++) {
//      System.out.printf(boxes2[i].mom << " ";
View Full Code Here

  public void tearDown() throws Exception {
  }

  @Test
  public void test() {
    Point zero2=new Point(0.0,0.0),one2=new Point(1.0,1.0);
    Point zero3=new Point(0.0,0.0,0.0),one3=new Point(1.0,1.0,1.0);
    boolean localflag, globalflag=false;

   

    // Test Box
View Full Code Here

  public void tearDown() throws Exception {
  }

  @Test
  public void test() {
    Point center=new Point(2);
    double radius,sbeps=1.e-16;
    boolean localflag, globalflag=false;

   
View Full Code Here

    // Conclass a tree of triangles
    // 0 -> 1,2,3 ; 1 -> 4,5,6 ; 2 -> 7,8,9 ; 3 -> 10,11,12

    Point []points=new Point[NPTS];
    for (i=0;i<NPTS;i++)
      points[i]=new Point((double)(i%2),(double)(i/2));

//    for (i=0;i<NPTS;i++)
//      System.out.printf(points[i].x[0] << " %f\n", points[i].x[1]);

    Triel[] triels=new Triel[NTRI];
    for(i=0;i<NTRI;i++)triels[i] = new Triel();
    for (i=0;i<NTRI;i++) {
      if (i%2 == 0)   // Note: the triangle must be in couterclockwise
        triels[i].setme(i,i+1,i+2,points)// order in order for the
      else                  // method contains() to work
        triels[i].setme(i,i+2,i+1,points)// properly
      for (j=0;j<3;j++)
        triels[i].d[j]=3*i+j+1;   // Indexes for daughter triangles
    }

//    Point<2> ptest;
//    for (i=0;i<NTRI;i++) {
//      ptest=points[triels[i].p[0]];
//      System.out.printf(ptest.x[0] << " %f\n", ptest.x[1] << "   ";
//      ptest=points[triels[i].p[1]];
//      System.out.printf(ptest.x[0] << " %f\n", ptest.x[1] << "   ";
//      ptest=points[triels[i].p[2]];
//      System.out.printf(ptest.x[0] << " %f\n", ptest.x[1] << "   ";
//      System.out.printf(endl;
//    }

    localflag=false;
    for (i=0;i<NTRI;i++)
      localflag = localflag || triels[i].stat != 1;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Triel: Status flags are improperly set");
     
    }

    // Track through some daughters
    localflag = triels[triels[0].d[2]].d[0] != 10;
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Triel: Indexing of daughters is not working");
     
    }

//    Triel t=triels[triels[triels[0].d[2]].d[0]];
//    System.out.printf(t.pts[t.p[0]].x[0] << " ";
//    System.out.printf(t.pts[t.p[1]].x[0] << " ";
//    System.out.printf(t.pts[t.p[2]].x[0] << " ";
//    System.out.printf(endl;
//    System.out.printf(t.pts[t.p[0]].x[1] << " ";
//    System.out.printf(t.pts[t.p[1]].x[1] << " ";
//    System.out.printf(t.pts[t.p[2]].x[1] << " ";
//    System.out.printf(endl;


    // Test contains() method
    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      Point z=new Point(2.0*myran.doub(),6.0*myran.doub());
      // Points in the range (0-2.0,0-6.0).  Only the ones
      // with x coordinate between 0 and 1 are inside a triangle
      test=false;   // Test if point is inside a triangle
      for (j=0;j<NTRI;j++)
        test = test || (triels[j].contains(z) > 0.0);
View Full Code Here

    int i,j,k,mm,N=1000,M=100;
    long key;
    double sbeps=1.e-15;
    Point[] pvec=new Point[N];
    for(i=0;i<N;i++)
      pvec[i]= new Point(2);
    boolean localflag, globalflag=false;

   

    // Test Voronoi
    System.out.println("Testing Voronoi");

    Ran myran=new Ran(17);
    for (i=0;i<N;i++) {
      pvec[i].x[0]=myran.doub();
      pvec[i].x[1]=myran.doub();
    }
    Voronoi vor=new Voronoi(pvec);

    int m,nsite,jfirst;
    Voronoi.Voredge edge; // = new Voronoi.Voredge();
    Point end1=new Point(2),end2=new Point(2);
    Triel tt;
    double dotprodi,dotprodj;

    for (mm=0;mm<M;mm++) {
      // Choose a random segment
View Full Code Here

TOP

Related Classes of com.nr.cg.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.