思路:這題注意練習一下向量的旋轉,和直線的相交。
注意代碼中用vector表示向量,用point表示點,這一點還是非常好的。
今天是六一兒童節哈,在圖書館A題,呵呵。
[cpp]
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
struct point {
double x;
double y;
point(double x = 0, double y = 0) : x(x), y(y) {}
};
typedef point Vector;
Vector operator - (point A, point B) {
return point(A.x-B.x, A.y-B.y);
}
Vector operator + (Vector A, Vector B) {
return Vector(A.x+B.x, A.y+B.y);
}
const double eps = 1e-10;
int dcmp(double x) {
if(fabs(x) < eps) return 0;
if(x > 0) return 1;
return -1;
}
double Dot(Vector A, Vector B) {
return A.x*B.x + A.y*B.y;
}
double Length(Vector A) {
return sqrt(Dot(A, A));
}
double Cross(Vector A, Vector B) {
return A.x*B.y - A.y*B.x;
}
Vector operator * (Vector A, double p) {
return Vector(A.x*p, A.y*p);
}
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));
}
//調用前確保兩條直線相交。當且僅當Cross(v,w)非零。
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;
}
point read_point() {
point tmp;
scanf("%lf%lf", &tmp.x, &tmp.y);
return tmp;
}
point getD(point A, point B, point C) {
Vector v1 = C - B, v2 = A - B;
double a1 = Angle(v1, v2); //兩個向量的夾角。
v1 = Rotate(v1, a1/3); //逆時針旋轉,弧度.
Vector v3 = A - C, v4 = B - C;
double a3 = Angle(v3, v4);
v3 = Rotate(v3, a3*2/3);
return GetLineIntersection(B, v1, C, v3);//求直線的交點.
}
int main()
{
int T;
point A, B, C, D, E, F;
scanf("%d", &T);
while(T--) {
A = read_point();
B = read_point();
C = read_point();
D = getD(A, B, C);
E = getD(B, C, A);
F = getD(C, A, B);
printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y);
}
return 0;
}
/**
測試數據:
21
1 1 2 2 1 2
0 0 100 0 50 50
1.316987 1.816987 1.183013 1.683013 1.366025 1.633975
56.698730 25.000000 43.301270 25.000000 50.000000 13.397460
**/