xtofl
xtofl

Reputation: 41509

2d coordinate system: Math vs. Screen

We're working on a library that does calculations in 2D space. However, the 'natural' interpretation of the 2D coordinate system is where increasing Y values represent points that lie higher, while the awt coordinates do the reverse. This reflects in Rectangle(10,100).maxY() returning 0, while the mathematician would expect it to return 100.

How can we properly deal with that difference? Is there another java library to do geometrical calculations?

Upvotes: 0

Views: 794

Answers (2)

lbalazscs
lbalazscs

Reputation: 17784

You should try things before asking. The following code prints 100, so there is no problem :)

import java.awt.*;

public class A {
    public static void main(String[] args) {
        double maxX = new Rectangle(10, 100).getMaxY();
        System.out.println("A::main: maxX = " + maxX);
    }
}

Upvotes: 2

xtofl
xtofl

Reputation: 41509

I turns out that maxY returns 'the biggest y-coordinate`, which is exactly the intuitive behavior. I was confused: only when actually drawing it to screen the objects have a 'top-left' and a 'bottom-right' are merely conventions when visualizing it.

Upvotes: 1

Related Questions