gpt4 book ai didi

Java - 在 Graphics2D 中获取新的旋转点

转载 作者:行者123 更新时间:2023-11-30 10:30:34 26 4
gpt4 key购买 nike

我需要获取新的旋转点才能知道物体的真实位置和尺寸,例如:

Example 01 .

我的应用程序的上下文是渲染 2D 图形,其主要内容如下:

    protected void paintComponent(Graphics g) {
...

g2d.rotate(Test.angle * Math.PI / 180, Test.hero, Test.heroY);
g2d.drawImage(Main.hero, Test.hero - 15, Test.heroY - 15, this);
...

图像绘制正确,但我无法获取新点。

最佳答案

double angle = ang * Math.PI / 180;
double sin = Math.sin(angle);
double cos = Math.cos(angle);

double a = (centerX + ray) - x0;
double b = centerY - y0;
int xx = (int) (a * cos - b * -sin + x0);
int yy = (int) (a * -sin + b * cos + y0);

ang++;

它将围绕 centerX 和 centerY 在这些原点的 +ray 中旋转一个点,代码已经过测试并且可以从所有角度工作。

关于Java - 在 Graphics2D 中获取新的旋转点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43659968/

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