From 5f7a4a974dd2ee67f7853e31fff725900bc712fd Mon Sep 17 00:00:00 2001 From: laa11004 Date: Tue, 8 Dec 2015 11:07:09 -0500 Subject: [PATCH] added incomplete circle test --- .DS_Store | Bin 6148 -> 6148 bytes RangeApp/circleTests.pde | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 RangeApp/circleTests.pde diff --git a/.DS_Store b/.DS_Store index 16ae1e190884b3bf321e46608f4fc11dfcf48d06..40abc44ca2b7370ba006ce79a0b58cd4c7a4f3a7 100644 GIT binary patch delta 110 zcmZoMXfc=|#>B)qu~2NHo}wrR0|Nsi1A_nqLkUAFLoq{1T1s*9#=_-{6ZP08C$dTd z6$CLPGUPF&1En1q3K$B2@;RGJSSK@WY%pft%+A5j0W@v1Ajfy+$^0UYAoD;5vTTkJ HS;Gtfb4?h$ delta 426 zcmZoMXfc=|#>B!ku~2NHo}wr>0|Nsi1A_nqLoq{1Qh9MfQcix-=0xV@%=I8CHim45 z6owLpRAgzO__L&foXp}91A`lkOw25-Z0sDITwGk7T>PA|!5R7G!6k_$rNvH(MbThh zW=d)jlpT;*k^y6ftop + 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; } + } +} + + +