题意:作三角形ABC每个内角的三等分线,相交乘三角形DEF,则DEF是等边三角形。已知A,B,C三点坐标,问D,E,F三点坐标。
题解:用对于点D,是向量BC逆时针旋转∠ABC的三分之一的直线与向量CB逆时针旋转∠ACB的三分之一的直线的交点,坐标都有了,可以直接计算。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct Point {
double x, y;
Point(double x = 0, double y = 0):x(x), y(y) {}
};
Point operator + (Point A, Point B) {
return Point(A.x + B.x, A.y + B.y);
}
Point operator - (Point A, Point B) {
return Point(A.x - B.x, A.y - B.y);
}
Point operator * (Point A, double p) {
return Point(A.x * p, A.y * p);
}
Point operator / (Point A, double p) {
return Point(A.x / p, A.y / p);
}
bool operator < (const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
double Dot(Point A, Point B) {
return A.x * B.x + A.y * B.y;
}
double Cross(Point A, Point B) {
return A.x * B.y - A.y * B.x;
}
double Length(Point A) {
return sqrt(Dot(A, A));
}
Point Rotate(Point A, double rad) {
return Point(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
Point GetLineIntersection(Point P, Point v, Point Q, Point w) {
Point u = P - Q;
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
Point get(Point a, Point b, Point c) {
Point BC = c - b;
Point BA = a - b;
double a1 = acos(Dot(BC, BA) / (Length(BC) * Length(BA)));
Point V1 = Rotate(BC, a1 / 3);
Point CB = b - c;
Point CA = a - c;
double a2 = acos(Dot(CB, CA) / (Length(CB) * Length(CA)));
Point V2 = Rotate(CB, -a2 / 3); //负数顺时针旋转
return GetLineIntersection(b, V1, c, V2);
}
int main() {
int t;
Point A, B, C, D, E, F;
scanf("%d", &t);
while (t--) {
scanf("%lf%lf%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y, &C.x, &C.y);
D = get(A, B, C);
E = get(B, C, A);
F = get(C, A, B);
printf("%lf %lf %lf %lf %lf %lf\n", D.x, D.y, E.x, E.y, F.x, F.y);
}
return 0;
}