uavsim.windmodel
Class WindVelocityCell

java.lang.Object
  extended by uavsim.windmodel.WindVelocityCell

public class WindVelocityCell
extends java.lang.Object

This class defines a lookup table for a simple encoding that provides approximate wind velocity in knots through linear interpolation on discrete altitude planes within a three-dimensional cell in the world. A cell is defined as a square with the size of one degree of latitude in our flat-earth world model. Its bottom-right corner anchors to the world by the degree component of a latitude and longitude. Six stacked altitude planes define the velocities at 0, 3000, 6000, 9000, 12000 feet, and 15000 feet. Altitudes outside this range clamp to the limits.

The definition resides in a separate text file for each cell. The format is as follows, where each dot grid is an altitude plane left to right in the order indicated above. Rows are latitude, and columns are longitude, both on six-minute intervals offset from the anchor. For simplicity, the navigation model is limited to the northern, western hemisphere, which means latitude is always degrees north and increases upward, and longitude is always degrees west and increases leftward.

latitude_degrees,longitude_degrees
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............
............ ............ ............ ............ ............ ............

A dot indicates no wind. The encoding for the other discrete wind velocities is a single character that takes the place of a dot. It is a two-phase encoding that combines both the direction and speed. The direction component is based on the eight cardinal and intercardinal directions with the following base characters:

 Char  Direction
 ----  ---------
  a         0
  f        45
  k        90
  p       135
  u       180
  z       225
  E       270
  J       315
 
The speed component is alphabetically derived from the base character, which itself indicates 10 knots in the specified direction. Adding 1 to the character (e.g., a+1=b) indicates 20 knots, whereas 2 is 30, 3 is 40, and 4 is 50. The complete encoding table is as follows:
 Char  Direction  Speed      Char  Direction  Speed
 ----  ---------  -----      ----  ---------  -----
  .         0        0
  a         0       10        u       180       10
  b         0       20        v       180       20
  c         0       30        w       180       30
  d         0       40        x       180       40
  e         0       50        y       180       50
 
f 45 10 z 225 10 g 45 20 A 225 20 h 45 30 B 225 30 i 45 40 C 225 40 j 45 50 D 225 50
k 90 10 E 270 10 l 90 20 F 270 20 m 90 30 G 270 30 n 90 40 H 270 40 o 90 50 I 270 50
p 135 10 J 315 10 q 135 20 K 315 20 r 135 30 L 315 30 s 135 40 M 315 40 t 135 50 N 315 50

Author:
Dan Tappan [09.10.11]

Nested Class Summary
private  class WindVelocityCell.SubcellIndex
          Defines a data wrapper for the row, column, and plane indices into the cell.
 
Field Summary
private  CoordinateWorld _cellAnchor
          the bottom-right cell coordinate in degrees latitude and longitude.
private  java.lang.String _filename
          the fully qualified filename of the cell definition
private  Velocity[][][] _subcells
          the subcell grid, as minutes of latitude, minutes of longitude, and altitude
private static int[] ALTITUDES
          the altitude planes in feet
private static int CELL_SIZE_HORIZONTAL
          the horizontal size of the square cell, where each subcell corresponds to six degrees of latitude and latitude
private static int CELL_SIZE_VERTICAL
          the vertical size of the cell, where the altitude layers are 0, 3000, 6000, 9000, 12000, and 15000 feet
private static char ENCODING_NO_WIND
          the velocity encoding for no wind
private static java.lang.String ENCODING_WIND
          the velocity encoding for wind
private static int MINUTES_PER_SUBCELL
          the span in latitude and longitude minutes represented by each subcell
private static int[] WIND_RATES
          the wind rates corresponding to base encoding plus 0, 1, 2, 3, and 4, respectively
 
Constructor Summary
WindVelocityCell(java.lang.String filename)
          Creates a wind-velocity cell.
 
Method Summary
private  Scaler calculateScaler(A_LatitudeLongitude<?> latitudeOrLongitude)
          Calculates the scaler between the two nearest latitude or longitude samples.
private  Scaler calculateScaler(Altitude altitude)
          Calculates the scaler between the two nearest altitude samples.
private  Velocity decodeVelocity(char encoding)
          Decodes a character encoding into a velocity.
 java.lang.StringBuilder dump()
          Generates a tabular representation of the wind definition, where the first value is direction in navigational degrees and the second speed in knots.
 CoordinateWorld getCellAnchor()
          Gets the bottom-right anchor coordinate of this cell.
 java.lang.String getCellFilename()
          Gets the fully qualified filename of the definition file for this cell.
 Velocity interpolate(CoordinateWorld3D coordinate)
          Esimates the wind velocity at a coordinate through three-dimension linear interpolation.
private  Velocity interpolatePlane(CoordinateWorld3D coordinate, boolean isPlaneBelowOrAbovecoordinate)
          Interpolates a coordinate by interpolating longitude at a latitude above and below a coordinate, then interpolating a latitude between these two results.
private  Velocity interpolateVelocity(Velocity velocity1, Velocity velocity2, Scaler scaler)
          Interpolates between two velocities.
private  void loadCellDefinition()
          Loads the cell definition from a file.
private  void loadCellDefinitionAnchor(java.io.BufferedReader infile)
          Loads the anchor component of the cell definition.
private  void loadCellDefinitionBody(java.io.BufferedReader infile)
          Loads the body component of the cell definition.
private  int mapPlaneIndex(Altitude altitude)
          Determines which altitude plane on the supported interval lies below an altitude.
private  int mapRowColumnIndex(A_LatitudeLongitude<?> latitudeOrLongitude)
          Determines the row or column index in the subcell grid based on the minutes component of a latitude or longitude, respectively.
private  WindVelocityCell.SubcellIndex mapSubcellIndex(CoordinateWorld3D coordinate)
          Calculates the three-dimensional index in the subcell grid based on a coordinate with altitude.
 java.lang.String toString()
          Returns a text representation of this object with the cell anchor and definition filename.
private  void validateCoordinate(CoordinateWorld coordinate)
          Validates that a coordinate resides on this cell.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_cellAnchor

private CoordinateWorld _cellAnchor
the bottom-right cell coordinate in degrees latitude and longitude. The minutes and seconds are always zero


_filename

private final java.lang.String _filename
the fully qualified filename of the cell definition


_subcells

private final Velocity[][][] _subcells
the subcell grid, as minutes of latitude, minutes of longitude, and altitude


ALTITUDES

private static final int[] ALTITUDES
the altitude planes in feet


CELL_SIZE_HORIZONTAL

private static final int CELL_SIZE_HORIZONTAL
the horizontal size of the square cell, where each subcell corresponds to six degrees of latitude and latitude

See Also:
Constant Field Values

CELL_SIZE_VERTICAL

private static final int CELL_SIZE_VERTICAL
the vertical size of the cell, where the altitude layers are 0, 3000, 6000, 9000, 12000, and 15000 feet

See Also:
Constant Field Values

ENCODING_NO_WIND

private static final char ENCODING_NO_WIND
the velocity encoding for no wind

See Also:
Constant Field Values

ENCODING_WIND

private static final java.lang.String ENCODING_WIND
the velocity encoding for wind

See Also:
Constant Field Values

MINUTES_PER_SUBCELL

private static final int MINUTES_PER_SUBCELL
the span in latitude and longitude minutes represented by each subcell

See Also:
Constant Field Values

WIND_RATES

private static final int[] WIND_RATES
the wind rates corresponding to base encoding plus 0, 1, 2, 3, and 4, respectively

Constructor Detail

WindVelocityCell

public WindVelocityCell(java.lang.String filename)
                 throws java.io.IOException
Creates a wind-velocity cell.

Parameters:
filename - - the fully qualified filename of the cell definition
Throws:
java.io.IOException - for any file error
Method Detail

calculateScaler

private Scaler calculateScaler(A_LatitudeLongitude<?> latitudeOrLongitude)
Calculates the scaler between the two nearest latitude or longitude samples.

Parameters:
latitudeOrLongitude - - the latitude or longitude
Returns:
the scaler

calculateScaler

private Scaler calculateScaler(Altitude altitude)
Calculates the scaler between the two nearest altitude samples.

Parameters:
altitude - - the altitude
Returns:
the scaler

decodeVelocity

private Velocity decodeVelocity(char encoding)
Decodes a character encoding into a velocity.

Parameters:
encoding - - the encoding
Returns:
the velocity

dump

public java.lang.StringBuilder dump()
Generates a tabular representation of the wind definition, where the first value is direction in navigational degrees and the second speed in knots.

Returns:
the representation

getCellAnchor

public CoordinateWorld getCellAnchor()
Gets the bottom-right anchor coordinate of this cell. The minutes and seconds are always zero.

Returns:
the coordinate

getCellFilename

public java.lang.String getCellFilename()
Gets the fully qualified filename of the definition file for this cell.

Returns:
the filename

interpolate

public Velocity interpolate(CoordinateWorld3D coordinate)
                     throws UnsupportedCoordinateException
Esimates the wind velocity at a coordinate through three-dimension linear interpolation.

Parameters:
coordinate - - the coordinate
Returns:
the velocity
Throws:
UnsupportedCoordinateException - if the coordinate is not on this cell

interpolatePlane

private Velocity interpolatePlane(CoordinateWorld3D coordinate,
                                  boolean isPlaneBelowOrAbovecoordinate)
Interpolates a coordinate by interpolating longitude at a latitude above and below a coordinate, then interpolating a latitude between these two results.

Parameters:
coordinate - - the coordinate
isPlaneBelowOrAbovecoordinate - - whether to use the altitude plane below or above the coordinate
Returns:
the interpolated coordinate

interpolateVelocity

private Velocity interpolateVelocity(Velocity velocity1,
                                     Velocity velocity2,
                                     Scaler scaler)
Interpolates between two velocities. The rules are as follows:

Parameters:
velocity1 - - the first velocity
velocity2 - - the second velocity
scaler - - the scaler between the velocities
Returns:
the interpolated velocity

loadCellDefinition

private void loadCellDefinition()
                         throws java.io.IOException
Loads the cell definition from a file.

Throws:
java.io.IOException - for any file error

loadCellDefinitionAnchor

private void loadCellDefinitionAnchor(java.io.BufferedReader infile)
                               throws java.io.IOException
Loads the anchor component of the cell definition. This line specifies the latitude and longitude of the cell definition in this format: latitude_degrees,longitude_degrees

Parameters:
infile - - the input file
Throws:
java.io.IOException - for any file error

loadCellDefinitionBody

private void loadCellDefinitionBody(java.io.BufferedReader infile)
                             throws java.io.IOException
Loads the body component of the cell definition. These lines encode the wind velocity at the subcell coordinates.

Parameters:
infile - - the input file
Throws:
java.io.IOException - for any file error

mapPlaneIndex

private int mapPlaneIndex(Altitude altitude)
Determines which altitude plane on the supported interval lies below an altitude.

Parameters:
altitude - - the altitude
Returns:
the index

mapRowColumnIndex

private int mapRowColumnIndex(A_LatitudeLongitude<?> latitudeOrLongitude)
Determines the row or column index in the subcell grid based on the minutes component of a latitude or longitude, respectively.

Parameters:
latitudeOrLongitude - - the latitude or longitude
Returns:
the index

mapSubcellIndex

private WindVelocityCell.SubcellIndex mapSubcellIndex(CoordinateWorld3D coordinate)
Calculates the three-dimensional index in the subcell grid based on a coordinate with altitude.

Parameters:
coordinate - - the coordinate
Returns:
the subcell index

toString

public java.lang.String toString()
Returns a text representation of this object with the cell anchor and definition filename.

Overrides:
toString in class java.lang.Object
Returns:
the representation

validateCoordinate

private void validateCoordinate(CoordinateWorld coordinate)
                         throws UnsupportedCoordinateException
Validates that a coordinate resides on this cell.

Parameters:
coordinate - - the coordinate
Throws:
UnsupportedCoordinateException - if the coordinate is not on this cell