如何旋转坐标系?

发布于 2025-01-04 06:26:47 字数 155 浏览 4 评论 0原文

如果我绕原点旋转,我试图找到坐标的新值。

例如,假设我有点 (1,1)。 如果我绕原点旋转坐标轴 45 度,变换后的坐标将为 (0,1.414)

有没有办法在 cocos2d 或 Objective-c 中有效地做到这一点? 即使是解释数学原理的答案也会有所帮助。

I am trying to find the new value of a coordinate if I rotate around the origin.

For example, say I have the point (1,1).
If I rotate the coordinate axis 45 degrees around the origin, the transformed coordinate would be (0,1.414)

Is there a way to do this efficiently in cocos2d, or in objective-c ?
Even answers explaining the math to do this would be helpful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2025-01-11 06:26:47

请参阅此页面:
http://www.siggraph.org/education/materials/HyperGraph /modeling/mod_tran/2drota.htm

这是公式:

x' = x cos f - y sin f

y' = y cos f + x sin f

请记住,sin 和 cos 需要弧度,所以你必须这样做:

double x,y;
double newX,newY;
double angle;

//Test values:
x=1;
y=1;
angle = 45;

double rad = angle*M_PI/180;

newX = x * cos(rad) - y * sin(rad);
newY = y * cos(rad) + x * sin(rad);

我没有测试这个,所以可能会有拼写错误...;)

See this page:
http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/2drota.htm

This is the formula:

x' = x cos f - y sin f

y' = y cos f + x sin f

Remember that sin and cos takes radians, so you have to do like this:

double x,y;
double newX,newY;
double angle;

//Test values:
x=1;
y=1;
angle = 45;

double rad = angle*M_PI/180;

newX = x * cos(rad) - y * sin(rad);
newY = y * cos(rad) + x * sin(rad);

I didn't test this, so there might be typos... ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文