コード例 #1
0
ファイル: circle_2d.cpp プロジェクト: MrKarimiD/Merge
/*!

 */
int
Circle2D::intersection( const Circle2D & circle,
                        Vector2D * sol1,
                        Vector2D * sol2 ) const
{
    double rel_x = circle.center().x - this->center().x;
    double rel_y = circle.center().y - this->center().y;

    double center_dist2 = rel_x * rel_x + rel_y * rel_y;
    double center_dist = std::sqrt( center_dist2 );

    if ( center_dist < std::fabs( this->radius() - circle.radius() )
         || this->radius() + circle.radius() < center_dist )
    {
        return 0;
    }

    //std::cerr << "must exist intersection C1: " << this->center() << this->radius()
    //        << " C2: " << circle.center() << circle.radius()
    //        << std::endl;
    // line that passes through the intersection points
    Line2D line( -2.0 * rel_x,
                 -2.0 * rel_y,
                 circle.center().r2()
                 - circle.radius() * circle.radius()
                 - this->center().r2()
                 + this->radius() * this->radius() );

    return this->intersection( line, sol1, sol2 );
}
コード例 #2
0
// ==================================================================================
Vector2D TacticTransferObject::AvoidtoEnterCircle(Circle2D Ci, Vector2D pnt, Vector2D finPOS)
{
    //    Avoided=false;
    Segment2D S(pnt,finPOS);
    if(Ci.HasIntersection(S) || Ci.contains(pnt) || Ci.contains(finPOS))
    {
        //        qDebug() << " HAS INTERSECTION WITH CIRCLE !! DO NOT ENTER THIS CIRCLE PLEASE !!!";
//                qDebug() << " HAS INTERSECTION WITH CIRCLE ( " << Ci.center().x << "," << Ci.center().y << " ) , Radius : " << Ci.radius() ;
        Vector2D c2r = pnt - Ci.center() ;
        Vector2D c2f = finPOS - Ci.center() ;
        c2r.setLength(Ci.radius()+50);
        AngleDeg angle=c2r.dir() - c2f.dir();
        //double ang=c2r.dir().radian() - c2f.dir().radian();
        if (angle.radian() > M_PI) angle -=  AngleDeg(M_PI) *= 2;
        if (angle.radian() < -M_PI) angle += AngleDeg(M_PI) *= 2;

        //if (ang > M_PI) ang -= 2 * M_PI;
        //if (ang < -M_PI) ang += 2 * M_PI;

        //qDebug() << "c2r DIRECTION = " << c2r.dir().degree() << "c2f DIRECTION = " << c2f.dir().degree() << "   ANGLE  = " << angle.degree() << "    ANG =" << ang*57.32;
        int div=int(Ci.radius()/50);
        //        qDebug() << "div = " << div ;
        angle=angle/=min(div,6);
        angle=c2r.dir() - angle;
        c2r.setDir(angle);// c2f.dir()));
        Vector2D p = Ci.center() + c2r ;
        //        Avoided=true;
//                    qDebug() << " Avoided point is : (" << finPOS.x << "," <<finPOS.y << ")  & Corrected is : ("<<
//                                p.x << "," << p.y << ")" ;
        return p;
    }
    else
    {
        return finPOS;
    }


}