博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
坐标旋转公式
阅读量:6982 次
发布时间:2019-06-27

本文共 2874 字,大约阅读时间需要 9 分钟。

坐标旋转公式

x1=cos(angle)*x-sin(angle)*y;

y1=cos(angle)*y+sin(angle)*x;

其中x,y表示物体相对于旋转点旋转angle的角度之前的坐标,x1,y1表示物体旋转angle后相对于旋转点的坐标

 

从数学上来说,此公式可以用来计算某个点绕另外一点旋转一定角度后的坐标,例如:A(x,y)绕B(a,b)旋转β度后的位置为C(c,d),则x,y,a,b,β,c,d有如下关系式:

1。设A点旋转前的角度为δ,则旋转(逆时针)到C点后角度为δ+β

2。求A,B两点的距离:dist1=|AB|=y/sin(δ)=x/cos(δ)

3。求C,B两点的距离:dist2=|CB|=d/sin(δ+β)=c/cos(δ+β)

4。显然dist1=dist2,设dist1=r所以:

  r=x/cos(δ)=y/sin(δ)=d/sin(δ+β)=c/cos(δ+β)

5。由三角函数两角和差公式知:

  sin(δ+β)=sin(δ)cos(β)+cos(δ)sin(β)

  cos(δ+β)=cos(δ)cos(β)-sin(δ)sin(β)

  所以得出:

  c=r*cos(δ+β)=r*cos(δ)cos(β)-r*sin(δ)sin(β)=xcos(β)-ysin(β)

  d=r*sin(δ+β)=r*sin(δ)cos(β)+r*cos(δ)sin(β)=ycos(β)+xsin(β)

即旋转后的坐标c,d只与旋转前的坐标x,y及旋转的角度β有关

 

从图中可以很容易理解出A点旋转后的C点总是在圆周上运动,圆周的半径为|AB|,利用这点就可以使物体绕圆周运动,即旋转物体。

 

上面公式是相对于B点坐标来的,也就是假如B点位(0,0)可以这么做。现在给出可以适合任意情况的公式:

x0 = dx * cos(β) - dy * sin(β)

y0 = dy * cos(β) + dx * sin(β)

 

参数解释:

x0,y0是旋转后相对于中心点的坐标,也就是原点的坐标,但不是之前点旋转后的实际坐标,还要计算一步,

β旋转角度,可以是顺时针或者逆时针。

dx是旋转前的x坐标-旋转后的x坐标

dy是旋转前的y坐标-旋转后的y坐标

 

x1=a+x0;

y1=b+y0;

 

上面才是旋转后的实际坐标,其中a,b是原点坐标

 

下面是上面图的公式解答:

x0=(x-a)*cos(β)-(y-b)*sin(β);

y0=(y-b)*cos(β)+(x-a)*sin(β);

x1=x0+a;

y1=y0+b;

 

 

Rescue The Princess

 

题目描述

    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 the equilateral triangle. And coordinates A(x1,y1) and B(x2,y2) are given by anticlockwise.

输出

    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.

示例输入

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)

提示

 

来源

2013年山东省第四届ACM大学生程序设计竞赛
cin>>a>>b>>x>>y ;       X=(x-a)*0.5-(y-b)*sqrt(3.0)*0.5 +a;       Y=(y-b)*0.5+(x-a)*sqrt(3.0)*0.5 +b;       printf("(%.2lf,%.2lf)\n",X,Y) ;

 

 

转载于:https://www.cnblogs.com/liyangtianmen/p/3304195.html

你可能感兴趣的文章
内部毕业学生对老男孩教育的客观评价
查看>>
SQL Server 表和索引存储结构
查看>>
Linux监控之系统性能
查看>>
CIO要更有担当
查看>>
为什么用Immutable.js代替普通js对象?
查看>>
马云:现实版岳不群?
查看>>
IT从花钱到赚钱——惠普IT转型记
查看>>
Ossim系统常见测试方法
查看>>
创业那些年,我们一起走过的坑
查看>>
瞎扯赚大钱的逻辑
查看>>
"人肉"云-【软件和信息服务】2014.02
查看>>
华为5.3亿美元收购赛门铁克在合资公司中股权
查看>>
Asp.net mvc4用JQuery插件实现异步上传
查看>>
使用组策略控制可移动存储访问
查看>>
监控平台实施方案
查看>>
RSA2012系列(2):HP谈他们的安全智能平台
查看>>
统帅转型:轻时尚时代挺进年轻领地
查看>>
Photoshop制作一只可爱的卡通小鸟
查看>>
飞鹤借力品质打造奶粉生态 胜算几何?
查看>>
1-2-Active Directory 域服务准备概述
查看>>