public class WWMath
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static double |
DAY_TO_MILLIS |
static double |
HOUR_TO_MILLIS |
static LatLon |
LONGITUDE_OFFSET_180 |
static double |
METERS_TO_FEET |
static double |
METERS_TO_KILOMETERS |
static double |
METERS_TO_MILES |
static double |
METERS_TO_NAUTICAL_MILES |
static double |
METERS_TO_YARDS |
static double |
MINUTE_TO_MILLIS |
static double |
SECOND_TO_MILLIS |
static double |
SQUARE_METERS_TO_ACRES |
static double |
SQUARE_METERS_TO_HECTARES |
static double |
SQUARE_METERS_TO_SQUARE_FEET |
static double |
SQUARE_METERS_TO_SQUARE_KILOMETERS |
static double |
SQUARE_METERS_TO_SQUARE_MILES |
static double |
SQUARE_METERS_TO_SQUARE_YARDS |
Constructor and Description |
---|
WWMath() |
Modifier and Type | Method and 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)
|
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)
|
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(java.nio.FloatBuffer coords,
int stride)
Finds three non-colinear points in a buffer.
|
static Vec4[] |
findThreeIndependentVertices(Vec4[] coords)
Finds three non-colinear points in an array of points.
|
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.
|
public static final double DAY_TO_MILLIS
public static final double HOUR_TO_MILLIS
public static final LatLon LONGITUDE_OFFSET_180
public static final double METERS_TO_FEET
public static final double METERS_TO_KILOMETERS
public static final double METERS_TO_MILES
public static final double METERS_TO_NAUTICAL_MILES
public static final double METERS_TO_YARDS
public static final double MINUTE_TO_MILLIS
public static final double SECOND_TO_MILLIS
public static final double SQUARE_METERS_TO_ACRES
public static final double SQUARE_METERS_TO_HECTARES
public static final double SQUARE_METERS_TO_SQUARE_FEET
public static final double SQUARE_METERS_TO_SQUARE_KILOMETERS
public static final double SQUARE_METERS_TO_SQUARE_MILES
public static final double SQUARE_METERS_TO_SQUARE_YARDS
protected static void addTriangleNormal(int a, int b, int c, java.nio.FloatBuffer vertices, java.nio.FloatBuffer normals)
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.public static java.util.List<java.awt.Point> bresenham(int x0, int y0, int x1, int y1)
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.public static double clamp(double v, double min, double max)
v
- the value to clamp.min
- the floor.max
- the ceilingpublic static int clamp(int v, int min, int max)
v
- the value to clamp.min
- the floor.max
- the ceilingpublic static Vec4 computeArrayNormal(Vec4[] coords)
coords
- the coordinates. This method returns null if this argument is null.public static Vec4 computeBufferNormal(java.nio.FloatBuffer coords, int stride)
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.public static boolean computeCircleThroughPoints(Vec4 p0, Vec4 p1, Vec4 p2, Vec4[] centerOut, Vec4[] axisOut, double[] radiusOut)
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.java.lang.IllegalArgumentException
- if p0
, p1
, or p2
is nullpublic static double computeDistanceFromEye(DrawContext dc, Extent extent)
View
eye point to the specified
Extent
. If the View eye point is inside the extent, this returns 0.dc
- the DrawContext
which the View eye point is obtained from.extent
- the extent to compute the distance from.java.lang.IllegalArgumentException
- if either the DrawContext or the extent is null.public static java.nio.IntBuffer computeIndicesForGridInterior(int width, int height)
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.width
- the patch width, in vertices.height
- the patch height, in vertices.java.lang.IllegalArgumentException
- if either the width or height are less than or equal to zero.public static java.nio.IntBuffer computeIndicesForGridOutline(int width, int height)
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.width
- the patch width, in vertices.height
- the patch height, in vertices.java.lang.IllegalArgumentException
- if either the width or height are less than or equal to zero.public static double computeInterpolationFactor(double v, double x, double y)
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
.v
- the value to compute the interpolation factor for.x
- the first value.y
- the second value.v
given the specified range [x, y]
public static java.nio.FloatBuffer computeNormalsForIndexedTriangleStrip(java.nio.IntBuffer indices, java.nio.FloatBuffer vertices, java.nio.FloatBuffer normals)
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.java.lang.IllegalArgumentException
- if either the index buffer or the vertex buffer is null.public static double computePolygonAreaFromVertices(java.lang.Iterable<? extends Vec4> points)
points
- the (x, y) points which define the 2D polygon.java.lang.IllegalArgumentException
- if points is null.protected static int[] computePowers(int base, int numPowers)
base
- the number whose powers to compute.numPowers
- the number of powers to compute.public static Vec4[] computePrincipalAxes(BufferWrapper coordinates, int stride)
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.java.lang.IllegalArgumentException
- if the buffer is null, or if the stride is less than three.public static Vec4[] computePrincipalAxes(java.lang.Iterable<? extends Vec4> points)
points
- the Iterable of points for which to compute the principal axes.java.lang.IllegalArgumentException
- if the points Iterable is null.public static double computeSizeInWindowCoordinates(DrawContext dc, Extent extent)
Extent
from the current
View
. The returned size is an estimate of the Extent's diameter in window
coordinates.dc
- the current draw context, from which the View is obtained from.extent
- the extent to compute the window size for.java.lang.IllegalArgumentException
- if either the DrawContext or the extent is null.public static double computeSphereProjectedArea(View view, Vec4 center, double radius)
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.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.java.lang.IllegalArgumentException
- if the view
is null
, if center
is
null
, or if radius
is less than zero.public static Vec4 computeTriangleNormal(Vec4 a, Vec4 b, Vec4 c)
a
- the triangle's first vertex.b
- the triangle's second vertex.c
- the triangle's third vertex.java.lang.IllegalArgumentException
- if any of the specified vertices are null.public static java.lang.String computeWindingOrderOfLocations(java.lang.Iterable<? extends LatLon> locations)
locations
- the locations defining the geographic polygon.AVKey.CLOCKWISE
if the polygon has clockwise winding order, and AVKey.COUNTER_CLOCKWISE
otherwise.public static java.lang.String computeWindingOrderOfVertices(java.lang.Iterable<? extends Vec4> points)
points
- the (x, y) points which define the 2D polygon.public static double convertDaysToMillis(double millis)
millis
- time in days.public static double convertFeetToMeters(double feet)
feet
- the distance in feet.public static double convertHoursToMillis(double hours)
hours
- time in hours.public static double convertMetersToFeet(double meters)
meters
- the value in meters.public static double convertMetersToMiles(double meters)
meters
- the value in meters.public static double convertMillisToDays(double millis)
millis
- time in milliseconds.public static double convertMillisToHours(double mills)
mills
- time in milliseconds.public static double convertMillisToMinutes(double millis)
millis
- time in milliseconds.public static double convertMillisToSeconds(double millis)
millis
- time in milliseconds.public static double convertMinutesToMillis(double minutes)
minutes
- time in minutes.public static double convertSecondsToMillis(double seconds)
seconds
- time in seconds.public static Vec4[] findThreeIndependentVertices(java.nio.FloatBuffer coords, int stride)
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.public static Vec4[] findThreeIndependentVertices(Vec4[] coords)
coords
- the coordinates. This method returns null if this argument is null.public static void generateParallelLines(java.util.List<Position> controlPositions, java.util.List<Position> leftPositions, java.util.List<Position> rightPositions, double distance, Globe globe)
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.java.lang.IllegalArgumentException
- if any of the lists are null, the number of control positions is less than 2, or
the globe is null.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)
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.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.public static boolean isLocationInside(LatLon location, java.lang.Iterable<? extends LatLon> locations)
LatLon
location is located inside a given polygon.location
- the locationlocations
- the list of positions describing the polygon. Last one should be the same as the first one.public static boolean isPolygonClosed(java.lang.Iterable<? extends LatLon> locations)
locations
- the locations which define the geographic polygon.java.lang.IllegalArgumentException
- if the locations are null.public static boolean isPolygonClosed2(java.lang.Iterable<? extends Vec4> points)
points
- the (x, y) points which define the 2D polygon.java.lang.IllegalArgumentException
- if the points are null.public static boolean isPowerOfTwo(int value)
value
- the value to test for power of 2public static double logBase2(double value)
value
- the value to take the log of.public static double mix(double a, double x, double y)
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
.a
- the interpolation factor.x
- the first value.y
- the second value.x
and y
.public static double mixSmooth(double a, double x, double y)
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.a
- the interpolation factor.x
- the first value.y
- the second value.x
and y
.protected static void normalize3(java.nio.FloatBuffer buffer)
buffer
- the buffer to normalize.java.lang.NullPointerException
- if the buffer is null.public static Intersection[] polytopeIntersect(Line line, Plane[] planes)
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.)java.lang.IllegalArgumentException
- if the line is null or ill-formed, the planes array is null or there are fewer
than three planes.public static int powerOfTwoCeiling(int reference)
reference
- the reference value. The power of 2 returned is greater than or equal to this value.public static int powerOfTwoFloor(int reference)
reference
- the reference value. The power of 2 returned is less than or equal to this value.public static double smoothStepValue(double value, double min, double max)
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:
value
- the value to compare to the minimum and maximum.min
- the minimum value.max
- the maximum value.public static double stepValue(double value, double min, double max)
value
- the value to compare to the minimum and maximum.min
- the minimum value.max
- the maximum value.