题目传送门
/*
已知一向量为(x , y) 则将它旋转θ后的坐标为(x*cosθ- y * sinθ , y*cosθ + x * sinθ)
应用到本题,x变为(xb - xa), y变为(yb - ya)相对A点的位置,即B绕着A点旋转60度至C点
注意:计算后加回A点的坐标才是相对于原点的坐标
详细解释:http://www.tuicool.com/articles/FnEZJb
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
const double PI = acos (-1.0);
int main(void) //A Rescue The Princess
{
//freopen ("A.txt", "r", stdin);
int t;
while (scanf ("%d", &t) == )
{
while (t--)
{
double xa, ya, xb, yb, xd, yd;
scanf ("%lf%lf%lf%lf", &xa, &ya, &xb, &yb);
double xc = (xb - xa) * cos (PI/3.0) - (yb - ya) * sin (PI/3.0) + xa;
double yc = (yb - ya) * cos (PI/3.0) + (xb - xa) * sin (PI/3.0) + ya;
printf ("(%.2f,%.2f)\n", xc, yc);
}
}
return ;
}
/*
分各种情况讨论,这是我比赛写的,最后因为没有去绝对值而WA几次,
与上面的比较来看,可见好的思维和数学素养是多么重要:)
*/
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;
int main(void) //A Rescue The Princess
{
//freopen ("A.txt", "r", stdin);
int t;
while (scanf ("%d", &t) == )
{
while (t--)
{
double xa, ya, xb, yb, xc, yc, xd, yd;
scanf ("%lf%lf%lf%lf", &xa, &ya, &xb, &yb);
double ab = sqrt ((xa-xb) * (xa-xb) + (ya-yb) * (ya-yb));
double cd = sqrt (3.0) / * ab;
xd = (xa + xb) / ; yd = (ya + yb) / ;
if (ya == yb)
{
xc = (xa + xb) / ;
if (xa < ab)
{
yc = ya + cd;
}
else
{
yc = ya - cd;
}
}
else if (xa == xb)
{
yc = (ya + yb) / ;
if (ya > yb)
{
xc = xa + cd;
}
else
{
xc = xa - cd;
}
}
else
{
double k = (ya - yb) / (xa - xb);
k = -1.0 / k;
double q = atan (k);
//printf ("%.2f %.2f %.2f %.2f %.2f %.2f\n", ab, cd, xd, yd, k, q);
if (k > )
{
if (xa < xb)
{
xc = xd + abs (cd * cos (q));
yc = yd + abs (cd * sin (q));
}
else
{
xc = xd - abs (cd * cos (q));
yc = yd - abs (cd * sin (q));
}
}
else
{
if (xa < xb)
{
xc = xd - abs (cd * cos (q));
yc = yd + abs (cd * sin (q));
}
else
{
xc = xd + abs (cd * cos (q));
yc = yd - abs (cd * sin (q));
}
}
}
printf ("(%.2f,%.2f)\n", xc, yc);
}
}
return ;
}