UVA 11178 Morley's Theorem(二维几何基础)

来源:互联网 发布:sdcms 域名未授权 编辑:程序博客网 时间:2024/05/29 02:11

题意:给定一个三角形,求每个角的三等分线相交形成的三角形的三个坐标

题解:直接模板

#include <cstdio>#include <iostream>#include <cstring>#include <string>#include <cstdlib>#include <algorithm>#include <cmath>#include <set>#include <list>#include <queue>using namespace std;#define L(i) i<<1#define R(i) i<<1|1const int N = 100005;const double eps = 1e-10;struct Point{    double x,y;    Point(double x = 0,double y = 0):x(x),y(y){}    Point operator +(Point a)    {        return Point(x + a.x,y + a.y);    }    Point operator -(Point a)    {        return Point(x - a.x,y-a.y);    }    Point operator *(double p)    {        return Point(x * p,y * p);    }};int dcmp(double x){    if(fabs(x) < eps)        return 0;    else        return x < 0 ? -1 : 1;}double Dot(Point A,Point B){    return A.x * B.x + A.y * B.y;}double Length(Point A){    return sqrt(Dot(A,A));}double Angle(Point A,Point B){    return acos(Dot(A,B) / Length(A) / Length(B));}double Cross(Point A,Point B){    return A.x*B.y - A.y*B.x;}Point Rotate(Point A,double rad){    return Point(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));}Point GetLineIntersection(Point P,Point v,Point Q,Point w){    Point u = P - Q;    double t = Cross(w,u) / Cross(v,w);    return P + v*t;}Point get(Point A,Point B,Point C){    Point v1 = C-B;    double a1 = Angle(A-B,v1);    //printf("%.6lf\n",a1);    v1 = Rotate(v1,a1/3);    //printf("%.6lf %.6lf\n",v1.x,v1.y);    Point v2 = B-C;    double a2 = Angle(A - C,v2);    //printf("%.6lf\n",a2);    v2 = Rotate(v2,-a2/3);    //printf("%.6lf %.6lf\n",v2.x,v2.y);    return GetLineIntersection(B,v1,C,v2);}int main(){    int t,n;    scanf("%d",&t);    Point A,B,C,D,E,F;    while(t--)    {        scanf("%lf%lf%lf%lf%lf%lf",&A.x,&A.y,&B.x,&B.y,&C.x,&C.y);        D = get(A,B,C);        E = get(B,C,A);        F = get(C,A,B);        printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n",D.x,D.y,E.x,E.y,F.x,F.y);    }    return 0;}


0 0
原创粉丝点击