用c++设计直线类,然后判断直线与圆的位置关系

1个回答

  • #include

    #include

    class line //定义直线类

    {

    public:

    x05float a,b,c; //标准式

    };

    class circle //定义圆类

    {

    public:

    x05float x,y,r;//圆心及半径

    };

    int main(int argc,char**argv)

    {

    x05line myline;

    x05circle mycircle;

    x05

    x05coutmyline.a;

    x05coutmyline.b;

    x05coutmyline.c;

    x05coutmycircle.x;

    x05coutmycircle.y;

    x05coutmycircle.r;

    x05float mydistance;

    x05mydistance=fabs(myline.a*mycircle.x+myline.b*mycircle.y+myline.c)/sqrt(myline.a*myline.a+myline.b*myline.b);//计算圆心与直线的距离

    x05//比较R与圆心到直线的距离

    x05if (mydistance