uva 11178

题意:作三角形ABC每个内角的三等分线,相交乘三角形DEF,则DEF是等边三角形。已知A,B,C三点坐标,问D,E,F三点坐标。
题解:用对于点D,是向量BC逆时针旋转∠ABC的三分之一的直线与向量CB逆时针旋转∠ACB的三分之一的直线的交点,坐标都有了,可以直接计算。

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct Point {
    double x, y;
    Point(double x = 0, double y = 0):x(x), y(y) {}
};

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

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

Point operator * (Point A, double p) {
    return Point(A.x * p, A.y * p);
}

Point operator / (Point A, double p) {
    return Point(A.x / p, A.y / p);
}

bool operator < (const Point& a, const Point& b) {
    return a.x < b.x || (a.x == b.x && a.y < b.y);
}

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

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

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

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 BC = c - b;
    Point BA = a - b;
    double a1 = acos(Dot(BC, BA) / (Length(BC) * Length(BA)));
    Point V1 = Rotate(BC, a1 / 3);

    Point CB = b - c;
    Point CA = a - c;
    double a2 = acos(Dot(CB, CA) / (Length(CB) * Length(CA)));
    Point V2 = Rotate(CB, -a2 / 3); //负数顺时针旋转

    return GetLineIntersection(b, V1, c, V2);

}

int main() {
    int t;
    Point A, B, C, D, E, F;
    scanf("%d", &t);
    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("%lf %lf %lf %lf %lf %lf\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、付费专栏及课程。

余额充值