From: Eustace on
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?

Thanks,

emf

--
It ain't THAT, babe! - A radical reinterpretation
https://files.nyu.edu/emf202/public/bd/itaintmebabe.html
From: Lew on
On 06/16/2010 04:08 AM, 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.

Take the world for what it is and don't fight to jam it into your preconceptions.

--
Lew
From: Lew on
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
From: Patricia Shanahan on
Eustace wrote:
....
> 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?
....

It is generally a *very* bad idea to try to change the established
conventions, even if you don't like them.

The least readable piece of C code I have ever seen was written by some
programmers who preferred Pascal, and used #define to make their C code
look a bit Pascal-ish. Even for someone fluent in both C and Pascal, it
was very confusing.

If you do something to change the screen coordinate convention, anyone
else working on one of your programs is going to get into all sorts of
trouble dealing with the dissonance between their expectations and your
conventions.

Patricia
From: Rene' Descartes on
On Wed, 16 Jun 2010, Lew wrote:

> From time immemorial screen coordinates have been expressed from the
> top-left corner. You will go through a lot of useless effort
> resisting this.

But even before such immemorial times, physicists and mathematicians are
used to coordinates starting in the bottom left corner.

> Take the world for what it is and don't fight to jam it into your
> preconceptions.

And Y-flipping is something standard in every sensible graphics package.
Usually one has some world coordinates, some "normalized device
coordinates" (NDC) and the raw device coordinates. Y-flipping is taken
care when passing from NDC to raw.

--
----------------------------------------------------------------------
nospam(a)mi.iasf.cnr.it is a newsreading account used by more persons to
avoid unwanted spam. Any mail returning to this address will be rejected.
Users can disclose their e-mail address in the article if they wish so.