gpt4 book ai didi

c - C中的旋转程序

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:41 24 4
gpt4 key购买 nike

我主要是想用 C 编写一个数学轮换程序。但输出总是错误的。 P(x,y) 围绕 Q(r,s) 旋转;顺时针(方向=1)或逆时针(方向=0)。 a、b、c 是三倍角,我想问题的意思是 c 以百为单位,然后 b 以十为单位,a 以单位为单位。

输入:

   0
7 3
0 1 1
0 0

输出:-3 7

而我得到的是 -5 5

感谢您抽出时间来帮助我。

原题链接:https://www.codechef.com/problems/DSPC305

我发现同一个上传者提出的另一个问题也使用了 TRIPLE。他进一步添加了一个注释:Triple 由 a,b,c 定义,其中 a 是底边,b 是高度,c 是三角形的斜边。每个三元组对应一个由 cosA= a/c 给出的角度

    #include<stdio.h>
#include<math.h>

int main() {
int x,y,a,b,direction,c,r,s,xnew,ynew;

scanf("%i", &direction);
scanf("%i %i", &x, &y);
scanf("%i %i %i" , &a, &b, &c);
scanf("%i %i", &r, &s);

float PI = 3.1415926535897932384626;
float theta = ((c*100+b*10+a)*PI)/180;

if (direction==1)
{
xnew= (x-r) * cos(theta) + (y-s) * sin(theta);
ynew= -(x-r) * sin(theta) + (y-s) * cos(theta);
printf("%i %i", xnew+r, ynew+s);
}

if (direction==0)
{
xnew =( (x-r) * ((cos(theta))) - (y-s) * sin(theta));
ynew =( (x-r) * ((sin(theta))) + (y-s) * cos(theta));
printf("%i %i", (xnew+r), (ynew+s));
}
return 0;
}

最佳答案

这个

float theta = ((c*100+b*10+a)*PI)/180;

与三元组的定义无关。

关于c - C中的旋转程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50084195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com