Point __trilaterate(const Circle& a, const Circle& b, const Circle& c) { //radii of each circle float ra, rb, rc; ra = a.getRadius(); rb = b.getRadius(); rc = c.getRadius(); //center of each circle Point ca, cb, cc; ca = a.getCenter(); cb = b.getCenter(); cc = c.getCenter(); //x basis vector of transformed co-ordinate space in original space Point xUnitVector = getXUnit(ca, cb); //"horizontal" component (transformed space) of difference between circle centers float i = signedMagnitudeX(ca, cc, xUnitVector); //y basis vector of transformed co-ordinate space in original space Point yUnitVector = getYUnit(ca, cc, i, xUnitVector); //"vertical" component (transformed space) of difference between circle centers float j = signedMagnitudeY(ca, cc, yUnitVector); float d = getDistance(ca, cb); //the intersection point relative to origin in transformed co-ordinate space float x = (powf(ra,2)-powf(rb,2)+powf(d,2))/(2*d); float y = ((powf(ra, 2)-powf(rc,2)+powf(i,2)+powf(j,2))/(2*j)) - x*(i)/(j); //transform x, y to original co-ordinate frame Point xMagVector = xUnitVector*x, yMagVector = yUnitVector*y; Point p = ca + xMagVector + yMagVector; return p; }
void OpenGLESCircleBatcher::renderPartialCircle(Circle &circle, int arcDegrees, Color &c, GpuProgramWrapper &gpuProgramWrapper) { OGLESManager->m_colorVertices.clear(); OGLESManager->addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints = 1; for (int i = 90 - arcDegrees; i > -270; i -= DEGREE_SPACING) { float rad = DEGREES_TO_RADIANS(i); float cos = cosf(rad); float sin = sinf(rad); OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints++; } float rad = DEGREES_TO_RADIANS(-270); float cos = cosf(rad); float sin = sinf(rad); OGLESManager->addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha); m_iNumPoints++; endBatch(gpuProgramWrapper); }
Point trilaterate(const Circle& c1, const Circle& c2, const Circle& c3) { Point p1, p2, p3; p1 = c1.getCenter(); p2 = c2.getCenter(); p3 = c3.getCenter(); float r1, r2, r3; r1 = c1.getRadius(); r2 = c2.getRadius(); r3 = c3.getRadius(); float d12, d13, d23; d12 = getDistance(p1,p2); d13 = getDistance(p1,p3); d23 = getDistance(p2,p3); DEBUG("Attempting to trilaterate:\n"); DEBUG("Centre:(%f, %f) Radius:%f\n",p1.getX(), p1.getY(), r1); DEBUG("Centre:(%f, %f) Radius:%f\n",p2.getX(), p2.getY(), r2); DEBUG("Centre:(%f, %f) Radius:%f\n",p3.getX(), p3.getY(), r3); bool inter12, inter13, inter23; inter12 = d12-r1 < r2 && r2 < d12+r1; inter13 = d13-r1 < r3 && r3 < d13+r1; inter23 = d23-r2 < r3 && r3 < d23+r3; if(!(inter12 && inter13 && inter23)) { DEBUG("Error: each pair of circles must intersect with at least two points\n"); throw CIRCLES_DO_NOT_INTERSECT; } return __trilaterate(c1, c2, c3); }
bool OverlapTester::doCirclesOverlap(const Circle &c1, const Circle &c2) { Vector2D c1Center = c1.getCenter(); Vector2D c2Center = c2.getCenter(); float distance = c1Center.distSquared(c2Center); float radiusSum = c1.m_fRadius + c2.m_fRadius; return distance <= radiusSum * radiusSum; }
bool TestCircleCircle ( Circle const & A, Circle const & B ) { float dist2 = Distance2d::Distance2PointPoint( A.getCenter(), B.getCenter() ); float rad = A.getRadius() * B.getRadius(); float rad2 = rad * rad; return dist2 <= rad2; }
double Circle::intersectionArea(const Circle & otherCircle) { double d = center.distanceFrom(otherCircle.getCenter()); //fprintf(stderr, "d=%f\n", d); double r = radius; //fprintf(stderr, "r=%f\n", r); double R = otherCircle.getRadius(); //fprintf(stderr, "R=%f\n", R); // error handle: if a circle has no radius if (r==0 || R==0 || r+R<=d) { return 0; } if (d==0){ r = r<R ? r:R; return M_PI*r*r; } if ( ((((d+r <= r)||(-d-R >= -r)) && (r>R))) || \ ((((d+r <= R)||(-d-r >= -R)) && (r<R)))){ //if overlap completely, do pi*r^2 with the smaller radius r = r<R ? r:R; return M_PI*r*r; } double part1 = r*r*acos( (d*d+r*r-R*R)/(2*d*r)); //fprintf(stderr, "part1=%f\n", part1); double part2 = R*R*acos( (d*d+R*R-r*r)/(2*d*R)); //fprintf(stderr, "part2=%f\n", part2); double part3 = 0.5*sqrt( (-d+r+R)*(d+r-R)*(d-r+R)*(d+r+R)); //fprintf(stderr, "part3=%f\n", part3); return part1+part2-part3; }
void GerberGenerator::drawCircleOutline(const Circle& circle) noexcept { PositiveLength outerDia = circle.getDiameter() + circle.getLineWidth(); Length innerDia = circle.getDiameter() - circle.getLineWidth(); if (innerDia < 0) innerDia = 0; flashCircle(circle.getCenter(), positiveToUnsigned(outerDia), UnsignedLength(innerDia)); }
bool TestSegCircle_Below ( Segment3d const & S, Circle const & circle ) { Vector A = S.getBegin(); Vector B = S.getEnd(); Vector const & C = circle.getCenter(); if(A.y > B.y) std::swap(A,B); if(C.y > B.y) { return false; } else if(C.y < A.y) { return Overlap2d::TestSegCircle(S,circle); } else { if(A.y == B.y) { return Overlap2d::TestSegCircle(S,circle); } else { float param = (C.y - A.y) / (B.y - A.y); Vector D = A + (B - A) * param; return Overlap2d::TestSegCircle( Segment3d(D,B), circle ); } } }
float Circle::getIntersectionArea( const Circle &c ) const { Vector2D pos1, pos2, pos3; float d, h, dArea; AngDeg ang; d = getCenter().distanceTo( c.getCenter() ); // dist between two centers if( d > c.getRadius() + getRadius() ) // larger than sum radii return 0.0; // circles do not intersect if( d <= fabs(c.getRadius() - getRadius() ) ) // one totally in the other { float dR = min( c.getRadius(), getRadius() );// return area smallest circle return M_PI*dR*dR; } int iNrSol = getIntersectionPoints( c, &pos1, &pos2 ); if( iNrSol != 2 ) return 0.0; // the intersection area of two circles can be divided into two segments: // left and right of the line between the two intersection points p1 and p2. // The outside area of each segment can be calculated by taking the part // of the circle pie excluding the triangle from the center to the // two intersection points. // The pie equals pi*r^2 * rad(2*ang) / 2*pi = 0.5*rad(2*ang)*r^2 with ang // the angle between the center c of the circle and one of the two // intersection points. Thus the angle between c and p1 and c and p3 where // p3 is the point that lies halfway between p1 and p2. // This can be calculated using ang = asin( d / r ) with d the distance // between p1 and p3 and r the radius of the circle. // The area of the triangle is 2*0.5*h*d. pos3 = pos1.getVector2DOnLineFraction( pos2, 0.5 ); d = pos1.distanceTo( pos3 ); h = pos3.distanceTo( getCenter() ); ang = asin( d / getRadius() ); dArea = ang*getRadius()*getRadius(); dArea = dArea - d*h; // and now for the other segment the same story h = pos3.distanceTo( c.getCenter() ); ang = asin( d / c.getRadius() ); dArea = dArea + ang*c.getRadius()*c.getRadius(); dArea = dArea - d*h; return dArea; }
Point trilaterate(const Circle& a, const Circle& b, const Circle& c) { Point ca, cb, cc; ca = a.getCenter(); cb = b.getCenter(); cc = c.getCenter(); float dab = getDistance(ca, cb); //distance from a to b float dac = getDistance(ca, cc); //distance from a to c float dbc = getDistance(cb, cc); //distance from b to c float ra, rb, rc; ra = a.getRadius(); rb = b.getRadius(); rc = c.getRadius(); //does a,b intersect? a,c intersect? b,c intersect? bool abIntersect, acIntersect, bcIntersect; abIntersect = fabs(dab-ra) < rb && rb < dab+ra; acIntersect = fabs(dac-ra) < rc && rc < dac+ra; bcIntersect = fabs(dbc-rb) < rc && rc < dbc+rb; //debug statements #ifdef VERBOSE PRINT_ERR("Attempting to trilaterate:\n"); PRINT_ERR("Centre:(%f, %f) Radius:%f\n",ca.getX(), ca.getY(), ra); PRINT_ERR("Centre:(%f, %f) Radius:%f\n",cb.getX(), cb.getY(), rb); PRINT_ERR("Centre:(%f, %f) Radius:%f\n",cc.getX(), cc.getY(), rc); #endif //if colinear will cause nan errors in calculation if(areColinear(ca,cb,cc)) { #ifdef VERBOSE PRINT_ERR("Error: circle centres are colinear\n"); #endif throw CIRCLE_CENTRES_ARE_COLINEAR; } //insufficient number of intersections will result in throwing exception if(!abIntersect || !acIntersect || !bcIntersect) { #ifdef VERBOSE PRINT_ERR("Error: each pair of circles must intersect with at least two points\n"); #endif throw CIRCLES_DO_NOT_INTERSECT; } return __trilaterate(a, b, c); }
bool BoundingBox::overlaps(const Circle &circle) { RectangleGeo rect( Vector2D( box.x, box.y ), Vector2D( box.x + box.w, box.y + box.h ) ); return (rect.isInside(circle.getCenter()) || circle.isInside(rect.getPosLeftTop()) || circle.isInside(rect.getPosRightBottom()) || circle.isInside(Vector2D( box.x, box.y + box.h )) || circle.isInside(Vector2D( box.x + box.w, box.y ))); }
void Direct3DCircleBatcher::renderCircle(Circle &circle, Color &c, GpuProgramWrapper &gpuProgramWrapper) { m_iNumPoints = 0; D3DManager->m_colorVertices.clear(); for (int i = 0; i <= 360; i += DEGREE_SPACING) { float rad = DEGREES_TO_RADIANS(i); float cos = cosf(rad); float sin = sinf(rad); addVertexCoordinate(cos * circle.m_fRadius + circle.getCenter().getX(), sin * circle.m_fRadius + circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); addVertexCoordinate(circle.getCenter().getX(), circle.getCenter().getY(), 0, c.red, c.green, c.blue, c.alpha, 0, 0); } endBatch(gpuProgramWrapper); }
void Ball::geOutOf(Object* object) { Circle* bouncer = object->getCircleBounds(); Circle* ball = getCircleBounds(); sf::Vector2f* normal = vectors->computeNormToSurface(ball, bouncer); vectors->setLength(normal, bouncer->getRadius() + ball->getRadius()); sf::Vector2f* bouncerCenter = bouncer->getCenter(); setPosition(bouncerCenter->x + normal->x - ball->getRadius(), bouncerCenter->y + normal->y - ball->getRadius()); }
void findIntersections(std::vector<Point>& p, const Circle& a, const Circle& b) { Point mid = centroidIntersection(a,b); DEBUG("Circles intersect at: (%f %f)\n",mid.getX(),mid.getY()); Point ca = a.getCenter(); Point cb = b.getCenter(); float deltaX, deltaY; deltaX = cb.getX() - ca.getX(); deltaY = cb.getY() - ca.getY(); float s = getDistance(ca,mid); float ra = a.getRadius(); float d = getDistance(ca, cb); float u = sqrt(pow(ra,2)-pow(s,2)); p.push_back(Point(ca.getX() - deltaX * u / d, ca.getY() + deltaY * u / d)); p.push_back(Point(ca.getX() + deltaX * u / d, ca.getY() - deltaY * u / d)); }
bool isCircleInTriangle(Circle& circ, Triangle& trig) { if(!trig.isPointInsideFigure(circ.getCenter())) return false; Point O(circ.getCenter()); Point OA(circ.getCenter().x, circ.getCenter().y + circ.getRadius()); Point OB (circ.getCenter().x + circ.getRadius(), circ.getCenter().y); Point OC(circ.getCenter().x, circ.getCenter().y - circ.getRadius()); Point OD(circ.getCenter().x - circ.getRadius(), circ.getCenter().y); if(trig.isPointInsideFigure(OA) && trig.isPointInsideFigure(OB) && trig.isPointInsideFigure(OC) && trig.isPointInsideFigure(OD)) return true; return false; }
bool OverlapTester::overlapCircleRectangle(const Circle &c, Rectangle &r) { float closestX = c.getCenter().getX(); float closestY = c.getCenter().getY(); if (c.getCenter().getX() < r.getLowerLeft().getX()) { closestX = r.getLowerLeft().getX(); } else if (c.getCenter().getX() > r.getLowerLeft().getX() + r.getWidth()) { closestX = r.getLowerLeft().getX() + r.getWidth(); } if (c.getCenter().getY() < r.getLowerLeft().getY()) { closestY = r.getLowerLeft().getY(); } else if (c.getCenter().getY() > r.getLowerLeft().getY() + r.getHeight()) { closestY = r.getLowerLeft().getY() + r.getHeight(); } return c.getCenter().distSquared(closestX, closestY) < c.m_fRadius * c.m_fRadius; }
bool isCircleInRectangle(Circle& circ, Rectangle& rect) { Point O(circ.getCenter()); Point OA(circ.getCenter().x, circ.getCenter().y + circ.getRadius()); Point OB (circ.getCenter().x + circ.getRadius(), circ.getCenter().y); Point OC(circ.getCenter().x, circ.getCenter().y - circ.getRadius()); Point OD(circ.getCenter().x - circ.getRadius(), circ.getCenter().y); if(rect.isPointInsideFigure(OA) && rect.isPointInsideFigure(OB) && rect.isPointInsideFigure(OC) && rect.isPointInsideFigure(OD)) return true; return false; }
int Circle::getIntersectionPoints( const Circle &c, Vector2D *p1, Vector2D *p2) const { float x0, y0, r0; float x1, y1, r1; x0 = getCenter( ).getX(); y0 = getCenter( ).getY(); r0 = getRadius( ); x1 = c.getCenter( ).getX(); y1 = c.getCenter( ).getY(); r1 = c.getRadius( ); float d, dx, dy, h, a, x, y, p2_x, p2_y; // first calculate distance between two centers circles P0 and P1. dx = x1 - x0; dy = y1 - y0; d = sqrt(dx*dx + dy*dy); // normalize differences dx /= d; dy /= d; // a is distance between p0 and point that is the intersection point P2 // that intersects P0-P1 and the line that crosses the two intersection // points P3 and P4. // Define two triangles: P0,P2,P3 and P1,P2,P3. // with distances a, h, r0 and b, h, r1 with d = a + b // We know a^2 + h^2 = r0^2 and b^2 + h^2 = r1^2 which then gives // a^2 + r1^2 - b^2 = r0^2 with d = a + b ==> a^2 + r1^2 - (d-a)^2 = r0^2 // ==> r0^2 + d^2 - r1^2 / 2*d a = (r0*r0 + d*d - r1*r1) / (2.0 * d); // h is then a^2 + h^2 = r0^2 ==> h = sqrt( r0^2 - a^2 ) float arg = r0*r0 - a*a; h = (arg > 0.0) ? sqrt(arg) : 0.0; // First calculate P2 p2_x = x0 + a * dx; p2_y = y0 + a * dy; // and finally the two intersection points x = p2_x - h * dy; y = p2_y + h * dx; p1->setVector2D( x, y ); x = p2_x + h * dy; y = p2_y - h * dx; p2->setVector2D( x, y ); return (arg < 0.0) ? 0 : ((arg == 0.0 ) ? 1 : 2); }
/* Considérons le segment de ligne l (AB) et le cercre centré en C Le point D est la projection de AC sur AB. DC est le vecteur entre D et C. Lorsque que la norme de DC est plus petite que le rayon, nous savons qu'il y a une intersection sur la ligne AB. Il reste a determiner si le point d'intersection est sur le segment AB. Ensuite on détermine s'il y a 1 ou 2 points d'intersections. Lorsque la norme de DC est strictement égale au rayon, il n'y a qu'une intersection parce que AB est tangente au cercle. Si la norme de DC est plus petite que le rayon, il y aura 2 intersections. Ensuite, pour chaque intersection, il faut d'éterminer le point précis de l'intersection (E) et déterminer si ce point est sur le segment AB. Dans le cas de la tangente, le point d'intersection est déterminer par la projection AC sur AB. Dans l'autre cas, on trouve le point d'intersection par trigonométrie. On connais le rayon et le point D. Par c^2 = a^2 + b^2 (triangle rectangle), on peut trouver la norme de ED. Ensuite les deux points d'intersections sont défini comme AD - ED et AD + ED. Pour terminer, afin de determiner si E est sur le segment AB on s'assure que le produit scalaire AB * AE est positif et que la norme de AB est plus grande qye la norme de AE */ Intersection2d intersect( const LineSegment2d& l, const Circle& c) { Intersection2d r; Vector2d ab(l.a(), l.b()); Vector2d abUnit = ab.getUnit(); Vector2d ac(l.a(), c.getCenter()); double adNorm = ac * abUnit; Vector2d ad = adNorm * abUnit; Vector2d dc( l.a() + ad, c.getCenter() ); double dcNorm = dc.norm(); if( dcNorm <= c.getRadius() ) { if( isEqual( dcNorm, c.getRadius(), 1.0e-5 ) ) //l'intersection est tangente { Point2d e = l.a() + ad; Vector2d ae(l.a(), e); Vector2d ec( c.getCenter(), e ); if( ab.normSquare() >= ae.normSquare() && ab * ae >= 0.0 ) r.add( e, ec ); } else { double edNorm = sqrt( std::abs( dc.normSquare() - c.getRadius() * c.getRadius() ) ); Point2d e = l.a() + (adNorm - edNorm) * abUnit; Vector2d ae(l.a(), e); Vector2d ec( c.getCenter(), e ); if( ab.normSquare() >= ae.normSquare() && ab * ae >= 0.0 ) r.add( e, ec ); e = l.a() + (adNorm +edNorm) * abUnit; ae = Vector2d(l.a(), e); ec = Vector2d( c.getCenter(), e ); if( ab.normSquare() >= ae.normSquare() && ab * ae >= 0.0 ) r.add( e, ec ); } } return r; }
Point centroidIntersection(const Circle& a, const Circle& b) { Point ca, cb; ca = a.getCenter(); cb = b.getCenter(); float ra, rb; ra = a.getRadius(); rb = b.getRadius(); float deltaX, deltaY; deltaX = cb.getX() - ca.getX(); deltaY = cb.getY() - ca.getY(); float d = getDistance(ca,cb); float s = (pow(d,2)+pow(ra,2)-pow(rb,2))/(2*d); float newX, newY; newX = ca.getX()+deltaX * s/d; newY = ca.getY()+deltaY * s/d; return Point(newX,newY); }
void circles_test(u32 n, u32 size) { std::cout << "Circles(" << n << "):" << std::endl; Array<Circle> circles; circles.reserve(n); { BlockMeasure m(" creation"); for (u32 i=0; i<n; ++i) { f32 x = ((f32)rand()/RAND_MAX)*size; f32 y = ((f32)rand()/RAND_MAX)*size; f32 r = ((f32)rand()/RAND_MAX)*5 + 0.1f; circles.add(Vec2{x, y}, r); } } u32 overlaps = 0; { BlockMeasure m(" update + collide"); for (u32 i=0; i<n; ++i) { f32 dx = ((f32)rand()/RAND_MAX)*0.5f; f32 dy = ((f32)rand()/RAND_MAX)*0.5f; Circle* c = circles.getAtPos(i); c->setCenter(c->getCenter()+Vec2{dx, dy}); } for (u32 i=0; i<n; ++i) { Circle* c1 = circles.getAtPos(i); for (u32 j=i+1; j<n; ++j) { Circle* c2 = circles.getAtPos(j); if (c1->overlaps(*c2)) ++overlaps; } } } std::cout << " overlaps: " << overlaps << std::endl; fast_vector<unsigned int> destruction_order; destruction_order.reserve(n); randomPickN(destruction_order, n, n); { grynca::BlockMeasure m(" removal"); for (u32 i=0; i<destruction_order.size(); ++i) { u32 circle_id = destruction_order[i]; circles.removeAtPos(circle_id); } } }
int Line::getCircleIntersectionPoints( Circle circle, Vector2D *posSolution1, Vector2D *posSolution2 ){ int iSol; float dSol1, dSol2; float h = circle.getCenter().getX(); float k = circle.getCenter().getY(); // line: x = -c/b (if a = 0) // circle: (x-h)^2 + (y-k)^2 = r^2, with h = center.x and k = center.y // fill in:(-c/b-h)^2 + y^2 -2ky + k^2 - r^2 = 0 // y^2 -2ky + (-c/b-h)^2 + k^2 - r^2 = 0 // and determine solutions for y using abc-formula if( fabs(a) < EPSILON ){ iSol = Geometry::abcFormula( 1, -2*k, ((-c/b) - h)*((-c/b) - h) + k*k - circle.getRadius()*circle.getRadius(), &dSol1, &dSol2); posSolution1->setVector2D( (-c/b), dSol1 ); posSolution2->setVector2D( (-c/b), dSol2 ); return iSol; } // ay + bx + c = 0 => y = -b/a x - c/a, with da = -b/a and db = -c/a // circle: (x-h)^2 + (y-k)^2 = r^2, with h = center.x and k = center.y // fill in:x^2 -2hx + h^2 + (da*x-db)^2 -2k(da*x-db) + k^2 - r^2 = 0 // x^2 -2hx + h^2 + da^2*x^2 + 2da*db*x + db^2 -2k*da*x -2k*db // + k^2 - r^2 = 0 // (1+da^2)*x^2 + 2(da*db-h-k*da)*x + h2 + db^2 -2k*db + k^2 - r^2 = 0 // and determine solutions for x using abc-formula // fill in x in original line equation to get y coordinate float da = -b/a; float db = -c/a; float dA = 1 + da*da; float dB = 2*( da*db - h - k*da ); float dC = h*h + db*db - 2*k*db + k*k - circle.getRadius()*circle.getRadius(); iSol = Geometry::abcFormula( dA, dB, dC, &dSol1, &dSol2 ); posSolution1->setVector2D( dSol1, da*dSol1 + db ); posSolution2->setVector2D( dSol2, da*dSol2 + db ); return iSol; }
void showTemplate(const MinutiaeTemplate & mt, double T, const char *name) { Circle c; c.setT(T); c.getCenter(mt); c.fromTemplate(mt); Mat mat(500, 500, CV_8UC3, Scalar(255, 255, 255)); int offsetx = 100, offsety = 100, R = c.getR(); circle(mat,Point(c.getCenterX()+offsetx,c.getCenterY()+offsety),R,Scalar(0,255,0)); for(int i = 1; i < c.getSize(); i+=2) { double p1 = c.getPoint(i-1); double p2 = c.getPoint(i); line(mat,Point(R*cos(p1)+c.getCenterX()+offsetx,R*sin(p1)+c.getCenterY()+offsety), Point(R*cos(p2)+c.getCenterX()+offsetx,R*sin(p2)+c.getCenterY()+offsety), Scalar(255,0,0)); } for(int i = 0; i < mt.getSize(); i++) circle(mat,Point(mt.getMinutia(i).getX()+offsetx,mt.getMinutia(i).getY()+offsety),3,Scalar(0,0,255),CV_FILLED); imshow(name,mat); }
bool TestPointCircle ( Vector const & V, Circle const & C ) { return Distance2d::Distance2PointPoint( C.getCenter(), V ) <= C.getRadiusSquared(); }
bool isCircleInCircle(Circle& circ1, Circle& circ2) { if(!circ2.isPointInsideFigure(circ1.getCenter())) return false; if(!circ1.isPointInsideFigure(circ2.getCenter())) return false; Point OA(circ1.getCenter().x, circ1.getCenter().y + circ1.getRadius()); Point OB (circ1.getCenter().x + circ1.getRadius(), circ1.getCenter().y); Point OC(circ1.getCenter().x, circ1.getCenter().y - circ1.getRadius()); Point OD(circ1.getCenter().x - circ1.getRadius(), circ1.getCenter().y); if(circ2.isPointInsideFigure(OA) && circ2.isPointInsideFigure(OB) && circ2.isPointInsideFigure(OC) && circ2.isPointInsideFigure(OD)) return true; Point OA2(circ2.getCenter().x, circ2.getCenter().y + circ2.getRadius()); Point OB2(circ2.getCenter().x + circ2.getRadius(), circ2.getCenter().y); Point OC2(circ2.getCenter().x, circ2.getCenter().y - circ2.getRadius()); Point OD2(circ2.getCenter().x - circ2.getRadius(), circ2.getCenter().y); if(circ1.isPointInsideFigure(OA2) && circ1.isPointInsideFigure(OB2) && circ1.isPointInsideFigure(OC2) && circ1.isPointInsideFigure(OD2)) return true; return false; }
bool TestYLineCircle ( Vector const & V, Circle const & C ) { return Distance2d::Distance2PointPoint(V,C.getCenter()) < sqr(C.getRadius()); }
bool OverlapTester::isPointInCircle(const Vector2D &p, const Circle &c) { return c.getCenter().distSquared(p) < c.m_fRadius * c.m_fRadius; }
void Console::outputAll(Core &core) { cout << "OBJECTS:" << endl; if (core.sizeListObj() == 0) cout << " No objects yet." << endl; for (size_t i = 0; i < core.sizeListObj(); ++i) { Point * newp = 0; Circle *newc = 0; Segment * news = 0; switch (core.searchID(core.getObjIDs()[i])->object_type()) { case IsPoint: { newp = dynamic_cast<Point*>(core.searchID(core.getObjIDs()[i])); cout.precision(2); cout << setw(8); newp->isFixed() ? cout << "(fixed) " : cout << ""; cout << setw(8) << "POINT "; cout << setw(3) << "ID: " << setw(2) << newp->showId(); cout << setw(6) << "X: " << setw(8) << newp->getX(); cout << setw(6) << "Y: " << setw(8) << newp->getY(); newp->isPicked() ? cout << " <-" : cout << ""; cout << endl; } break; case IsSegment: { news = dynamic_cast<Segment*>(core.searchID(core.getObjIDs()[i])); cout.precision(2); cout << setw(8); news->isFixed() ? cout << "(fixed) " : cout << ""; cout << setw(8) << "SEGMENT "; cout << setw(3) << "ID: " << setw(2) << news->showId(); cout << setw(6) << news->getP1()->showId(); cout << "-----" << news->getP2()->showId(); news->isPicked() ? cout << setw(16) << "<-" : cout << ""; cout << endl << endl; } break; case IsCircle: { newc = dynamic_cast<Circle*>(core.searchID(core.getObjIDs()[i])); cout.precision(2); cout << setw(8); Point t = newc->getCenter(); newc->isFixed() ? cout << "(fixed) " : cout << ""; cout << setw(8) << "CIRCLE "; cout << setw(3) << "ID: " << setw(2) << newc->showId(); cout << setw(6) << "O: " << setw(8) << newc->getCenter().showId(); cout << setw(6) << "R: " << setw(8) << newc->getRadius(); newc->isPicked() ? cout << " <-" : cout << ""; cout << endl << endl; } break; } } cout << "RESTRICTIONS:" << endl; if (core.sizeListRestr() == 0) cout << " No restrictions yet." << endl; for (size_t i = 0; i < core.sizeListRestr(); ++i) { switch (core.searchIDRestr(core.getRestrIDs()[i])->get_type()) { case RT_P2PDIST: { auto restr = dynamic_cast<RestrP2PDIST*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "P2PDIST " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId() << endl; } break; case RT_P2SDIST: { auto restr = dynamic_cast<RestrP2SDIST*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "P2SDIST " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId(); cout << "==" << restr->getP3()->showId() << endl; } break; case RT_P2SDISTEX: { auto restr = dynamic_cast<RestrP2SDISTEX*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "P2SDISTEX " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getP1()->showId() << "---" << restr->getP2()->showId(); cout << "==" << restr->getP3()->showId() << endl; } break; case RT_S2SANGLE: { auto restr = dynamic_cast<RestrS2SANGLE*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "S2SANGLE " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl; } break; case RT_S2SORTHO: { auto restr = dynamic_cast<RestrS2SORTHO*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "S2SORTHO " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl; } break; case RT_S2SPARAL: { auto restr = dynamic_cast<RestrS2SPARAL*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "S2SPARAL " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl; } break; case RT_S2SEQUALS: { auto restr = dynamic_cast<RestrS2SEQUALS*>(core.searchIDRestr(core.getRestrIDs()[i])); cout.precision(2); cout << setw(16) << "S2SEQUALS " << setw(3) << "ID: " << setw(2) << restr->showId(); cout << setw(13) << "violation: " << setw(8) << restr->violation(); cout << setw(8) << restr->getS1()->showId() << "---" << restr->getS2()->showId() << endl; } break; } } core.ShowRestr(); }
bool TestSegCircle ( Segment3d const & S, Circle const & C ) { return Distance2d::Distance2PointSeg( C.getCenter(), S ) <= C.getRadiusSquared(); }
bool TestLineCircle ( Line3d const & L, Circle const & C ) { return Distance2d::Distance2PointLine( C.getCenter(), L ) <= C.getRadiusSquared(); }