用户登录
用户注册

分享至

如何围绕另一个点旋转一个点

  • 作者: 夏亚-雷鸣
  • 来源: 51数据库
  • 2022-10-20

问题描述

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

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;

这种方法使用旋转矩阵.point"是你的a点,center"是你的b点.

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

软件
前端设计
程序设计
Java相关