Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200200 points
In an xyxyxy-coordinate plane whose xxx-axis is oriented to the right and whose yyy-axis is oriented upwards, rotate a point (a,b)(a, b)(a,b) around the origin ddd degrees counterclockwise and find the new coordinates of the point.
Input is given from Standard Input in the following format:
aaa bbb ddd
Let the new coordinates of the point be (a′,b′)(a', b')(a′,b′). Print a′a'a′ and b′b'b′ in this order, with a space in between.
Your output will be considered correct when, for each value printed, the absolute or relative error from the answer is at most 10−610^{-6}10−6.
2 2 180
-2 -2
When (2,2)(2, 2)(2,2) is rotated around the origin 180180180 degrees counterclockwise, it becomes the symmetric point of (2,2)(2, 2)(2,2) with respect to the origin, which is (−2,−2)(-2, -2)(−2,−2).
5 0 120
-2.49999999999999911182 4.33012701892219364908
When (5,0)(5, 0)(5,0) is rotated around the origin 120120120 degrees counterclockwise, it becomes (−52,532)(-\frac {5}{2} , \frac {5\sqrt{3}}{2})(−25,253).
This sample output does not precisely match these values, but the errors are small enough to be considered correct.
0 0 11
0.00000000000000000000 0.00000000000000000000
Since (a,b)(a, b)(a,b) is the origin (the center of rotation), a rotation does not change its coordinates.
15 5 360
15.00000000000000177636 4.99999999999999555911
A 360360360-degree rotation does not change the coordinates of a point.
-505 191 278
118.85878514480690171240 526.66743699786547949770
x x x轴正向朝右, y y y轴正向朝上的二维坐标平面上有一点的坐标为 ( a , b ) (a, b) (a,b)
求 将这个点绕坐标原点逆时针旋转 d d d°后 的坐标
C++内置了 sin 、 cos 、 arctan \sin、\cos、\arctan sin、cos、arctan等函数,但这些函数都是以弧度制为基础的。
先计将直角坐标转换为极坐标,然后把角度加上 d d d,再转换为直角坐标即可。
后面会有简化及技巧
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
const double PI = acos(-1);
int main() {
double a, b;
cin >> a >> b;
double l = sqrt(a * a + b * b);
if (l < 1e-8) {
puts("0 0");
return 0;
}
double alpha;
if (a == 0) {
if (b > 0)
alpha = PI / 2;
else
alpha = PI / 2 * 3;
}
alpha = atan(b / a);
if (a < 0)
alpha += PI;
double d;
cin >> d;
double belta = alpha + d / 180 * PI;
belta += 4 * PI;
while (belta > 2 * PI)
belta -= 2 * PI;
double x = l * cos(belta);
double y = l * sin(belta);
printf("%.9lf %.9lf\n", x, y);
return 0;
}
double l = sqrt(a * a + b * b);
double l = hypot(a, b);
double alpha;
if (a == 0) {
if (b > 0)
alpha = PI / 2;
else
alpha = PI / 2 * 3;
}
alpha = atan(b / a);
if (a < 0)
alpha += PI;
double alpha = atan2(b, a);
belta += 4 * PI;
while (belta > 2 * PI)
belta -= 2 * PI;
#include <bits/stdc++.h>
using namespace std;
#define mem(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << #x << " = " << x << endl
#define fi(i, l, r) for (int i = l; i < r; i++)
#define cd(a) scanf("%d", &a)
typedef long long ll;
const double PI = acos(-1);
int main() {
double a, b;
cin >> a >> b;
double l = hypot(a, b); // 代替sqrt(a * a + b * b);
double alpha = atan2(b, a); // 非常方便地求角
double d;
cin >> d;
double belta = alpha + d / 180 * PI;
double x = l * cos(belta);
double y = l * sin(belta);
printf("%.9lf %.9lf\n", x, y); // 也可以:cout<<fixed<<setprecision(9)<<x<<' '<<y<<endl;
return 0;
}
同步发文于CSDN,原创不易,转载请附上原文链接哦~
Tisfy:https://letmefly.blog.csdn.net/article/details/125699603