Uva - 11178 - Morley's Theorem

本文提供了一段C++代码,用于求解Morley定理中三个特定点的坐标。通过旋转和平移向量的方法来确定这些点的位置,并利用点线交点公式找到交点坐标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:求Morley定理的3个点的坐标。

题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18543

——>>照要求做~

#include <cstdio>
#include <cmath>

using namespace std;

struct Point{
    double x;
    double y;
    Point(double x = 0, double y = 0):x(x), y(y){}
}p[3];

typedef Point Vector;

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

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

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

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

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

void read(){
    for(int i = 0; i < 3; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
}

Point getD(Point A, Point B, Point C){
    Vector BC = C - B, BA = A - B;
    Vector CB = B - C, CA = A - C;
    BC = Rotate(BC, Angle(BC, BA) / 3);
    CB = Rotate(CB, -Angle(CB, CA) / 3);
    return GetLineIntersection(B, BC, C, CB);
}

void solve(){
    Point D, E, F;
    D = getD(p[0], p[1], p[2]);
    E = getD(p[1], p[2], p[0]);
    F = getD(p[2], p[0], p[1]);
    printf("%.6f %.6f %.6f %.6f %.6f %.6f\n", D.x, D.y, E.x, E.y, F.x, F.y);
}

int main()
{
    int N;
    scanf("%d", &N);
    while(N--){
        read();
        solve();
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值