开发者

Why is g2d.rotate to 90 degrees not exactly 90 degrees? JAVA

开发者 https://www.devze.com 2023-03-07 19:34 出处:网络
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 go

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


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:

xform1.rotate(Math.toRadians(90));
0

精彩评论

暂无评论...
验证码 换一张
取 消