Class WWMath


  • public class WWMath
    extends java.lang.Object
    A collection of useful math methods, all static.
    • Constructor Summary

      Constructors 
      Constructor Description
      WWMath()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void addTriangleNormal​(int a, int b, int c, java.nio.FloatBuffer vertices, java.nio.FloatBuffer normals)
      Computes a triangle normal given the starting position of three tuples in the specified vertex buffer, and stores adds the result to three tuples in the specified normal buffer with the same positions.
      static java.util.List<java.awt.Point> bresenham​(int x0, int y0, int x1, int y1)
      Computes a line between two integer-coordinate points using Bresenham's algorithm.
      static double clamp​(double v, double min, double max)
      Clamps a value to a given range.
      static int clamp​(int v, int min, int max)
      Clamps an integer value to a given range.
      static Vec4 computeArrayNormal​(Vec4[] coords)
      Computes a unit-length normal vector for an array of coordinates.
      static Vec4 computeBufferNormal​(java.nio.FloatBuffer coords, int stride)
      Computes a unit-length normal vector for a buffer of coordinate triples.
      static boolean computeCircleThroughPoints​(Vec4 p0, Vec4 p1, Vec4 p2, Vec4[] centerOut, Vec4[] axisOut, double[] radiusOut)
      Computes the center, axis, and radius of the circle that circumscribes the specified points.
      static double computeDistanceFromEye​(DrawContext dc, Extent extent)
      Returns the distance in model coordinates from the View eye point to the specified Extent.
      static java.nio.IntBuffer computeIndicesForGridInterior​(int width, int height)
      Computes an index buffer in the system native byte order that tessellates the interior of a vertex grid as a triangle strip.
      static java.nio.IntBuffer computeIndicesForGridOutline​(int width, int height)
      Computes an index buffer in the system native byte order that tessellates the outline of a vertex grid as a line strip.
      static double computeInterpolationFactor​(double v, double x, double y)
      Returns the interpolation factor for v given the specified range [x, y].
      static java.nio.FloatBuffer computeNormalsForIndexedTriangleStrip​(java.nio.IntBuffer indices, java.nio.FloatBuffer vertices, java.nio.FloatBuffer normals)
      Computes per-vertex normals of an indexed triangle strip, storing the normal coordinates in the specified normal buffer.
      static double computePolygonAreaFromVertices​(java.lang.Iterable<? extends Vec4> points)
      Returns the area enclosed by the specified (x, y) points (the z and w coordinates are ignored).
      protected static int[] computePowers​(int base, int numPowers)
      Populate an array with the successive powers of a number.
      static Vec4[] computePrincipalAxes​(BufferWrapper coordinates, int stride)
      Returns an array of normalized vectors defining the three principal axes of the x-, y-, and z-coordinates from the specified buffer of points, sorted from the most prominent axis to the least prominent.
      static Vec4[] computePrincipalAxes​(java.lang.Iterable<? extends Vec4> points)
      Returns an array of normalized vectors defining the three principal axes of the x-, y-, and z-coordinates from the specified points Iterable, sorted from the most prominent axis to the least prominent.
      static double computeSizeInWindowCoordinates​(DrawContext dc, Extent extent)
      Returns the size in window coordinates of the specified Extent from the current View.
      static double computeSphereProjectedArea​(View view, Vec4 center, double radius)
      Computes the area in square pixels of a sphere after it is projected into the specified view's viewport.
      static Vec4 computeTriangleNormal​(Vec4 a, Vec4 b, Vec4 c)
      Returns the normal vector corresponding to the triangle defined by three vertices (a, b, c).
      static java.lang.String computeWindingOrderOfLocations​(java.lang.Iterable<? extends LatLon> locations)
      Returns the winding order of the polygon described by the specified locations, with respect to an axis perpendicular to the (lat, lon) coordinates, and pointing in the direction of "positive elevation".
      static java.lang.String computeWindingOrderOfVertices​(java.lang.Iterable<? extends Vec4> points)
      Returns the winding order of the 2D polygon described by the specified (x, y) points (z and w coordinates are ignored), with respect to the positive z axis.
      static double convertDaysToMillis​(double millis)
      Convert time in days to time in milliseconds.
      static double convertFeetToMeters​(double feet)
      Converts distance in feet to distance in meters.
      static double convertHoursToMillis​(double hours)
      Converts time in hours to time in milliseconds.
      static double convertMetersToFeet​(double meters)
      converts meters to feet.
      static double convertMetersToMiles​(double meters)
      converts meters to miles.
      static double convertMillisToDays​(double millis)
      Convert time in milliseconds to time in days.
      static double convertMillisToHours​(double mills)
      Converts time in milliseconds to time in hours.
      static double convertMillisToMinutes​(double millis)
      Converts time in milliseconds to time in minutes.
      static double convertMillisToSeconds​(double millis)
      Converts time in milliseconds to time in seconds.
      static double convertMinutesToMillis​(double minutes)
      Converts time in minutes to time in milliseconds.
      static double convertSecondsToMillis​(double seconds)
      Converts time in seconds to time in milliseconds.
      static Vec4[] findThreeIndependentVertices​(Vec4[] coords)
      Finds three non-colinear points in an array of points.
      static Vec4[] findThreeIndependentVertices​(java.nio.FloatBuffer coords, int stride)
      Finds three non-colinear points in a buffer.
      static void generateParallelLines​(java.util.List<Position> controlPositions, java.util.List<Position> leftPositions, java.util.List<Position> rightPositions, double distance, Globe globe)
      Create positions that describe lines parallel to a control line.
      static Vec4 generateParallelPoints​(Vec4 point, Vec4 prev, Vec4 next, java.util.List<Position> leftPositions, java.util.List<Position> rightPositions, double distance, double elevation, Globe globe, Vec4 previousOffset)
      Compute points on either side of a line segment.
      static boolean isLocationInside​(LatLon location, java.lang.Iterable<? extends LatLon> locations)
      Determines whether a LatLon location is located inside a given polygon.
      static boolean isPolygonClosed​(java.lang.Iterable<? extends LatLon> locations)
      Returns whether the geographic polygon described by the specified locations defines a closed loop.
      static boolean isPolygonClosed2​(java.lang.Iterable<? extends Vec4> points)
      Returns whether the 2D polygon described by the specified (x, y) points defines a closed loop (z and w coordinates are ignored).
      static boolean isPowerOfTwo​(int value)
      Convenience method for testing whether a value is a power of two.
      static double logBase2​(double value)
      Convenience method to compute the log base 2 of a value.
      static double mix​(double a, double x, double y)
      Returns the linear interpolation of x and y according to the function: (1 - a) * x + a * y.
      static double mixSmooth​(double a, double x, double y)
      Returns the smooth hermite interpolation of x and y according to the function: (1 - t) * x + t * y, where t = a * a * (3 - 2 * a).
      protected static void normalize3​(java.nio.FloatBuffer buffer)
      Normalizes the 3-coordinate tuple starting at the buffer's position, then advances the buffer's position to the end of the tuple.
      static Intersection[] polytopeIntersect​(Line line, Plane[] planes)
      Intersect a line with a convex polytope and return the intersection points.
      static int powerOfTwoCeiling​(int reference)
      Returns the value that is the nearest power of 2 greater than or equal to the given value.
      static int powerOfTwoFloor​(int reference)
      Returns the value that is the nearest power of 2 less than or equal to the given value.
      static double smoothStepValue​(double value, double min, double max)
      Returns a number between 0.0 and 1.0 indicating whether a specified floating point value is before, between or after the specified min and max.
      static double stepValue​(double value, double min, double max)
      Returns a number between 0.0 and 1.0 indicating whether a specified floating point value is before, between or after the specified min and max.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WWMath

        public WWMath()
    • Method Detail

      • logBase2

        public static double logBase2​(double value)
        Convenience method to compute the log base 2 of a value.
        Parameters:
        value - the value to take the log of.
        Returns:
        the log base 2 of the specified value.
      • isPowerOfTwo

        public static boolean isPowerOfTwo​(int value)
        Convenience method for testing whether a value is a power of two.
        Parameters:
        value - the value to test for power of 2
        Returns:
        true if power of 2, else false
      • powerOfTwoCeiling

        public static int powerOfTwoCeiling​(int reference)
        Returns the value that is the nearest power of 2 greater than or equal to the given value.
        Parameters:
        reference - the reference value. The power of 2 returned is greater than or equal to this value.
        Returns:
        the value that is the nearest power of 2 greater than or equal to the reference value
      • powerOfTwoFloor

        public static int powerOfTwoFloor​(int reference)
        Returns the value that is the nearest power of 2 less than or equal to the given value.
        Parameters:
        reference - the reference value. The power of 2 returned is less than or equal to this value.
        Returns:
        the value that is the nearest power of 2 less than or equal to the reference value
      • computePowers

        protected static int[] computePowers​(int base,
                                             int numPowers)
        Populate an array with the successive powers of a number.
        Parameters:
        base - the number whose powers to compute.
        numPowers - the number of powers to compute.
        Returns:
        an array containing the requested values. Each element contains the value b^i, where b is the base and i is the element number (0, 1, etc.).
      • clamp

        public static double clamp​(double v,
                                   double min,
                                   double max)
        Clamps a value to a given range.
        Parameters:
        v - the value to clamp.
        min - the floor.
        max - the ceiling
        Returns:
        the nearest value such that min <= v <= max.
      • clamp

        public static int clamp​(int v,
                                int min,
                                int max)
        Clamps an integer value to a given range.
        Parameters:
        v - the value to clamp.
        min - the floor.
        max - the ceiling
        Returns:
        the nearest value such that min <= v <= max.
      • stepValue

        public static double stepValue​(double value,
                                       double min,
                                       double max)
        Returns a number between 0.0 and 1.0 indicating whether a specified floating point value is before, between or after the specified min and max. Returns a linear interpolation of min and max when the value is between the two.

        The returned number is undefined if min > max. Otherwise, the returned number is equivalent to the following:

        • 0.0 - If value < min
        • 1.0 - If value > max
        • Linear interpolation of min and max - If min <= value <= max
        Parameters:
        value - the value to compare to the minimum and maximum.
        min - the minimum value.
        max - the maximum value.
        Returns:
        a floating point number between 0.0 and 1.0, inclusive.
      • smoothStepValue

        public static double smoothStepValue​(double value,
                                             double min,
                                             double max)
        Returns a number between 0.0 and 1.0 indicating whether a specified floating point value is before, between or after the specified min and max. Returns a smooth interpolation of min and max when the value is between the two.

        This method's smooth interpolation is similar to the interpolation performed by stepValue(double, double, double), except that the first derivative of the returned number approaches zero as the value approaches the minimum or maximum. This causes the returned number to ease-in and ease-out as the value travels between the minimum and maximum.

        The returned number is undefined if min > max. Otherwise, the returned number is equivalent to the following:

        • 0.0 - If value < min
        • 1.0 - If value > max
        • Smooth interpolation of min and max - If min <= value <= max
        Parameters:
        value - the value to compare to the minimum and maximum.
        min - the minimum value.
        max - the maximum value.
        Returns:
        a floating point number between 0.0 and 1.0, inclusive.
      • computeInterpolationFactor

        public static double computeInterpolationFactor​(double v,
                                                        double x,
                                                        double y)
        Returns the interpolation factor for v given the specified range [x, y]. The interpolation factor is a number between 0 and 1 (inclusive), representing the value's relative position between x and y. For example, 0 corresponds to x, 1 corresponds to y, and anything in between corresponds to a linear combination of x and y.
        Parameters:
        v - the value to compute the interpolation factor for.
        x - the first value.
        y - the second value.
        Returns:
        the interpolation factor for v given the specified range [x, y]
      • mix

        public static double mix​(double a,
                                 double x,
                                 double y)
        Returns the linear interpolation of x and y according to the function: (1 - a) * x + a * y. The interpolation factor a defines the weight given to each value, and is clamped to the range [0, 1]. If a is 0 or less, this returns x. If a is 1 or more, this returns y. Otherwise, this returns the linear interpolation of x and y. For example, when a is 0.5 this returns (x + y)/2.
        Parameters:
        a - the interpolation factor.
        x - the first value.
        y - the second value.
        Returns:
        the linear interpolation of x and y.
      • mixSmooth

        public static double mixSmooth​(double a,
                                       double x,
                                       double y)
        Returns the smooth hermite interpolation of x and y according to the function: (1 - t) * x + t * y, where t = a * a * (3 - 2 * a). The interpolation factor a defines the weight given to each value, and is clamped to the range [0, 1]. If a is 0 or less, this returns x. If a is 1 or more, this returns y. Otherwise, this returns the smooth hermite interpolation of x and y. Like the linear function mix(double, double, double), when a is 0.5 this returns (x + y)/2. But unlike the linear function, the hermite function's slope gradually increases when a is near 0, then gradually decreases when a is near 1. This is a useful property where a more gradual transition from x to y is desired.
        Parameters:
        a - the interpolation factor.
        x - the first value.
        y - the second value.
        Returns:
        the smooth hermite interpolation of x and y.
      • convertMetersToFeet

        public static double convertMetersToFeet​(double meters)
        converts meters to feet.
        Parameters:
        meters - the value in meters.
        Returns:
        the value converted to feet.
      • convertMetersToMiles

        public static double convertMetersToMiles​(double meters)
        converts meters to miles.
        Parameters:
        meters - the value in meters.
        Returns:
        the value converted to miles.
      • convertFeetToMeters

        public static double convertFeetToMeters​(double feet)
        Converts distance in feet to distance in meters.
        Parameters:
        feet - the distance in feet.
        Returns:
        the distance converted to meters.
      • convertSecondsToMillis

        public static double convertSecondsToMillis​(double seconds)
        Converts time in seconds to time in milliseconds.
        Parameters:
        seconds - time in seconds.
        Returns:
        time in milliseconds.
      • convertMillisToSeconds

        public static double convertMillisToSeconds​(double millis)
        Converts time in milliseconds to time in seconds.
        Parameters:
        millis - time in milliseconds.
        Returns:
        time in seconds.
      • convertMinutesToMillis

        public static double convertMinutesToMillis​(double minutes)
        Converts time in minutes to time in milliseconds.
        Parameters:
        minutes - time in minutes.
        Returns:
        time in milliseconds.
      • convertMillisToMinutes

        public static double convertMillisToMinutes​(double millis)
        Converts time in milliseconds to time in minutes.
        Parameters:
        millis - time in milliseconds.
        Returns:
        time in minutes.
      • convertHoursToMillis

        public static double convertHoursToMillis​(double hours)
        Converts time in hours to time in milliseconds.
        Parameters:
        hours - time in hours.
        Returns:
        time in milliseconds.
      • convertMillisToHours

        public static double convertMillisToHours​(double mills)
        Converts time in milliseconds to time in hours.
        Parameters:
        mills - time in milliseconds.
        Returns:
        time in hours.
      • convertDaysToMillis

        public static double convertDaysToMillis​(double millis)
        Convert time in days to time in milliseconds.
        Parameters:
        millis - time in days.
        Returns:
        time in milliseconds.
      • convertMillisToDays

        public static double convertMillisToDays​(double millis)
        Convert time in milliseconds to time in days.
        Parameters:
        millis - time in milliseconds.
        Returns:
        time in days.
      • computeDistanceFromEye

        public static double computeDistanceFromEye​(DrawContext dc,
                                                    Extent extent)
        Returns the distance in model coordinates from the View eye point to the specified Extent. If the View eye point is inside the extent, this returns 0.
        Parameters:
        dc - the DrawContext which the View eye point is obtained from.
        extent - the extent to compute the distance from.
        Returns:
        the distance from the View eye point to the extent, in model coordinates.
        Throws:
        java.lang.IllegalArgumentException - if either the DrawContext or the extent is null.
      • computeSizeInWindowCoordinates

        public static double computeSizeInWindowCoordinates​(DrawContext dc,
                                                            Extent extent)
        Returns the size in window coordinates of the specified Extent from the current View. The returned size is an estimate of the Extent's diameter in window coordinates.
        Parameters:
        dc - the current draw context, from which the View is obtained from.
        extent - the extent to compute the window size for.
        Returns:
        size of the specified Extent from the specified View, in window coordinates (screen pixels).
        Throws:
        java.lang.IllegalArgumentException - if either the DrawContext or the extent is null.
      • computeSphereProjectedArea

        public static double computeSphereProjectedArea​(View view,
                                                        Vec4 center,
                                                        double radius)
        Computes the area in square pixels of a sphere after it is projected into the specified view's viewport. The returned value is the screen area that the sphere covers in the infinite plane defined by the view's viewport. This area is not limited to the size of the view's viewport, and portions of the sphere are not clipped by the view's frustum.

        This returns zero if the specified radius is zero.

        Parameters:
        view - the View for which to compute a projected screen area.
        center - the sphere's center point, in model coordinates.
        radius - the sphere's radius, in meters.
        Returns:
        the projected screen area of the sphere in square pixels.
        Throws:
        java.lang.IllegalArgumentException - if the view is null, if center is null, or if radius is less than zero.
      • computeBufferNormal

        public static Vec4 computeBufferNormal​(java.nio.FloatBuffer coords,
                                               int stride)
        Computes a unit-length normal vector for a buffer of coordinate triples. The normal vector is computed from the first three non-colinear points in the buffer.
        Parameters:
        coords - the coordinates. This method returns null if this argument is null.
        stride - the number of floats between successive points. 0 indicates that the points are arranged one immediately after the other.
        Returns:
        the computed unit-length normal vector, or null if a normal vector could not be computed.
      • computeArrayNormal

        public static Vec4 computeArrayNormal​(Vec4[] coords)
        Computes a unit-length normal vector for an array of coordinates. The normal vector is computed from the first three non-colinear points in the array.
        Parameters:
        coords - the coordinates. This method returns null if this argument is null.
        Returns:
        the computed unit-length normal vector, or null if a normal vector could not be computed.
      • findThreeIndependentVertices

        public static Vec4[] findThreeIndependentVertices​(java.nio.FloatBuffer coords,
                                                          int stride)
        Finds three non-colinear points in a buffer.
        Parameters:
        coords - the coordinates. This method returns null if this argument is null.
        stride - the number of floats between successive points. 0 indicates that the points are arranged one immediately after the other.
        Returns:
        an array of three points, or null if three non-colinear points could not be found.
      • findThreeIndependentVertices

        public static Vec4[] findThreeIndependentVertices​(Vec4[] coords)
        Finds three non-colinear points in an array of points.
        Parameters:
        coords - the coordinates. This method returns null if this argument is null.
        Returns:
        an array of three points, or null if three non-colinear points could not be found.
      • computeTriangleNormal

        public static Vec4 computeTriangleNormal​(Vec4 a,
                                                 Vec4 b,
                                                 Vec4 c)
        Returns the normal vector corresponding to the triangle defined by three vertices (a, b, c).
        Parameters:
        a - the triangle's first vertex.
        b - the triangle's second vertex.
        c - the triangle's third vertex.
        Returns:
        the triangle's unit-length normal vector.
        Throws:
        java.lang.IllegalArgumentException - if any of the specified vertices are null.
      • computePolygonAreaFromVertices

        public static double computePolygonAreaFromVertices​(java.lang.Iterable<? extends Vec4> points)
        Returns the area enclosed by the specified (x, y) points (the z and w coordinates are ignored). If the specified points do not define a closed loop, then the loop is automatically closed by simulating appending the first point to the last point.
        Parameters:
        points - the (x, y) points which define the 2D polygon.
        Returns:
        the area enclosed by the specified coordinates.
        Throws:
        java.lang.IllegalArgumentException - if points is null.
      • computeWindingOrderOfLocations

        public static java.lang.String computeWindingOrderOfLocations​(java.lang.Iterable<? extends LatLon> locations)
        Returns the winding order of the polygon described by the specified locations, with respect to an axis perpendicular to the (lat, lon) coordinates, and pointing in the direction of "positive elevation".
        Parameters:
        locations - the locations defining the geographic polygon.
        Returns:
        AVKey.CLOCKWISE if the polygon has clockwise winding order, and AVKey.COUNTER_CLOCKWISE otherwise.
      • computeWindingOrderOfVertices

        public static java.lang.String computeWindingOrderOfVertices​(java.lang.Iterable<? extends Vec4> points)
        Returns the winding order of the 2D polygon described by the specified (x, y) points (z and w coordinates are ignored), with respect to the positive z axis.
        Parameters:
        points - the (x, y) points which define the 2D polygon.
        Returns:
        AVKey.CLOCKWISE if the polygon has clockwise winding order about the positive z axis, and AVKey.COUNTER_CLOCKWISE otherwise.
      • computePrincipalAxes

        public static Vec4[] computePrincipalAxes​(java.lang.Iterable<? extends Vec4> points)
        Returns an array of normalized vectors defining the three principal axes of the x-, y-, and z-coordinates from the specified points Iterable, sorted from the most prominent axis to the least prominent. This returns null if the points Iterable is empty, or if all of the points are null. The returned array contains three normalized orthogonal vectors defining a coordinate system which best fits the distribution of the points Iterable about its arithmetic mean.
        Parameters:
        points - the Iterable of points for which to compute the principal axes.
        Returns:
        the normalized principal axes of the points Iterable, sorted from the most prominent axis to the least prominent.
        Throws:
        java.lang.IllegalArgumentException - if the points Iterable is null.
      • computePrincipalAxes

        public static Vec4[] computePrincipalAxes​(BufferWrapper coordinates,
                                                  int stride)
        Returns an array of normalized vectors defining the three principal axes of the x-, y-, and z-coordinates from the specified buffer of points, sorted from the most prominent axis to the least prominent. This returns null if the buffer is empty. The returned array contains three normalized orthogonal vectors defining a coordinate system which best fits the distribution of the points about its arithmetic mean.

        The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride. The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the remaining elements that follow the last complete tuple.

        Parameters:
        coordinates - the buffer containing the point coordinates for which to compute the principal axes.
        stride - the number of elements between the first coordinate of consecutive points. If stride is 3, this interprets the buffer has having tightly packed XYZ coordinate tuples.
        Returns:
        the normalized principal axes of the points, sorted from the most prominent axis to the least prominent.
        Throws:
        java.lang.IllegalArgumentException - if the buffer is null, or if the stride is less than three.
      • isPolygonClosed

        public static boolean isPolygonClosed​(java.lang.Iterable<? extends LatLon> locations)
        Returns whether the geographic polygon described by the specified locations defines a closed loop. If the iterable holds fewer than two points, this always returns false. Therefore a polygon consisting of a single point and the empty polygon are not considered closed loops.
        Parameters:
        locations - the locations which define the geographic polygon.
        Returns:
        true if the polygon defines a closed loop, and false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the locations are null.
      • isPolygonClosed2

        public static boolean isPolygonClosed2​(java.lang.Iterable<? extends Vec4> points)
        Returns whether the 2D polygon described by the specified (x, y) points defines a closed loop (z and w coordinates are ignored). If the iterable holds fewer than two points, this always returns false. Therefore a polygon consisting of a single point and the empty polygon are not considered closed loops.
        Parameters:
        points - the (x, y) points which define the 2D polygon.
        Returns:
        true if the polygon defines a closed loop, and false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if the points are null.
      • isLocationInside

        public static boolean isLocationInside​(LatLon location,
                                               java.lang.Iterable<? extends LatLon> locations)
        Determines whether a LatLon location is located inside a given polygon.
        Parameters:
        location - the location
        locations - the list of positions describing the polygon. Last one should be the same as the first one.
        Returns:
        true if the location is inside the polygon.
      • computeCircleThroughPoints

        public static boolean computeCircleThroughPoints​(Vec4 p0,
                                                         Vec4 p1,
                                                         Vec4 p2,
                                                         Vec4[] centerOut,
                                                         Vec4[] axisOut,
                                                         double[] radiusOut)
        Computes the center, axis, and radius of the circle that circumscribes the specified points. If the points are oriented in a clockwise winding order, the circle's axis will point toward the viewer. Otherwise the axis will point away from the viewer. Values are returned in the first element of centerOut, axisOut, and radiusOut. The caller must provide a preallocted arrays of length one or greater for each of these values.
        Parameters:
        p0 - the first point.
        p1 - the second point.
        p2 - the third point.
        centerOut - preallocated array to hold the circle's center.
        axisOut - preallocated array to hold the circle's axis.
        radiusOut - preallocated array to hold the circle's radius.
        Returns:
        true if the computation was successful; false otherwise.
        Throws:
        java.lang.IllegalArgumentException - if p0, p1, or p2 is null
      • polytopeIntersect

        public static Intersection[] polytopeIntersect​(Line line,
                                                       Plane[] planes)
        Intersect a line with a convex polytope and return the intersection points.

        See "3-D Computer Graphics" by Samuel R. Buss, 2005, Section X.1.4.

        Parameters:
        line - the line to intersect with the polytope.
        planes - the planes defining the polytope. Each plane's normal must point away from the the polytope, i.e. each plane's positive halfspace is outside the polytope. (Note: This is the opposite convention from that of a view frustum.)
        Returns:
        the points of intersection, or null if the line does not intersect the polytope. Two points are returned if the line both enters and exits the polytope. One point is retured if the line origin is within the polytope.
        Throws:
        java.lang.IllegalArgumentException - if the line is null or ill-formed, the planes array is null or there are fewer than three planes.
      • computeIndicesForGridInterior

        public static java.nio.IntBuffer computeIndicesForGridInterior​(int width,
                                                                       int height)
        Computes an index buffer in the system native byte order that tessellates the interior of a vertex grid as a triangle strip. The returned buffer may be used as the source buffer in a call to GL2ES1.glDrawElements(int, int, int, java.nio.Buffer), where mode is GL.GL_TRIANGLE_STRIP, count is the number of elements remaining in the buffer, and type is GL.GL_UNSIGNED_INT.

        For details the drawing OpenGL primitives, see http://www.glprogramming.com/red/chapter02.html#name14.

        Parameters:
        width - the patch width, in vertices.
        height - the patch height, in vertices.
        Returns:
        an index buffer that tessellate's the grid interior as a triangle strip.
        Throws:
        java.lang.IllegalArgumentException - if either the width or height are less than or equal to zero.
      • computeIndicesForGridOutline

        public static java.nio.IntBuffer computeIndicesForGridOutline​(int width,
                                                                      int height)
        Computes an index buffer in the system native byte order that tessellates the outline of a vertex grid as a line strip. The returned buffer may be used as the source buffer in a call to GL2ES1.glDrawElements(int, int, int, java.nio.Buffer), where mode is GL.GL_LINE_STRIP, count is the number of elements remaining in the buffer, and type is GL.GL_UNSIGNED_INT.

        For details the drawing OpenGL primitives, see http://www.glprogramming.com/red/chapter02.html#name14.

        Parameters:
        width - the patch width, in vertices.
        height - the patch height, in vertices.
        Returns:
        an index buffer that tessellates the grid outline as a line strip.
        Throws:
        java.lang.IllegalArgumentException - if either the width or height are less than or equal to zero.
      • computeNormalsForIndexedTriangleStrip

        public static java.nio.FloatBuffer computeNormalsForIndexedTriangleStrip​(java.nio.IntBuffer indices,
                                                                                 java.nio.FloatBuffer vertices,
                                                                                 java.nio.FloatBuffer normals)
        Computes per-vertex normals of an indexed triangle strip, storing the normal coordinates in the specified normal buffer. If the normal buffer is null, this creates a new buffer in the system native byte order with the capacity to store the same number of vertices as the vertex buffer. The vertex buffer is assumed to contain tightly packed 3-coordinate tuples. The 3-coordinate normal for each vertex is stored in the normal buffer at the same position each vertex appears in the vertex buffer.

        For details the drawing OpenGL primitives, see http://www.glprogramming.com/red/chapter02.html#name14.

        Parameters:
        indices - indices into the vertex buffer defining a triangle strip.
        vertices - buffer of vertex coordinate tuples used to compute the normal coordinates.
        normals - buffer of normal coordinate tuples that receives the normal coordinates, or null to create a new buffer to hold the normal coordinates.
        Returns:
        buffer of normal coordinate tuples.
        Throws:
        java.lang.IllegalArgumentException - if either the index buffer or the vertex buffer is null.
      • addTriangleNormal

        protected static void addTriangleNormal​(int a,
                                                int b,
                                                int c,
                                                java.nio.FloatBuffer vertices,
                                                java.nio.FloatBuffer normals)
        Computes a triangle normal given the starting position of three tuples in the specified vertex buffer, and stores adds the result to three tuples in the specified normal buffer with the same positions.
        Parameters:
        a - the first tuple's starting position.
        b - the second tuple's starting position.
        c - the third tuple's starting position.
        vertices - buffer of vertex coordinate tuples used to compute the normal coordinates.
        normals - buffer of normal coordinate tuples that receives the normal coordinates.
      • normalize3

        protected static void normalize3​(java.nio.FloatBuffer buffer)
        Normalizes the 3-coordinate tuple starting at the buffer's position, then advances the buffer's position to the end of the tuple.
        Parameters:
        buffer - the buffer to normalize.
        Throws:
        java.lang.NullPointerException - if the buffer is null.
      • bresenham

        public static java.util.List<java.awt.Point> bresenham​(int x0,
                                                               int y0,
                                                               int x1,
                                                               int y1)
        Computes a line between two integer-coordinate points using Bresenham's algorithm.
        Parameters:
        x0 - the x coordinate of the first point.
        y0 - the y coordinate of the first point, relative to an upper-left origin.
        x1 - the x coordinate of the second point.
        y1 - the y coordinate of the second point, relative to an upper-left origin.
        Returns:
        a list of points defining a line between the two input points.
      • generateParallelLines

        public static void generateParallelLines​(java.util.List<Position> controlPositions,
                                                 java.util.List<Position> leftPositions,
                                                 java.util.List<Position> rightPositions,
                                                 double distance,
                                                 Globe globe)
        Create positions that describe lines parallel to a control line.
        Parameters:
        controlPositions - List of positions along the control line. Must be greater than 1.
        leftPositions - List to receive positions on the left line.
        rightPositions - List to receive positions on the right line.
        distance - Distance from the center line to the left and right lines.
        globe - Globe used to compute positions.
        Throws:
        java.lang.IllegalArgumentException - if any of the lists are null, the number of control positions is less than 2, or the globe is null.
      • generateParallelPoints

        public static Vec4 generateParallelPoints​(Vec4 point,
                                                  Vec4 prev,
                                                  Vec4 next,
                                                  java.util.List<Position> leftPositions,
                                                  java.util.List<Position> rightPositions,
                                                  double distance,
                                                  double elevation,
                                                  Globe globe,
                                                  Vec4 previousOffset)
        Compute points on either side of a line segment. This method requires a point on the line, and either a next point, previous point, or both.
        Parameters:
        point - Center point about which to compute side points.
        prev - Previous point on the line. May be null if next is non-null.
        next - Next point on the line. May be null if prev is non-null.
        leftPositions - Left position will be added to this list.
        rightPositions - Right position will be added to this list.
        distance - Distance from the center line to the left and right lines.
        elevation - Elevation at which to place the generated positions.
        globe - Globe used to compute positions.
        previousOffset - Offset vector from a previous call to this method. May be null.
        Returns:
        Offset vector that should be passed back to this method on the next call for a list of positions. (Used to generate parallel points when a position list contains sequential co-located positions.)
        Throws:
        java.lang.IllegalArgumentException - if the necessary point, previous or next references are null, either the left or right position list is null, or the globe is null.