Re: Changing coordinates
Eustace wrote:
Instead of having the x and y coordinates start at the top right corner,
I prefer them to start either at the center of the window. This I can do
with:
...
class CustomPanel extends JPanel {
public void paintComponent(Graphics painter) {
painter2D = (Graphics2D)painter;
painter2D.translate(width/2, height/2);
...
But I would also prefer the positive values across the y axis to be
positive above the base line and negative below.
I could use
painter2D.rotate(-Math.PI/2);
but then of course the x axis and the y axis replace each other, so then
I have to use, for example,
Rectangle 2D frame = new Rectangle2D.Double(y, x, h, w);
instead of
Rectangle 2D frame = new Rectangle2D.Double(x, y, w, h);
As I see it my choices are:
(a) Get used to the y axis moving downwards.
(b) Use rotation and learn to remember that y replaces x etc.
(c) Use (b) and overwrite the constructors that use x, y, w, h.
I would like to hear what the solution of experienced programmers is. I
tend to accept (a), hoping that after some time it will seem natural.
But is there a (d) option of reversing the direction of the y axis?
From time immemorial screen coordinates have been expressed from the
top-left corner. You will go through a lot of useless effort resisting
this.
Lew wrote:
Take the world for what it is and don't fight to jam it into your
preconceptions.
I missed a few points.
What the heck do you mean by "overwrite the constructors"?
Where did you get the idea that screen coordinates start at the top right?
They don't.
Your line 'Rectangle 2D frame = ...' will not compile.
--
Lew