zephos2014
zephos2014

Reputation: 331

Graphics2D rotate methods. What's the difference?

The Java API doesn't really explain this very well and I'm still unsure.

What is the difference between these two Graphics2d overloaded method calls?

public abstract void rotate(double theta)

and

public abstract void rotate(double theta,
      double x,
      double y)

The Java Doc is here:

http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html#translate%28int,%20int%29

What I got from the documentation, was that the second rotate method translates the graphics object, rotates it, and translates it back. My confusion is about where drawing graphics fits in if it is already translated back to the previous origin.

If the graphics is rotated, can I go off the previous coordinate system (with the origin at (0,0)) and have everything end up where I'd expect?

My goal is to rotate the graphics around the center of a image (thus the translation), and then rotate and redraw the image. After that, I'd like to reset the graphics back to normal (or simply discard that version of graphics?).

Thanks in advance for any help.

Upvotes: 0

Views: 236

Answers (1)

MadProgrammer
MadProgrammer

Reputation: 347314

If I remember right, Graphics2D#rotate(double) rotates around the top/left corner of the Graphics context (based on it's current transformation), where as Graphics2D#rotate(double, double, double) allows you to define the anchor point around which the Graphics context will be rotated. Sometimes, you just have to give it a try

Upvotes: 1

Related Questions