题目地址:https://vjudge.net/problem/UVA-11178
题目:
给出ABC坐标,求角的三平分线构成的等边三角形的三个顶点的坐标
ac代码:
向量旋转+直线交点
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-6;//eps用于控制精度,或者更高精度
const double pi = acos(-1.0);//pi
struct Point//点或向量
{
double x, y;
Point(double x = 0, double y = 0) :x(x), y(y) {}
};
typedef Point Vector;
Vector operator + (Vector a, Vector b)//向量加法
{
return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (Vector a, Vector b)//向量减法
{
return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (Vector a, double p)//向量数乘
{
return Vector(a.x * p, a.y * p);
}
Vector operator / (Vector a, double p)//向量数除
{
return Vector(a.x / p, a.y / p);
}
int dcmp(double x)//精度三态函数(>0,<0,=0)
{
if (fabs(x) < eps)return 0; //等于
else return x < 0 ? -1 : 1;//小于,大于
}
bool operator == (const Point &a, const Point &b)//向量相等
{
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
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 Angle(Vector a, Vector b)//夹角,弧度制
{
return acos(Dot(a, b) / Length(a) / Length(b));
}
double Cross(Vector a, Vector b)//外积
{
return a.x * b.y - a.y * b.x;
}
Vector Rotate(Vector a, double rad)//逆时针旋转rad弧度
{
return Vector(a.x*cos(rad) - a.y*sin(rad), a.x*sin(rad) + a.y*cos(rad));
}
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w)//两直线的交点
{
Vector u = P - Q;//QP
double t = Cross(w, u) / Cross(v, w);
return P + v * t;
}
Point getPoint(Point A, Point B, Point C)
{
Vector BC = C - B, CA = A - C, BA = A - B, CB = B - C;
BC = Rotate(BC, Angle(BA, BC)/3.0);
CA = Rotate(CA, Angle(CB, CA)*2.0/3.0);
return GetLineIntersection(B, BC, C, CA);
}
int main()
{
//freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
int t;
scanf("%d", &t);
while(t--)
{
Point A, B, C;
double xa, ya, xb, yb, xc, yc;
scanf("%lf %lf %lf %lf %lf %lf", &xa, &ya, &xb, &yb, &xc, &yc);
A={xa, ya};B={xb, yb};C={xc, yc};
Point D = getPoint(A, B, C);
Point E = getPoint(B, C, A);
Point F = getPoint(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;
}