sdut 2603 向量的旋转变换与旋转角的关系(山东第4届省赛)
2017-04-18 14:31
357 查看
Problem Description
Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescuethe princess, a prince who wanted to marry the princess set out immediately. Yet, the beast set a maze. Only if the prince find out the maze’s exit can he save the princess.
Now, here comes the problem. The maze is a dimensional plane. The beast is smart, and he hidden the princess
snugly. He marked two coordinates of an equilateral triangle in the maze.
The two marked coordinates are A(x1,y1)
and B(x2,y2). The third coordinate
C(x3,y3) is the maze’s exit. If the
prince can find out the exit, he can save the princess. After the prince comes into the maze, he finds out the A(x1,y1)
and B(x2,y2), but he doesn’t know
where the C(x3,y3) is. The prince
need your help. Can you calculate the C(x3,y3)
and tell him?
Input
The first line is an integer T(1 <= T <= 100) which is the number of test cases. T test cases follow.Each test case contains two coordinates A(x1,y1)
and B(x2,y2), described by four floating-point
numbers x1, y1, x2,
y2 ( |x1|, |y1|,
|x2|, |y2| <=
1000.0).
Please notice that A(x1,y1)
and B(x2,y2) and C(x3,y3)
are in an anticlockwise direction from the equilateral triangle. And coordinates A(x1,y1)
and B(x2,y2) are given by anticlockwise.
Output
For each test case, you should output the coordinate of C(x3,y3),the result should be rounded to 2 decimal places in a line.
Example Input
4 -100.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 0.00 0.00 100.00 100.00 1.00 0.00 1.866 0.50
Example Output
(-50.00,86.60) (-86.60,50.00) (-36.60,136.60) (1.00,1.00)
Hint
Author
2013年山东省第四届ACM大学生程序设计竞赛本题在二维坐标中给出等边三角形其中的两个点(逆时针顺序),求第三个点的坐标
用到了向量的旋转变换:
向量p1(x1,y1)逆时针旋转
到p(x,y),二者的坐标关系为
将向量AB平移到坐标原点求出旋转后的点,然后再平移回去即可
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<sstream>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const double pi=3.141592;
int main()
{
int T;
cin>>T;
while(T--)
{
double x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
double d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double dx=x2-x1;
double dy=y2-y1;
double xx=dx*0.5-dy*sqrt(3)/2+x1;
double yy=dx*sqrt(3)/2+dy*0.5+y1;
printf("(%0.2f,%0.2f)\n",xx,yy);
}
return 0;
}
相关文章推荐
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
- sdut2408 Pick apples(山东第三届省赛)
- sdut2161 Simple Game(山东第二届省赛)
- 定向和旋转向量四元数之间的关系
- sdut 2603 Rescue The Princess(算是解析几何吧)(山东省第四届ACM省赛A题)
- 四元数运动学笔记(2)旋转向量,旋转矩阵和四元数的关系
- sdut 2170 The Largest SCC(山东第二届省赛)
- SDUT 3893 威佐夫+nim博弈(第八届山东ACM省赛A题)
- 旋转向量
- 编程珠玑之第二章questionB: n元一维向量旋转问题
- Unity中绕任意轴任意角度旋转向量
- UVA 10652 || Board Wrapping(向量旋转
- 编程珠玑第二章问题B: n元一维向量旋转问题之java实现
- POJ2991–Crane(成段更新+向量旋转)
- poj 1182(并查集的边权向量关系)
- BZOJ-2829信用卡凸包 凸包+向量旋转计算
- 向量相似度的计算和向量夹角余旋的关系
- 探讨:物体绕任意向量的旋转-四元数法VS.旋转矩阵法的性能比较
- Mean shift向量、概率密度函数、概率密度函数梯度之间的关系
- Archipelago - SGU 120(计算几何向量旋转)