如何绕另一点一个点

由网友(涼城″浅离)分享简介:我在写一个游戏。我需要知道如何度给定要旋转一个点周围的B点。我写这在Java中,这将是我的课,点的一部分。解决方案 双X1 = point.x - center.x;双Y1 = point.y - center.y;双X2 = X1 * Math.cos(角度) - Y1 * Math.sin(角度))...

我在写一个游戏。我需要知道如何度给定要旋转一个点周围的B点。我写这在Java中,这将是我的课,点的一部分。

解决方案

 双X1 = point.x  -  center.x;
双Y1 = point.y  -  center.y;

双X2 = X1 * Math.cos(角度) -  Y1 * Math.sin(角度));
双Y2 = X1 * Math.sin(角)+ Y1 * Math.cos(角));

point.x = X2 + center.x;
point.y = Y2 + center.y;
 

此方法使用了旋转矩阵。 点是你的点,中心是你的b点。

I am writing a game. I need to know how to rotate point a around point b by a given number of degrees. I am writing this in java and it is going to be part of my class, Point.

解决方案 直线绕其中一个起点旋转指定角度后,计算另一个点的坐标

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;

This approach uses rotation matrices. "point" is your point a, "center" is your point b.

阅读全文

相关推荐

最新文章