组合旋转和平移 - Java 2D

发布于 2024-10-27 06:26:44 字数 415 浏览 12 评论 0原文

public void drawEarth(Graphics2D g2){
    theta -=0.1;

    g2.rotate(theta);
    g2.translate(50, 50);

    g2.setPaint(Color.blue);
    g2.fill(shape);
}

public void rotate(Graphics2D g2)
{
    theta -=0.1;

    g2.translate(50, 50);
    g2.rotate(theta);
}

我已经写了这两个方法。第一个导致形状围绕一个点旋转,我现在尝试使形状绕其轴旋转。有人告诉我,在旋转之前进行平移将允许形状绕其轴旋转(如第二种方法所示),但我不确定如何将这两种平移结合起来,以便它旋转和旋转?

非常感谢任何帮助。

public void drawEarth(Graphics2D g2){
    theta -=0.1;

    g2.rotate(theta);
    g2.translate(50, 50);

    g2.setPaint(Color.blue);
    g2.fill(shape);
}

public void rotate(Graphics2D g2)
{
    theta -=0.1;

    g2.translate(50, 50);
    g2.rotate(theta);
}

I've written these two methods. The first one causes the shape to revolve around a point, and I'm now trying to make the shape spin about its axis. I've been told that doing translation before rotation would allow the shape to spin about it's axis (as shown in the second method), but I'm not sure how to combine these two translations so that it revolves and rotates?

Any help is much appreciated.

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

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

发布评论

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

评论(2

想挽留 2024-11-03 06:26:44

对我来说有太多聪明的话,但也许你想这样做:

g2.rotate(double theta, double x, double y)

在文档中旋转:

连接当前的 Graphics2D
通过平移旋转进行变换
变换。

There is too many smart words to me but maybe you want do this:

g2.rotate(double theta, double x, double y)

rotate in documentation:

Concatenates the current Graphics2D
Transform with a translated rotation
transform.

感情洁癖 2024-11-03 06:26:44

对于对象,它的工作原理如下:对象始终围绕原点旋转
它的工作原理也是这样的 Scale -->旋转-->翻译

如果你想围绕它自己的轴旋转一个对象,它必须位于原点(当你不平移时)。只需先调用旋转,然后将其翻译到世界中即可。完成此操作后,您必须使其绕地球旋转。所以再次调用旋转。

所以你得到这个: (Scale) -->绕自己的轴旋转 -->根据自己的偏移量进行翻译 -->翻译到地球-->绕地球旋转

我希望这会有所帮助。我不知道这方面的java API,只知道一般的查看管道。

For an object it works like this: An object always rotates around the Origin.
And it also works like this Scale --> Rotate --> Translate.

If you want to rotate an object around its own axis, it has to be on the origin (which it is when you don't translate). Just call a rotate first and then translate it into the world. Once you have done that, you have to rotate it around your earth. So call a rotate again.

So you get this: (Scale) --> Rotate on own axis --> Translate on own offset --> Translate to the earth --> Rotate around the earth

I hope this helps. I don't know about the java API for this, but only about the general viewing pipeline.

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