Search code examples
javacomputational-geometrycoordinate-systems

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?


Solution

  • 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);
        }
    }