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

来源:互联网 发布:python3网络数据采集 编辑:程序博客网 时间:2024/05/28 16:28

简单的计算几何题目     求出一个d点    其余的点具有相同的解法   


#include<cstdio>#include<cmath>#include<algorithm>#define eps 1e-10using 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;}


原创粉丝点击