【问题标题】:how to rotate a point around another point如何围绕另一个点旋转一个点
【发布时间】:2015-11-18 08:51:52
【问题描述】:

我正在写一个游戏。我需要知道如何将点 a 围绕点 b 旋转给定的度数。我正在用 java 写这个,它将成为我的课程的一部分,Point。

【问题讨论】:

标签: java algorithm rotation


【解决方案1】:
double x1 = point.x - center.x;
double y1 = point.y - center.y;

double x2 = x1 * Math.cos(angle) - y1 * Math.sin(angle));
double y2 = x1 * Math.sin(angle) + y1 * Math.cos(angle));

point.x = x2 + center.x;
point.y = y2 + center.y;

这种方法使用旋转矩阵。 “point”是你的a点,“center”是你的b点。

【讨论】:

  • 可变角度应该是弧度还是度数?
  • @user2277362 为什么不look it up
  • Math.sin 和其他三角函数使用弧度。 Math 类也有 toDegrees() 和 toRadians() 函数。
猜你喜欢
  • 2012-11-21
  • 1970-01-01
  • 2014-12-26
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 2018-02-27
  • 1970-01-01
相关资源
最近更新 更多