LRAUV  revA
AuvMath Class Reference

Contains useful math-related utilities. More...

#include <AuvMath.h>

Public Member Functions

template<>
uint8_t FlipEndian (uint8_t value)
 Has no effect, but included for use by template functions that accept uint8_t. More...
 
template<>
int8_t FlipEndian (int8_t value)
 Has no effect, but included for use by template functions that accept int8_t. More...
 
template<>
uint16_t FlipEndian (uint16_t value)
 
template<>
int16_t FlipEndian (int16_t value)
 
template<>
uint32_t FlipEndian (uint32_t value)
 
template<>
int32_t FlipEndian (int32_t value)
 
template<>
uint64_t FlipEndian (uint64_t value)
 
template<>
int64_t FlipEndian (int64_t value)
 
template<>
float FlipEndian (float value)
 
template<>
double FlipEndian (double value)
 

Static Public Member Functions

template<typename T >
static T Limit (const T &value, const T &limit1, const T &limit2)
 Makes sure a variable falls within defined limits... More...
 
template<typename T >
static bool InLimit (const T &value, const T &limit1, const T &limit2)
 Tests if a variable falls within defined limits... More...
 
template<typename T >
static T Min (const T &a, const T &b)
 Returns the lesser of the two arguments If either input is nan, nan is returned Unit tests in AuvMath_Test.testMin. More...
 
template<typename T >
static T Max (const T &a, const T &b)
 Returns the greater of the two arguments If either input is nan, nan is returned Unit tests in AuvMath_Test.testMin. More...
 
template<typename T >
static T Square (T number)
 Square function (opposite of sqrt(T)) More...
 
template<typename T >
static void Swap (T &a, T &b)
 Swaps the two arguments. More...
 
template<typename T >
static T FlipEndian (T value)
 Does not test the endianness of the input value, Just flips it. More...
 
template<typename T >
static T Round (const T &value, const T &divisor)
 Makes sure a variable is divisible by specified divisor... More...
 
template<typename T >
static T Sign (const T &x)
 Returns signum function: If input is nan, nan is returned Unit tests in AuvMath_Test.testSign. More...
 
template<typename T >
static T ModPi (const T &angle)
 modulo Pi function: If input is nan, nan is returned Unit tests in AuvMath_Test.testModPi More...
 
template<typename T >
static T NanZero (const T &value)
 Casts nan values to zero – otherwise returns the value Unit tests in AuvMath_Test.testNanZero. More...
 
template<typename T >
static int FindLtEqIndex (const T *values, const T &value, const unsigned int indexMin, const unsigned int indexMax)
 Finds the index within an array where the value is <= the supplied value Searches from indexMin to indexMax within the array. More...
 
template<typename T >
static T Interpolate1D (const T &x, const T &data0, const T &data1, const T &x0, const T &x1)
 Examines a 2 element data field for the value, where x0 <= x <= x1 Unit tests in AuvMath_Test.testInterpolate1D. More...
 
template<typename T >
static T Interpolate2D (const T &x, const T &y, T data[][2], const T &x0, const T &x1, const T &y0, const T &y1)
 Examines a 2x2 data field for the value, where x0 <= x <= x1, y0 <= y <= y1, Unit tests in AuvMath_Test.testInterpolate2D. More...
 
template<typename T >
static T Interpolate3D (const T &x, const T &y, const T &z, T data[][2][2], const T &x0, const T &x1, const T &y0, const T &y1, const T &z0, const T &z1)
 Examines a 2x2x2 data field for the value, where x0 <= x <= x1, y0 <= y <= y1, z0 <= z <= z1 Unit tests in AuvMath_Test.testInterpolate3D. More...
 
template<typename T >
static T Interpolate4D (const T &w, const T &x, const T &y, const T &z, T data[][2][2][2], const T &w0, const T &w1, const T &x0, const T &x1, const T &y0, const T &y1, const T &z0, const T &z1)
 Examines a 2x2x2x2 data field for the value, where w0 <= w <= w1, x0 <= x <= x1, y0 <= y <= y1, z0 <= z <= z1 Unit tests in AuvMath_Test.testInterpolate4D. More...
 
static double BulkModulus (double salinity, double temperature, double pressure)
 Seawater bulk modulus (S,T,P) More...
 
static double Density (double salinity, double temperature, double pressure)
 Seawater density (S,T,P) More...
 
static double OceanDepth (const double &pressure, const double &latitude)
 OceanDepth (pressure, latitude) More...
 
static double OceanPressure (const double &depth, const double &latitude)
 OceanPressure (depth, latitude) More...
 
template<typename T >
static void ShellSort (T array[], int arraySize)
 
static bool AreaContains (float x, float y, int segments, float *x0, float *y0, float *x1, float *y1)
 
static bool TriangleContains (float x, float y, float x0, float y0, float x1, float y1, float x2, float y2)
 
static void UnitVectorToAzimuthAndElevation (Point3D &uhat, float &azimuth, float &elevation)
 
static void AzimuthAndElevationToUnitVector (float &azimuth, float &elevation, Point3D &uhat)
 

Static Public Attributes

static const double TWOPI = M_PI * 2.0
 
static const double DEG_TO_RAD = atan( 1 ) / 45
 
static const double RAD_TO_DEG = 45 / atan( 1 )
 

Detailed Description

Contains useful math-related utilities.

Originally called Math.h, but could be confused with math.h

Member Function Documentation

bool AuvMath::AreaContains ( float  x,
float  y,
int  segments,
float *  x0,
float *  y0,
float *  x1,
float *  y1 
)
static
void AuvMath::AzimuthAndElevationToUnitVector ( float &  azimuth,
float &  elevation,
Point3D uhat 
)
static
double AuvMath::BulkModulus ( double  salinity,
double  temperature,
double  pressure 
)
static

Seawater bulk modulus (S,T,P)

UNESCO Tech Paper Mar Sci 44 (1983)

Use As: bulkmod_(S,T,P)

Input: salinity (psu) temperature (K) pressure (Pa)

Output: Bulk Modulus in Pa

Example: BulkModulus(35,283.15,4e7) -> 2.404604869e9 BulkModulus(35,298.15,1e8)-> 2.710894504e9 UNESCO 36 p19

Copyright (c) 1996 by Moss Landing Marine Laboratories Separated out from DENSITY_83 15 February 1992; W. BroenkowUnit tests in AuvMath_Test.testBulkModulus

Referenced by Density(), and AuvMath_Test::testBulkModulus().

double AuvMath::Density ( double  salinity,
double  temperature,
double  pressure 
)
static

Seawater density (S,T,P)

International Equation of State of Seawater (1980) UNESCO Tech Paper Mar Sci 44 (1983)

Use As: density_(S,T,P)

Input: S = Salinity (psu) T = Temperature (K) P = Pressure (Pa) Output: density (kg/m3)

Example: Density(34.567,278.15,2e7) -> 1036.409 Density(35,298.15,1e8) -> 1062.53817 UNESCO 44 p19

Copyright (c) 1996 by Moss Landing Marine Laboratories William Broenkow Checks perfectly with UNESCO 44. This function requires BulkmodUnit tests in AuvMath_Test.testDensity

References BulkModulus().

Referenced by CTD_NeilBrown::getSimulatedData(), CTD_NeilBrown::preprocessData(), EnvSimulator::simulateSensors(), and AuvMath_Test::testDensity().

template<typename T >
int AuvMath::FindLtEqIndex ( const T *  values,
const T &  value,
const unsigned int  indexMin,
const unsigned int  indexMax 
)
static

Finds the index within an array where the value is <= the supplied value Searches from indexMin to indexMax within the array.

Assumes the array is in increasing order. Unit tests in AuvMath_Test.testFindLtEqIndex

Referenced by EnvSimulator::simulateSensors(), and AuvMath_Test::testFindLtEqIndex().

template<typename T >
static T AuvMath::FlipEndian ( value)
static

Does not test the endianness of the input value, Just flips it.

Referenced by FlipEndian(), BlobValue::getElement(), and BlobValue::setElement().

template<>
uint8_t AuvMath::FlipEndian ( uint8_t  value)

Has no effect, but included for use by template functions that accept uint8_t.

template<>
int8_t AuvMath::FlipEndian ( int8_t  value)

Has no effect, but included for use by template functions that accept int8_t.

template<>
uint16_t AuvMath::FlipEndian ( uint16_t  value)
template<>
int16_t AuvMath::FlipEndian ( int16_t  value)
template<>
uint32_t AuvMath::FlipEndian ( uint32_t  value)
template<>
int32_t AuvMath::FlipEndian ( int32_t  value)
template<>
uint64_t AuvMath::FlipEndian ( uint64_t  value)
template<>
int64_t AuvMath::FlipEndian ( int64_t  value)
template<>
float AuvMath::FlipEndian ( float  value)

References FlipEndian().

template<>
double AuvMath::FlipEndian ( double  value)

References FlipEndian().

template<typename T >
bool AuvMath::InLimit ( const T &  value,
const T &  limit1,
const T &  limit2 
)
static

Tests if a variable falls within defined limits...

Tests whether a variable falls within defined limits...

Either limit may be min or max. If any input is nan, false is returned Unit tests in AuvMath_Test.testLimit

Either limit may be min or max. If any input is nan, nan is returned

Referenced by PNI_TCM::runnable().

template<typename T >
T AuvMath::Interpolate1D ( const T &  x,
const T &  data0,
const T &  data1,
const T &  x0,
const T &  x1 
)
static

Examines a 2 element data field for the value, where x0 <= x <= x1 Unit tests in AuvMath_Test.testInterpolate1D.

Referenced by TableLogWriter::interpolateDataEntry(), AuvMath_Test::testInterpolate1D(), HFRadarModelPoint::travelTime(), and EnvSimulator::twoLineEstimate().

template<typename T >
T AuvMath::Interpolate2D ( const T &  x,
const T &  y,
data[][2],
const T &  x0,
const T &  x1,
const T &  y0,
const T &  y1 
)
static

Examines a 2x2 data field for the value, where x0 <= x <= x1, y0 <= y <= y1, Unit tests in AuvMath_Test.testInterpolate2D.

Referenced by HFRCMSpaceInterpolator::interpolateRaveledTwoDimensionalGrid(), HFRadarModelPoint::makeFine(), and AuvMath_Test::testInterpolate2D().

template<typename T >
T AuvMath::Interpolate3D ( const T &  x,
const T &  y,
const T &  z,
data[][2][2],
const T &  x0,
const T &  x1,
const T &  y0,
const T &  y1,
const T &  z0,
const T &  z1 
)
static

Examines a 2x2x2 data field for the value, where x0 <= x <= x1, y0 <= y <= y1, z0 <= z <= z1 Unit tests in AuvMath_Test.testInterpolate3D.

Referenced by EnvSimulator::interpolate(), HFRCMReconstructedInterpolator::interpolateRaveledThreeDimensionalGrid(), HFRadarModelCalc::lookup(), and AuvMath_Test::testInterpolate3D().

template<typename T >
T AuvMath::Interpolate4D ( const T &  w,
const T &  x,
const T &  y,
const T &  z,
data[][2][2][2],
const T &  w0,
const T &  w1,
const T &  x0,
const T &  x1,
const T &  y0,
const T &  y1,
const T &  z0,
const T &  z1 
)
static

Examines a 2x2x2x2 data field for the value, where w0 <= w <= w1, x0 <= x <= x1, y0 <= y <= y1, z0 <= z <= z1 Unit tests in AuvMath_Test.testInterpolate4D.

Referenced by AuvMath_Test::testInterpolate4D().

template<typename T >
T AuvMath::Limit ( const T &  value,
const T &  limit1,
const T &  limit2 
)
static
template<typename T >
static T AuvMath::Max ( const T &  a,
const T &  b 
)
inlinestatic
double AuvMath::OceanDepth ( const double &  pressure,
const double &  latitude 
)
static

OceanDepth (pressure, latitude)

For pressure in pascals and latitude in radians, return depth in meters.

Use As: OceanDepth(pressure, latitude)

Input: pressure (Pa), latitude (radians) Output: Depth (m)

Example: Depth(5e7,0.628318531) -> 4906.08 Depth(1e8,1.570796327) -> 9674.23 UNESCO 44 p28

Note: For more accurate results an additional factor of the ratio of the actual geopotential anomaly/gravity must be added. This correction will be less than 2 m.

Ref: UNESCO Tech Paper Mar Sci 44 (1983) Copyright (c) 1996 by Moss Landing Marine Laboratories 17 Jan 1996; W. Broenkow Matlabized from UNESCO83.FORUnit tests in AuvMath_Test.testOceanDepth

Referenced by CTD_NeilBrown::preprocessData(), Depth_Keller::run(), and AuvMath_Test::testOceanDepth().

double AuvMath::OceanPressure ( const double &  depth,
const double &  latitude 
)
static

OceanPressure (depth, latitude)

For depth in meters and latitude in radians, return pressure in pascals.

Use As: OceanPressure(depth, latitude)

Input: depth (m), latitude (radians) Output: pressure (Pa)

Example: OceanPressure(4906.08,0.628318531) -> 5e7 OceanPressure(9674.23,1.570796327) -> 1e8 UNESCO 44 p28

Ref: UNESCO Tech Paper Mar Sci 44 (1983)Unit tests in AuvMath_Test.testOceanPressure

Referenced by CTD_NeilBrown::getSimulatedData(), Depth_Keller::run(), ExternalSim::run(), EnvSimulator::simulateSensors(), and AuvMath_Test::testOceanPressure().

template<typename T >
T AuvMath::Round ( const T &  value,
const T &  divisor 
)
static

Makes sure a variable is divisible by specified divisor...

If any input is nan, nan is returned Unit tests in AuvMath_Test.testRound

If any input is nan, nan is returned

Referenced by AuvMath_Test::testRound().

template<typename T >
static void AuvMath::ShellSort ( array[],
int  arraySize 
)
inlinestatic
template<typename T >
T AuvMath::Sign ( const T &  x)
static
template<typename T >
static T AuvMath::Square ( number)
inlinestatic
template<typename T >
static void AuvMath::Swap ( T &  a,
T &  b 
)
inlinestatic

Swaps the two arguments.

Referenced by AuvMath_Test::testSwap(), and Matrix3x3::transpose().

bool AuvMath::TriangleContains ( float  x,
float  y,
float  x0,
float  y0,
float  x1,
float  y1,
float  x2,
float  y2 
)
static

References AreaContains().

void AuvMath::UnitVectorToAzimuthAndElevation ( Point3D uhat,
float &  azimuth,
float &  elevation 
)
static

Referenced by DAT::directionsToAngles().

Member Data Documentation

const double AuvMath::DEG_TO_RAD = atan( 1 ) / 45
static

Referenced by ExternalSim::run().

const double AuvMath::RAD_TO_DEG = 45 / atan( 1 )
static

Referenced by DVL_micro::simNQ1().

const double AuvMath::TWOPI = M_PI * 2.0
static

The documentation for this class was generated from the following files: