UVa 11178 Morley's Theorem (向量旋转)

262 篇文章 0 订阅
40 篇文章 0 订阅

http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2119


/*0.025s*/

#include<cstdio>
#include<cmath>

struct P
{
	double x, y;
	P(double x = 0.0, double y = 0.0): x(x), y(y) {}
	void read() {scanf("%lf%lf", &x, &y);}
	void output() {printf("%f %f", x, y);}
};
typedef P Vector;

Vector operator + (const Vector &A, const Vector &B) {return Vector(A.x + B.x, A.y + B.y);}
Vector operator - (const P &A, const P &B) {return Vector(A.x - B.x, A.y - B.y);}
Vector operator * (const Vector &A, double p) {return Vector(A.x * p, A.y * p);}
Vector Rotate(const Vector &A, double rad) {return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));}
inline double Dot(const Vector &A, const Vector &B) {return A.x * B.x + A.y * B.y;}
inline double Cross(const Vector &A, const Vector &B) {return A.x * B.y - A.y * B.x;}
inline double Length(const Vector &A) {return hypot(A.x, A.y);}
inline double Angle(const Vector &A, const Vector &B) {return acos(Dot(A, B) / Length(A) / Length(B));}

inline P GetLineIntersection(const P &p1, const Vector &s1, const P &p2, const Vector &s2)
{
	return p1 + s1 * (Cross(s2, p1 - p2) / Cross(s1, s2));
}

P getP(P A, P B, P C)
{
	Vector v1 = Rotate(C - B, Angle(A - B, C - B) / 3);
	Vector v2 = Rotate(B - C, -Angle(A - C, B - C) / 3); /// 负数表示顺时针旋转
	return GetLineIntersection(B, v1, C, v2);
}

int main()
{
	int T;
	P A, B, C;
	scanf("%d", &T);
	while (T--)
	{
		A.read(), B.read(), C.read();
		getP(A, B, C).output(), putchar(32);
		getP(B, C, A).output(), putchar(32);
		getP(C, A, B).output(), putchar(10);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值