计算几何初步-向量的旋转 Rescue The Princess
来源:互联网 发布:string 转 日历 java 编辑:程序博客网 时间:2024/05/19 12:25
题目地址:http://acm.upc.edu.cn/problem.php?id=2217
题目描述
Several days ago, a beast caught a beautiful princess and the princess was put in prison. To rescue the 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?
输入
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 theequilateral triangle. And coordinates A(x1,y1) and B(x2,y2) are given by anticlockwise.
输出
示例输入
4-100.00 0.00 0.00 0.000.00 0.00 0.00 100.000.00 0.00 100.00 100.001.00 0.00 1.866 0.50
示例输出
(-50.00,86.60)(-86.60,50.00)(-36.60,136.60)(1.00,1.00)
告诉你是一个等边三角形并且给你两个点a(x1,y1)和b(x2,y2),让你求第三个点,按照逆时针顺序求。
我这里是用的纯三角函数做的。
#include <stdio.h>#include <math.h>int n;double xx1,xx2,yy1,yy2;int main() {double l, atana, pi = 3.14159265358;freopen("in.txt", "r", stdin);scanf("%d", &n);while(n--){scanf("%lf %lf %lf %lf", &xx1,&yy1, &xx2, &yy2);double tmp = (double)(xx2-xx1) * (xx2-xx1) + (yy2-yy1)*(yy2-yy1);l = sqrt(tmp);atana = atan2((yy2-yy1) , (xx2-xx1)) + pi/3;printf("(%.2lf,%.2lf)\n", cos(atana)*l + xx1, sin(atana)*l + yy1);}return 0;}
这里有推导的公式:
http://www.cnblogs.com/E-star/archive/2013/06/11/3131563.html
我们可以这样认为:对于任意点A(x,y),A非原点,绕原点旋转θ角后点的坐标为:(x*cosθ- y * sinθ, y*cosθ + x * sinθ)
因此又有此解法:
- #include<stdio.h>
- #include<math.h>
- int main()
- {
- int t;
- scanf("%d",&t);
- while(t--)
- {
- double x1,x2,y1,y2,x3,y3,x,y;
- scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
- x=x2-x1;
- y=y2-y1;
- x3=x/2-y*sqrt(3)/2+x1;
- y3=y/2+x*sqrt(3)/2+y1;
- printf("(%.2f,%.2f)\n",x3,y3);
- }
- return 0;
- }
- 计算几何初步-向量的旋转 Rescue The Princess
- Rescue The Princess(计算几何)
- 第四届 山东省ACM Rescue The Princess(计算几何)
- sdut 2603 Rescue The Princess (很水的几何题)
- 计算几何,三维向量的旋转
- poj 2957 计算几何向量的旋转
- SDUT 2603-Rescue The Princess(几何题)
- 山东省第四届ACM省赛题——Rescue The Princess(计算几何)
- 山东省第四届ACM大学生程序设计竞赛-Rescue The Princess(计算几何)
- 山东省第四届ACM程序设计大赛 Problem A:Rescue The Princess (计算几何)
- 计算几何之向量旋转
- Board Wrapping(计算几何求凸包加向量的旋转)
- Rescue The Princess
- UPC2217: Rescue The Princess
- A:Rescue The Princess
- Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛Rescue The Princess(一个点绕另一个点的旋转)
- 2217: Rescue The Princess(UPC)
- zoj 1073 Round and Round We Go
- 机房管理系统逻辑关系
- 个人博文索引
- 你的第一个Windows程序——关闭窗口
- 解决Access连接 accdb 不可识别的数据库格式异常
- 计算几何初步-向量的旋转 Rescue The Princess
- 斜45度地图简介、坐标系转换以及数据碰撞
- 内存详解
- 【中级】C++析构函数抛出异常
- android目录说明
- Java面向对象之类和封装
- esri/tasks/TrimExtendParameters
- hdu 2426 Interesting Housing Problem(最大权值匹配)
- WebView基本使用