您的位置:首页 > 其它

uva 11178 Morley's Theorem

2015-07-18 15:27 477 查看
题意:

Morley定理:作三角形ABC每个内角的三等分线,相交成三角形DEF,则DEF是等边三角形。

你的任务是根据A、B、C3个点的位置确定D、E、F3个点的位置。

分析:

根据三点的坐标,我们可以确定每条三等分线的直线方程P = P0+tv,P0是直线上一点,v是方向向量,t为参数。两两求交点即可得到D、E、F的坐标,求交点的代码参考了刘汝佳的大白书,对于方程是怎么得到的不理解。

以下附上代码:

#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

struct Point{
double x,y;

Point(){}
Point(double x_, double y_) :
x(x_), y(y_) {}

//Point
Point operator + (const Point &b) const{
return Point(x+b.x,y+b.y);
}

Point operator - (const Point &b) const{
return Point(x-b.x,y-b.y);
}

//Vector
Point operator *(double p) const{
return Point(x*p,y*p);;
}

double operator *(const Point &b) const{//向量点积
return x*b.x+y*b.y;
}

double operator ^(const Point &b) const{
return x*b.y-y*b.x;
}

Point rotate(double rad){
return Point(x*cos(rad)-y*sin(rad),x*sin(rad)+y*cos(rad));
}

double len(){
return sqrt(x*x+y*y);
}
};

struct Line{
Point p;
Point Vd;//方向向量s

Line(){}
Line(Point p_,Point Vd_) :
p(p_),Vd(Vd_){}

};

istream& operator >>(istream &in, Point &b)
{
in >> b.x >> b.y;
return in;
}

ostream& operator <<(ostream &out, Point &b)
{
out << b.x << " " << b.y;
return out;
}

double Angle(Point Va, Point Vb)
{
double x = (Va*Vb)/(Va.len()*Vb.len());
return acos(x);
}

Point Intersect(Line A, Line B)
{
Point V = A.p-B.p;
double t = (B.Vd^V)/(A.Vd^B.Vd);
return A.p+A.Vd*t;
}

Point getPoint(Point A, Point B, Point C)
{
double ABC = Angle(A-B,C-B);
Line OB(B,(C-B).rotate(ABC/3));

double ACB = Angle(A-C,B-C);
Line OC(C,(B-C).rotate(-ACB/3));

return Intersect(OB,OC);
}

int main()
{
int t;
cin >> t;
while(t--){
Point A,B,C;
cin >> A >> B >> C;
Point D = getPoint(A,B,C);
Point E = getPoint(B,C,A);
Point F = getPoint(C,A,B);
cout << fixed;
cout << setprecision(6);
cout << D << " " << E << " " << F << "\n";
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: