Utils
Class Units

java.lang.Object
  |
  +--Utils.Units

public class Units
extends java.lang.Object

Routines for units conversion.

This class comes from Tucker Balch: (c)1997, 1998 Tucker Balch

Author:
Tucker Balch

Field Summary
static double HUGE
          A very large number
static double PI
          Handy to have 2 PI around.
static double PI2
           
 
Constructor Summary
Units()
           
 
Method Summary
static double bestTurnDeg(double start, double finish)
          Compute the best direction and angle to turn from the start angle to the finish angle in degrees.
static double bestTurnRad(double start, double finish)
          Compute the best direction and angle to turn from the start angle to the finish angle in radians.
static double clipDeg(double deg)
          Limit the angle to between 0 and 359.9999.
static double clipRad(double rad)
          Limit the angle to between 0 and 2 PI.
static double deg10ToRad(int deg10)
          Convert 10ths of degrees to radians.
static double degToRad(double deg)
          Convert degrees to radians.
static double degToRad(int deg)
          Convert degrees to radians.
static double inch10ToMeter(int inch10)
          Convert 10ths of inches to meters.
static double inchToMeter(double inch)
          Convert inches to meters.
static double inchToMeter(int inch)
          Convert inches to meters.
static void main(java.lang.String[] args)
          Test the units functions.
static double meterToInch(double meter)
          Convert meters to inches.
static int meterToInch10(double meter)
          Convert meters to 10ths of inches.
static double NormalizePI(double t)
          Normalize an angle into the range [0,2*PI]
static double NormalizeZero(double t)
          Normalize an angle into the range [-PI,PI]
static double radToDeg(double rad)
          Convert radians to degrees.
static int radToDeg10(double rad)
          Convert radians to 10ths of degrees.
static double readDouble(java.io.StreamTokenizer in)
          read a double from a stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public static final double PI
Handy to have 2 PI around.

See Also:
Constant Field Values

PI2

public static final double PI2
See Also:
Constant Field Values

HUGE

public static final double HUGE
A very large number

See Also:
Constant Field Values
Constructor Detail

Units

public Units()
Method Detail

NormalizePI

public static double NormalizePI(double t)
Normalize an angle into the range [0,2*PI]


NormalizeZero

public static double NormalizeZero(double t)
Normalize an angle into the range [-PI,PI]


degToRad

public static double degToRad(double deg)
Convert degrees to radians.

Parameters:
deg - double, degrees.
Returns:
radians.

degToRad

public static double degToRad(int deg)
Convert degrees to radians.

Parameters:
deg - int, degrees.
Returns:
radians.

deg10ToRad

public static double deg10ToRad(int deg10)
Convert 10ths of degrees to radians.

Parameters:
deg10 - int, 10ths of degrees.
Returns:
radians.

radToDeg

public static double radToDeg(double rad)
Convert radians to degrees.

Parameters:
rad - double, radians.
Returns:
degrees.

radToDeg10

public static int radToDeg10(double rad)
Convert radians to 10ths of degrees.

Parameters:
rad - double, radians.
Returns:
10ths of degrees.

inchToMeter

public static double inchToMeter(int inch)
Convert inches to meters.

Parameters:
inch - int, inches.
Returns:
meters.

inchToMeter

public static double inchToMeter(double inch)
Convert inches to meters.

Parameters:
inch - double, inches.
Returns:
meters.

inch10ToMeter

public static double inch10ToMeter(int inch10)
Convert 10ths of inches to meters.

Returns:
10ths of meters.

meterToInch10

public static int meterToInch10(double meter)
Convert meters to 10ths of inches.

Parameters:
meter - double, meters.
Returns:
inches.

meterToInch

public static double meterToInch(double meter)
Convert meters to inches.

Parameters:
meter - double, meters.
Returns:
inches.

clipRad

public static double clipRad(double rad)
Limit the angle to between 0 and 2 PI.

Parameters:
rad - double, angle in radians to be clipped.
Returns:
the clipped angle.

clipDeg

public static double clipDeg(double deg)
Limit the angle to between 0 and 359.9999.

Parameters:
deg - double, angle in degrees to be clipped.
Returns:
the clipped angle.

bestTurnDeg

public static double bestTurnDeg(double start,
                                 double finish)
Compute the best direction and angle to turn from the start angle to the finish angle in degrees.

Parameters:
start - The starting angle.
finish - The desired angle.
Returns:
the required turn.

readDouble

public static double readDouble(java.io.StreamTokenizer in)
                         throws java.lang.Exception
read a double from a stream. Assumes you have just read the token.

Parameters:
in - StreamTokenizer, the stream to read from.
Returns:
the double.
Throws:
java.lang.Exception - if there is no number there.

bestTurnRad

public static double bestTurnRad(double start,
                                 double finish)
Compute the best direction and angle to turn from the start angle to the finish angle in radians.

Parameters:
start - The starting angle.
finish - The desired angle.
Returns:
The required turn.

main

public static void main(java.lang.String[] args)
Test the units functions.