UVA 11178 Morley's Theorem(计算几何入门)

就是求一个三角形的6条角三分线构成的一个正三角形的坐标。

算出角度,直接直线相交求交点。

简单题,主要是为了验证我的模板的正确性。


#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const double eps = 1e-10;

struct Point
{
      double x,y;
      Point(double x = 0,double y = 0) : x(x) , y(y){}
};

typedef Point Vector;

Vector operator + (Vector A,Vector B)
{
      return Vector(A.x + B.x, A.y + B.y);
}

Vector operator - (Vector A,Vector B)
{
      return Vector(A.x - B.x, A.y - B.y);
}

Vector operator * (Vector A,double P)
{
      return Vector(A.x * P,A.y * P);
}

Vector operator / (Vector A,double B)
{
      return Vector(A.x / B,A.y / B);
}

bool operator < (Vector A, Vector B)
{
      return A.x < B.x || (A.x == B.x && A.y < B.y);
}


double Dot(Vector A,Vector B)
{
      return A.x * B.x + A.y * B.y;
}

double Length(Vector A)
{
      return sqrt(Dot(A,A));
}

double Angle(Vector A,Vector B)
{
      return acos(Dot(A,B) / Length(A) / Length(B));
}

double Cross(Vector A,Vector B)
{
      return fabs(A.x * B.y - A.y * B.x);
}

Vector Rotate(Vector A,double rad)
{
      return Vector(A.x * cos(rad) - A.y * sin(rad) , A.x * sin(rad) + A.y * cos(rad));
}

Point GLIs(Point P,Vector V,Point Q,Vector W)
{
      Vector U = P - Q;
      double t = Cross(W,U) / Cross(V,W);
      return P + V * t;
}


Point solve(Point A,Point B,Point C)
{
      Vector a1 = A - B , a2 = C - B;
      double rad1 = Angle(a1,a2); rad1 /= 3;
      Vector a3 = A - C , a4 = B - C;
      double rad2 = Angle(a3,a4); rad2 = rad2 * -1 / 3;
      Vector a = Rotate(a2,rad1);
      Vector b = Rotate(a4,rad2);
      return GLIs(B,a,C,b);
      
}

Point Read_Point()
{
      Point a;
      scanf("%lf%lf",&a.x,&a.y);
      return a; 
}


int main()
{
      int T;
      scanf("%d",&T);
      for (int cas = 1;cas <= T;cas++)
      {
            Point A,B,C,D,E,F;
            A = Read_Point();
            B = Read_Point();
            C = Read_Point();
            D = solve(A,B,C);
            E = solve(B,C,A);
            F = solve(C,A,B);
		
		//printf("%f %f %f %f %f %f\n",A.x,A.y,B.x,B.y,C.x,C.y);            
            printf("%.6f %.6f %.6f %.6f %.6f %.6f\n",D.x,D.y,E.x,E.y,F.x,F.y);
      }
      return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值