您的位置:首页 > 其它

UVA 11178 - Morley's Theorem 简单的计算几何

2013-10-22 21:18 323 查看
简单的计算几何题目     求出一个d点    其余的点具有相同的解法   

#include<cstdio>
#include<cmath>
#include<algorithm>
#define eps 1e-10

using namespace std;

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);
}

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 Cross(Vector A, Vector B)
{
return A.x*B.y -A.y*B.x;
}

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

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 GetLineIntersection(Point P,Vector v, Point Q, Vector w)
{
Vector u = P -Q;
double t = Cross(w,u) / Cross(v,w);
return P + v*t;
}

int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
int N;
scanf("%d",&N);
while(N--)
{
Point a,b,c,d,e,f;
scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y);
double ang_a,ang_b,ang_c;
ang_a = Angle(b-a,c-a);
ang_b = Angle(a-b,c-b);
ang_c = Angle(a-c,b-c);
d = GetLineIntersection(c,Rotate(a-c,2.0*ang_c/3.0),b,Rotate(c-b,1.0*ang_b/3.0));
e = GetLineIntersection(c,Rotate(a-c,1.0*ang_c/3.0),a,Rotate(b-a,2.0*ang_a/3.0));
f = GetLineIntersection(b,Rotate(c-b,2.0*ang_b/3.0),a,Rotate(b-a,1.0*ang_a/3.0));
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",d.x,d.y,e.x,e.y,f.x,f.y);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息