本文主要是介绍uva 11178 Morley's Theorem,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题意:
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);}//VectorPoint 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;
}
这篇关于uva 11178 Morley's Theorem的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!