To handle Curve plotting, two classes were developed :
  •, handling the core curve functionnalities and the display (it is a subclass of JPanel).
  • jephem.gui.CurveViewer, which handles the commands
  • Curve data

    Curve API provides 2D representation. So it has an X axis and an Y axis.
    To display a curve, client classes send double arrays. The display is done from discrete values. Typically, 100 values are enough to get a continuous impression on the screen.
  • One array is needed to represent X values.
  • As Curve API can display several curves on the same drawing, it needs one double array per represented curve.

  • X and Y values are stored in a double[][], accessible via getData().
    This data are given to Curve via the constructor (see Curve javadoc).

  • public int getNbX() permits to retrieve the number of values used to represent each curve.
  • public int getNbY() permits to retrieve the number of represented curves.
  • getXMin(), getXMax(), getYMin(), getYMax() are also available.

  • Other way to access the data :
  • public double[] getX(), to get the X values.
  • public double[] getY(int whichY), to get the values of the whichYth curve.
  • public double[][] getAllY(int whichY), to get the values of all the curves.

  • getY(int whichY, double x) permits to retrieve the ordinate corresponding to x for th whichYth curve. An interpolation is done if x does not correspond to one of the pre-calculated values (see interpolation).
  • Organizing the display area

    Here, we only consider the area handled by Curve. It is organized like this :

    The gaps are used to put legends. There are top, left, bottom, right gaps, called tg, lg, bg, rg.
    Other useful quantities are h and w, the height and width of the area handled by Curve.

    Pixel and data coordinates

    Here, it is useful to consider two types of coordinates :
  • Data coordinates, noted (xD, yD), expressed in the data scale.
    We have : XXXXX
  • Pixel coordinates, noted (xP, yP), expressed in the usual computer screen coordinates (origin at top - left);
    We have : XXXXXX

  • We also note : Dx = xMax - xMin and Dy = yMax - yMin

    Data to pixel

    Data and pixel coordinates are linked by a linear relation.
  • For x, we have : xP = a1xD + b1 ( relation 1).

  • To find a1 and b1, we need to see the values for two different points :
    xD xP
    xMin lg
    xMax w - rg

    This leads to a system of two equations with two unknown ; the solutions are :

  • For y, we have : yP = a2yD + b2 (relation 2).

  • The same method is applied ; we have :
    yD yP
    yMin h - bg
    yMax ug

    The solutions are :

    Pixel to data

    If we pose : xD = a'1xP + b'1, from relation 1 we deduce :
    a'1 = 1 / a1 and b'1 = - b1/a1

    For y, we pose : yD = a'2yP + b'2 ; the same method leads to

    This is implemented in private methods pixelToData() and dataToPixel().