Chapter 12 : Mathematics

The API provides a couple of math objects.


Coord3d uses floats and allows performing these operations:

  • add(Coord3d), sub(Coord3d), mul(Coord3d), div(Coord3d) returning a new instance
  • add(float value), sub(float value), mul(float value), div(float value) addSelf(Coord3d), subSelf(Coord3d), mulSelf(Coord3d), divSelf(Coord3d)
  • distance(Coord3d) compute the distance.
  • dot(Coord3d) compute the dot product.
  • normalizeTo(Coord3d) and getNormalizedTo(Coord3d) which return a new instance.
  • interpolateTo(Coord3d, float ratio), performs a linear interpolation between current and given point.
  • negative() returns the negative coordinate.
  • polar() converts the current cartesian coordinate into a polar coordinate.
  • cartesian() converts the current polar coordinate into a cartesian coordinate.

The Coord2d object provides a subset of these 3d operations and is mainly here as a utility.

Bounding boxes

BoundingBox3d lets you append a list of coordinates (or also other bounding boxes) to get an overall bound. The object indeed holds values xmin, xmax, ymin, ymax, zmin, zmax that are updated over time.

Once created, a bounding box is in an invalid state until one adds a first coordinate or bound. Appart from providing final X, Y and Z min/max values and range, BoundingBox3d provides useful methods:

  • valid() returns true if the bounding box has been given at least one point or box to bound.
  • margin(float value) returns a new bounding box with an added margin on each side (x min, x max, etc)
  • selfMargin(float value) performs the same on the current bounding box.
  • scale(Coord3d) returns a new bounding box with each value multiplied by the given value.
  • shift(Coord3d) returns a new bounding box with each value incremented by the given value.
  • intersect(BoundingBox3d) returns true if both bounding boxes intersect.
  • contains(BoundingBox3d) returns true if this bounding box embed (or is equal to) the given box. getRadius() returns the half diagonal of the box.
  • getCenter() returns the coordinates of the center of the box.
  • getVertices() returns the corners of this bounding box has a List

The BoundingBox2d object provides a subset of these 3d operations and is mainly here as a utility.


  • append(int[], int)
  • atLeastOneNonNaN(double[])
  • clone(double[])
  • clone(double[], int)
  • clone(float[])
  • clone(float[], int)
  • clone(int[])
  • clone(int[], int)
  • countNaNs(double[])
  • filterNaNs(double[])
  • find(double[], double)
  • find(int[], int)
  • flatten(double[][])
  • flatten(double[][], boolean)
  • flatten(float[][])
  • flatten(float[][], boolean)
  • merge(double[], double[])
  • print(char[])
  • print(Coord3d[])
  • print(double[])
  • print(double[][])
  • print(float[])
  • print(float[][])
  • print(int[])
  • print(int[][])
  • sortAscending(Date[])
  • sortAscending(double[])
  • sortAscending(float[])
  • sortAscending(int[])
  • sortDescending(Date[])
  • sortDescending(double[])
  • sortDescending(float[])
  • sortDescending(int[])
  • toColumnMatrix(double[])
  • toColumnMatrix(float[])
  • toColumnMatrixAsDouble(float[])


  • mad(double[])
  • max(double[])
  • max(float[])
  • max(float[][])
  • max(int[][])
  • maxId(int[])
  • mean(double[])
  • mean(float[])
  • median(double[], boolean)
  • min(double[])
  • min(float[])
  • min(float[][])
  • min(int[][])
  • minId(double[])
  • minId(float[])
  • minId(int[])
  • quantile(double[], double[]) quantile(double[], double[], boolean)
  • std(double[])
  • variance(double[])


  • abs(double[])
  • blanks(int)
  • dat2num(Date)
  • dat2str(Date)
  • dat2str(Date, max(Date[])
  • min(Date[])
  • num2dat(long)
  • num2str(char)
  • num2str(char)
  • num2str(double)
  • num2str(double, int)
  • sum(double[])
  • sum(int[])
  • vector(double, double)
  • vector(double, double, int)
  • vector(int, int) vector(int, int, int)