为什么 g2d.rotate 到 90 度不完全是 90 度?爪哇
您好,我正在尝试创建一个圆形文本。我设法通过循环每个旋转的字符来做到这一点。但我还是不明白。我不明白这些角度。有人可以给我一个好的解释吗?就像下面的代码一样,为什么 a 不完全是 90 度?但在 100 到 120 之间?
Graphics2D g2d = (Graphics2D)g;
AffineTransform xform1, cxform;
xform1 = AffineTransform.getTranslateInstance(200,200);
g2d.setTransform(xform1);
g2d.drawLine(0, -20, 0, 20);
g2d.drawLine(-20, 0, 20, 0);
xform1.rotate(Math.toDegrees(90));
g2d.setTransform(xform1);
g2d.drawString("a", 0, 20);
我的第一篇文章。希望我没有犯任何错误。 谢谢
Hi I am trying to create a circular text. I managed to do it somehow by for-looping each rotated character. But I still don't get it. I don't understand the angles. Could someone please give me a good explanation? Like in the following code why is a not exactly 90 degrees? But somewhere between 100 and 120?
Graphics2D g2d = (Graphics2D)g;
AffineTransform xform1, cxform;
xform1 = AffineTransform.getTranslateInstance(200,200);
g2d.setTransform(xform1);
g2d.drawLine(0, -20, 0, 20);
g2d.drawLine(-20, 0, 20, 0);
xform1.rotate(Math.toDegrees(90));
g2d.setTransform(xform1);
g2d.drawString("a", 0, 20);
My first post. Hope I have not made any mistakes.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要旋转 90 度,但是
rotate
采用弧度 - 因此您的转换方式是错误的。您将 90 弧度转换为度数,然后将其传递给需要弧度的值:) 试试这个:You want to rotate by 90 degrees, but
rotate
takes radians - so your conversion is the wrong way round. You're converting 90 radians to degrees, and then passing that to something which expects radians :) Try this: