Skip to content

Commit

Permalink
added incomplete circle test
Browse files Browse the repository at this point in the history
  • Loading branch information
laa11004 committed Dec 8, 2015
1 parent b19bd3d commit 5f7a4a9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions RangeApp/circleTests.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

import javax.vecmath.Vector2d;

boolean rectCircleIntersect(BoundingBox bb, Point p, float r){
if( inBox(p, bb) ){ return true; } //circle center in rect
else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x1, bb.y2, p._x, p._y, r)){ return true; }//left:bottom->top
else if(lineIntersectsCircle (bb.x1, bb.y2, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//top:left->right
else if(lineIntersectsCircle (bb.x2, bb.y1, bb.x2, bb.y2, p._x, p._y, r)){ return true; }//right:bottom->top
else if(lineIntersectsCircle (bb.x1, bb.y1, bb.x2, bb.y1, p._x, p._y, r)){ return true; }//bottom: left->right
else{ return false; }
}

boolean lineIntersectsCircle(float a1, float a2, float b1, float b2, float c1, float c2, float r) {
Vector2d v = new Vector2d((double)b1-a1, (double)b2-a2);
Vector2d c = new Vector2d((double)c1-a1, (double)c2-a2);
double dpT = v.dot(c);//numerator of projection
double dpB = c.dot(c);//denominator of projection
double projScalar = dpT/dpB;//the
double orthX = c1-projScalar*(b1-a1);
double orthY = c2-projScalar*(b2-a2);
if( !online(0,) ){return true;
if( distance(orthX, orthY, (double)c1-a1, (double)c2-a2) < r ) return true;
return false;
}

double distance(double x1, double y1, double x2, double y2){
float t1 = (float)x2-(float)x1;
float t2 = (float)y2-(float)y1;
return sqrt(t1*t1+t2*t2);
}

boolean onLine(double a1, double a2, double b1, double b2, double p1, double p2){//returns true if p is on segment ab
if( a1 == b1 ){//vertical line case
if( a2<=p2 && p2<=b2 ){ return true; }
else { return false; }
}
else{// a2 == b2 horizontal line case
if( a1<=p1 && p1<=b1 ){ return true; }
else{ return false; }
}
}



0 comments on commit 5f7a4a9

Please sign in to comment.