2217: Rescue The Princess(UPC)

Description

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?

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.

Sample 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

Sample Output

(-50.00,86.60)
(-86.60,50.00)
(-36.60,136.60)
(1.00,1.00)
题意:知道等边三角形的两个点,求第三个点,并且是逆时针顺序
向量的旋转


 实际做题中我们可能会遇到很多有关及计算几何的问题,其中有一类问题就是向量的旋转问题,下面我们来具体探讨一下有关旋转的问题。


首先我们先把问题简化一下,我们先研究一个点绕另一个点旋转一定角度的问题。已知A点坐标(x1,y1),B点坐标(x2,y2),我们需要求得A点绕着B点旋转θ度后的位置。


A点绕B点旋转θ角度后得到的点,问题是我们要如何才能得到A' 点的坐标。(向逆时针方向旋转角度正,反之为负)研究一个点绕另一个点旋转的问题,我们可以先简化为一个点绕原点旋转的问题,这样比较方便我们的研究。之后我们可以将结论推广到一般的形式上。

令B是原点,我们先以A点向逆时针旋转为例,我们过A' 做AB的垂线,交AB于C,过C做x轴的平行线交过A' 做x轴的垂线于D。过点C做x轴的垂线交x轴于点E。

令A的坐标(x,y),A' 坐标(x1,y1),B的坐标(0,0)。我们可以轻松的获取AB的长度,而且显而易见A' B长度等于AB。假设我们已知θ角的大小那么我们可以很快求出BC和A' C的长度。BC=A' B x cosθ,A' C=A' B x sinθ。

因为∠A' CB和∠DCE为直角(显然的结论),则∠A' CD +∠DCB =∠ECD +∠DCB=90度。

则∠A' CD=∠ECD,∠A' DC=∠CEB=90度,因此可以推断⊿CA' D ∽⊿CBE。由此可以退出的结论有:

BC/BE=A' C/A' D和BC/CE=A' C/CD

当然了DC和A' D都是未知量,需要我们求解,但是我们却可以通过求出C点坐标和E点坐标间接获得A' C和CD的长度。我们应该利用相似的知识求解C点坐标。

C点横坐标等于:((|AB| x cosθ) / |AB|) * x = x*cosθ

C点纵坐标等于:((|AB| x cosθ) / |AB|) * y = y*cosθ

则CE和BE的的长度都可以确定。

我们可以通过相⊿CA' D ∽⊿CBE得出:

AD =  x * sinθ         DC = y * sinθ

那么接下来很容易就可以得出:

x1 =  x*cosθ- y * sinθ     y1 = y*cosθ + x * sinθ

则A' 的坐标为(x*cosθ- y * sinθ, y*cosθ + x * sinθ)

我们可以这样认为:对于任意点A(x,y),A非原点,绕原点旋转θ角后点的坐标为:(x*cosθ- y * sinθ, y*cosθ + x * sinθ)
接下来我们对这个结论进行一下简单的推广,对于任意两个不同的点A和B(对于求点绕另一个点旋转后的坐标时,A B重合显然没有太大意义),求A点绕B点旋转θ角度后的坐标,我们都可以将B点看做原点,对A和B进行平移变换,计算出的点坐标后,在其横纵坐标上分别加上原B点的横纵坐标,这个坐标就是A' 的坐标。

推广结论:对于任意两个不同点A和B,A绕B旋转θ角度后的坐标为:

(Δx*cosθ- Δy * sinθ+ xB, Δy*cosθ + Δx * sinθ+ yB ) 

注:xB、yB为B点坐标。

结论的进一步推广:对于任意非零向量AB(零向量研究意义不大),对于点C进行旋转,我们只需求出点A和B对于点C旋转一定角度的坐标即可求出旋转后的向量A' B' ,因为向量旋转后仍然是一条有向线段。同理,对于任意二维平面上的多边形旋转也是如此。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main()
{
   double pi=3.14159265358;
	int n;
	cin>>n;
	while(n--)
    {
    	double x1,y1,x2,y2;
   	    cin>>x1>>y1>>x2>>y2;
   	    double temp=(double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
   	    double L=sqrt(temp);
   	    double ans=atan2((y2-y1),(x2-x1))+pi/3;
   	    cout<<"("<<fixed<<setprecision(2)<<cos(ans)*L+x1<<","<<fixed<<setprecision(2)<<sin(ans)*L+y1<<")"<<endl;
    }
	return 0;
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值