UVa11187

莫勒定理,证明如下:

 

请结合下图看代码:


 

#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

#define pi acos(-1.0)

double lawofcosine(double a, double b, double c)
{
    return acos((a*a+b*b-c*c)/(2.0*a*b));
}

double getangle(double x1, double y1, double x2, double y2)
{
    return atan2(1.0*(y2-y1),1.0*(x2-x1));
}

double getdis(double x1, double y1, double x2, double y2)
{
    return sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
}

double solveequation_x(double x1, double y1, double x2, double y2, double k1, double k2)
{
    return (y1-y2+k2*x2-k1*x1)/(k2-k1);
}

typedef struct point
{
    double x, y;
} p;


int main()
{
    p A, B, C, D, E, F;
    int n;
    cin>>n;
    while(n--)
    {
        cin>>A.x>>A.y>>B.x>>B.y>>C.x>>C.y;

        double a,b,c;

        //cout << A.x << ' ' << A.y << ' ' << B.x << ' ' << B.y << ' ' << C.x << ' ' << C.y << endl;

        a = getdis(B.x,B.y,C.x,C.y);
        b = getdis(C.x,C.y,A.x,A.y);
        c = getdis(B.x,B.y,A.x,A.y);

        //cout << "dis" << ' ' << a << '!' << b << '!' << c << endl;

        double alpha = lawofcosine(b,c,a);
        double beta = lawofcosine(a,c,b);
        double gama = lawofcosine(a,b,c);

        //cout << "angle" << ' ' << alpha * 180 / pi << '@' << beta * 180 / pi << '@' << gama * 180 / pi<<endl;

        double theta1 = getangle(A.x,A.y,B.x,B.y);//k(AB)angle
        double theta2 = getangle(B.x,B.y,C.x,C.y);//k(CB)angle
        double theta3 = getangle(A.x,A.y,C.x,C.y);//k(AC)angle

        //cout << "theta" << ' ' << theta1 * 180 / pi << '#' << theta2 * 180 / pi<< '#' << theta3 * 180 / pi<< endl;

        double k1 = tan(theta2 + beta / 3.0);//k(BD)
        double k2 = tan(theta3 + gama / 3.0);//k(CE)
        double k3 = tan(theta3 + 2.0 * gama / 3.0);//k(CD)
        double k4 = tan(theta1 + 2.0 * alpha / 3.0);//k(AE)

        //cout << "k" << '$' << k1 * 180 / pi << '$' << k2 * 180 / pi << '$' << k3 * 180 / pi << '$' << k4 * 180 / pi << endl;

        D.x = (k1 * B.x - k3 * C.x + C.y - B.y) / (k1 - k3);
        D.y = D.x * k1 - k1 * B.x + B.y;

        E.x = (k2 * C.x - k4 * A.x + A.y - C.y) / (k2 - k4);
        E.y = E.x * k2 - k2 * C.x + C.y;

        double x1, y1, x2, y2;
        x2 = D.x, y2 = D.y, x1 = E.x, y1 = E.y;

        double alpha1 = atan2((y1-y2),(x1-x2));
        double l = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
        double x3=x2+l*cos(alpha1+pi/3);
        double y3=y2+l*sin(alpha1+pi/3);

        F.x = x3, F.y = y3;

        cout << fixed << setprecision(7) << D.x << ' ' << D.y << ' ' << E.x << ' ' << E.y << ' ' << F.x << ' ' << F.y << endl;
    }
}

 


变成解析几何就太麻烦了,可是欧氏几何又没有现成的关系

 

posted @ 2013-07-14 23:21  爱生活,爱编程  阅读(239)  评论(0编辑  收藏  举报