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


發佈了115 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章