Class TacticalGraphicUtil


  • public class TacticalGraphicUtil
    extends java.lang.Object
    Utility methods for working with tactical graphics.
    • Constructor Detail

      • TacticalGraphicUtil

        public TacticalGraphicUtil()
    • Method Detail

      • asPositionList

        public static java.util.List<Position> asPositionList​(Globe globe,
                                                              Vec4... points)
        Convert a list of cartesian points to Positions.
        Parameters:
        globe - Globe used to convert points to positions.
        points - Points to convert.
        Returns:
        List of positions computed from cartesian points.
      • getDateRange

        public static java.lang.Object[] getDateRange​(TacticalGraphic graphic)
        Get the date range from a graphic's modifiers. This method looks at the value of the AVKey.DATE_TIME modifier, and returns the results as a two element array. If the value of the modifier is an Iterable, then this method returns the first two values of the iteration. If the value of the modifier is a single object, this method returns an array containing that object and null.
        Parameters:
        graphic - Graphic from which to retrieve dates.
        Returns:
        A two element array containing the altitude modifiers. One or both elements may be null.
      • getAltitudeRange

        public static java.lang.Object[] getAltitudeRange​(TacticalGraphic graphic)
        Get the altitude range from the graphic's modifiers. This method looks at the value of the AVKey.ALTITUDE modifier, and returns the results as a two element array. If the value of the modifier is an Iterable, then this method returns the first two values of the iteration. If the value of the modifier is a single object, this method returns an array containing that object and null.
        Parameters:
        graphic - Graphic from which to retrieve dates.
        Returns:
        A two element array containing the altitude modifiers. One or both elements may be null.
      • placeLabelsOnPath

        public static void placeLabelsOnPath​(DrawContext dc,
                                             java.lang.Iterable<? extends Position> positions,
                                             TacticalGraphicLabel label1,
                                             TacticalGraphicLabel label2,
                                             double distance)
        Position one or two labels some distance along the path. Top and bottom labels are often positioned above and below the same point, so this method supports positioning a pair of labels at the same point. The label offsets determine how the labels draw in relation to the line.
        Parameters:
        dc - Current draw context.
        positions - Positions that describe the path.
        label1 - First label to position.
        label2 - Second label to position. (May be null.)
        distance - Distance along the path at which to position the labels.
      • bezierCurve

        public static Vec4 bezierCurve​(Vec4[] controlPoints,
                                       double t,
                                       int[] coefficients)
        Compute a point along a Bezier curve defined by a list of control points. The first and last points should mark the start and end of the curve.

        This function implements the Bezier curve equation from "Mathematics for 3D Game Programming and Computer Graphics, Second Edition" by Eric Lengyel (equation 15.16, pg. 458).

        A typical usage looks like this:

         
         Vec4[] controlPoints = ... // Determine control points appropriate for your curve
        
         List<Position> curvePositions = new ArrayList<Position>();
         int[] coefficients = new int[controlPoints.length];
        
         int intervals = 32;
         double delta = 1.0 / intervals;
         for (int i = 0; i < intervals; i++)
         {
             double t = i * delta;
             Vec4 pt = TacticalGraphicUtil.bezierCurve(controlPoints, t, coefficients);
             Position pos = globe.computePositionFromPoint(p);
             curvePositions.add(pos);
         }
         
         
        Parameters:
        controlPoints - Control points for the curve.
        t - Interpolation parameter in the range [0..1].
        coefficients - Array to store binomial coefficients between invocations of this function. On the first invocation, pass an int[] with length equal to the controlPoints array. bezierCurve will populate the array on the first invocation, and reuse the computed values on subsequent invocations.
        Returns:
        A point along the curve.
      • binomial

        protected static void binomial​(int n,
                                       int[] coefficients)
        Compute binomial coefficients for a polynomial of order n. Stated another way, computes the nth row of Pascal's triangle.
        Parameters:
        n - Order of polynomial for which to calculate coefficients.
        coefficients - Array to receive coefficients. The length of this array must be n + 1.