rotate() - a Bug?

J

Jenny

Hi,

The java doc says rotate() will be rotating with a positive angle
theta rotates points on the positive x axis toward the positive y
axis. It seems the positive angle theta does the opposite.

Here is the code with a positive angle theta for you to see.

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class TryFont extends JFrame {
public TryFont() {
super("Rectangles");
setSize(410, 430);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RectPanel r = new RectPanel();
Container content = getContentPane();
content.add(r);
setContentPane(content);
setVisible(true);
}
public static void main(String[] arguments) {
TryFont rect = new TryFont();
}
}
class RectPanel extends JPanel {
public void paintComponent(Graphics comp) {
super.paintComponent(comp);
Graphics2D comp2D = (Graphics2D) comp;
setBackground(Color.white);
comp2D.rotate(-.4,200,200);
Font f = new Font("Garbage",Font.BOLD,40);
Font f1 = new Font("Times New Roman",Font.BOLD,40);
comp2D.setColor(Color.green);
comp2D.setFont(f);
comp2D.drawString("Happy", 50,150);
comp2D.setColor(Color.red);
comp2D.setFont(f1);
comp2D.drawString("Birthday!", 50,200);
}}
 
P

Paul Lutus

Jenny said:
Hi,

The java doc says rotate() will be rotating with a positive angle
theta rotates points on the positive x axis toward the positive y
axis. It seems the positive angle theta does the opposite.

Here is the code with a positive angle theta for you to see.

So -.4 is a positive theta angle, as in your posted code? If positive Y is
downward, as is so often the case in typical coordinate systems (makes me
crazy), the doecumentation is correct. You just have to actually use a
positive rotation value.
 
P

Paul Lutus

Jenny said:
Thanks. Java is not math.

Meaning, I presume, that rightfully, +x = right and +y = up. I agree. All my
graphic programs use this convention, but those that are closer to text
display, as your example is, adhere to the +y = down convention. This
Graphics2D class appears to have one foot in each world, making it a
strange duck if there ever was one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top