组合旋转和平移 - Java 2D
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对我来说有太多聪明的话,但也许你想这样做:
在文档中旋转:
There is too many smart words to me but maybe you want do this:
rotate in documentation:
对于对象,它的工作原理如下:对象始终围绕原点旋转。
它的工作原理也是这样的
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.