Ejemplo n.º 1
0
SpatialMarkup
SpatialConvex::triangleTest(uint64 id)
{
  SpatialMarkup mark;
//
// do the face test on the triangle

  mark =  testNode(V(NV(0)),V(NV(1)),V(NV(2)));

// do we have a final result code?
// if rEJECT, fULL then return

  if(mark > fULL) return mark;

  if(mark == fULL) {
      fillChildren(id); // propagate final result to children
      return mark;
  }

// if pARTIAL or dONTKNOW, then continue, test children,
//    but do not reach beyond the leaf nodes.
//    If Convex is fully contained within one (sWALLOWED),
//    we can stop looking further in another child

  if (NC(id,0)!=0) {
    triangleTest(NC(id,0));
    triangleTest(NC(id,1));
    triangleTest(NC(id,2));
    triangleTest(NC(id,3));
// we are at the leafnodes
// If we have to recurse further, calculate intersections one by one
// If not, just set the proper bit in partial_ or append id to plist_.
  } else {
    if(addlevel_) {
      // from now on, continue to build the triangles dynamically.
      // until maxlevel_ levels depth.
      testPartial(addlevel_, N(id).id_, V(NV(0)), V(NV(1)), V(NV(2)));

    } else {
      if(bitresult_)
	partial_->set((uint32)index_->leafNumberById(N(id).id_),true);
      else
	plist_->append(N(id).id_);
    }
  }

  return mark;
}
Ejemplo n.º 2
0
int tests () {
//  vertPosition (px, py, m, b);
    assert (vertPosition (2.0, 1.0, 1.0, 0.0 ) ==  UNDER);
    assert (vertPosition (2.0, 2.0, 1.0, 0.0 ) ==  ON_LINE);
    assert (vertPosition (2.0, 3.0, 1.0, 0.0 ) ==  ABOVE);

    assert (vertPosition (2.0, 1.0, -1.0, 4.0 ) ==  UNDER);
    assert (vertPosition (2.0, 2.0, -1.0, 4.0 ) ==  ON_LINE);
    assert (vertPosition (2.0, 3.0, -1.0, 4.0 ) ==  ABOVE);
  
    assert (vertPosition (-2.0, -2.0, 1.0, 2.0 ) ==  UNDER);
    assert (vertPosition (-2.0,  0.0, 1.0, 2.0 ) ==  ON_LINE);
    assert (vertPosition (-2.0,  2.0, 1.0, 2.0 ) ==  ABOVE);

    assert (vertPosition (0.0, 1.0, 0.0, 0.0 ) ==  ABOVE);
    assert (vertPosition (0.0, 0.0, 0.0, 0.0 ) ==  ON_LINE);
    assert (vertPosition (0.0, -1.0, 0.0, 0.0 ) ==  UNDER);
    
//  bothAbove (test1 (px, py, m, b, lx, ly));
    assert (sameSide (1.0, 4.0, 1.0, 2.0, 3.0, 6.0) == TRUE);
    assert (sameSide (1.0, 4.0, 1.0, 2.0, 3.0, 2.0) == FALSE);
    assert (sameSide (1.0, 4.0, 1.0, 2.0, 1.0, 1.0) == FALSE);
    assert (sameSide (1.0, 1.0, 1.0, 1.0, 3.0, 2.0) == TRUE);
    assert (sameSide (1.0, 1.0, 0,   1.0, 2.0, 1.0) == TRUE);
    assert (sameSide (1.0, 0.0, 0,   0.0, 2.0, 0.0) == TRUE);
    
    assert (sameSide (0.5, 0.0, 0,   0.0, 0.0, 1.0) == FALSE);

//  assert (triangleTest (x0, y0, x1, y1, x2, y2, px, py)); //
    assert (triangleTest (0.0, 0.0, 0.0,  1.0,  1.0, 0.0,  0.25,  0.25) == TRUE);
    assert (triangleTest (0.0, 0.0, 0.0,  1.0,  1.0, 0.0,  2.0,   2.0)  == FALSE);
/*
    Special case where P(x,y) lies on a hozizontal line. Not sure if this 
    should be true or false.
    Test is below for either. I will assume a FALSE result for my program
    assert (tritest (0.0, 0.0, 0.0,  1.0,  1.0, 0.0,  0.5,   0.0)  == TRUE); XXX Special
*/
    assert (triangleTest (0.0, 0.0, 0.0,  1.0,  1.0, 0.0,  0.5,   0.0)  == FALSE); 
    assert (triangleTest (0.0, 0.0, 0.0, -1.0, -1.0, 0.0, -0.25, -0.25) == TRUE);

    printf("Tests Completed Sucessfully.\n"); 
    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
/////////////DOINTERSECT//////////////////////////////////
//
void
SpatialConvex::doIntersect() {

  simplify();				// don't work too hard...

  if(constraints_.length()==0)return;   // nothing to intersect!!

  // Start with root nodes (index = 1-8) and intersect triangles
  for(uint32 i = 1; i <= 8; i++)
    triangleTest(i);

}
Ejemplo n.º 4
0
int main (int argc, char* argv[]) {
    tests();
    
    double x0,x1,x2;
    double y0,y1,y2;
    double px, py;
    int errorCode;
    int error;
    int inTriangle;

    errorCode = NO_ERROR;
    error = NO_ERROR;

    // get input
    printf("Triangle Vertex A (x,y): "); 
    errorCode += scanf("%lf,%lf", &x0,&y0);
    printf("Triangle Vertex B (x,y): "); 
    errorCode += scanf("%lf,%lf", &x1,&y1);
    printf("Triangle Vertex C (x,y): "); 
    errorCode += scanf("%lf,%lf", &x2,&y2);
    printf("Test Point (x,y): "); 
    errorCode += scanf("%lf,%lf", &px,&py);
 
    // print error
    if( errorCode != 8 ) {
        printf("\nSorry, but your inputted data seems to be incorrect. " 
               "Error: %d\n", errorCode);
        error = ERROR;
    }

    if (error != ERROR) { 
        inTriangle = triangleTest(x0,y0,x1,y1,x2,y2,px,py);

        if (inTriangle == TRUE) {
            printf("Point (%.2lf,%.2lf) is inside the Triangle\n.", px,py);
        }
    
        if (inTriangle == FALSE) {
            printf("Point (%.2lf,%.2lf) is outside the Triangle\n.", px,py);
        }
    }
    
    return error;
}