gov.sns.tools.math.r3
Class R3

java.lang.Object
  |
  +--gov.sns.tools.math.r3.R3
All Implemented Interfaces:
java.io.Serializable

public class R3
extends java.lang.Object
implements java.io.Serializable

Represents an element of R^3, the three-dimensional cartesian real space.

See Also:
Serialized Form

Field Summary
 double x1
          first coordinate
 double x2
          second coordinate
 double x3
          third coordinate
 
Constructor Summary
R3()
          Creates a new instance of R3, the zero element.
R3(double[] arrVals)
          Creates a new instance of R3 initialized to argument.
R3(double x1, double x2, double x3)
          Creates a new instance of R3 initialized to arguments.
R3(R3 vecPt)
          Creates a new instance of R3 initialized to argument.
R3(java.lang.String strTokens)
          Create a new instance of R3 with specified initial value specified by the formatted string argument.
 
Method Summary
 R3 cartesian2Cylindrical()
          Apply coordinate transform from cartesian to cylindrical coordinates.
 R3 cartesian2Spherical()
          Apply coordinate transform from cartesian to spherical coordinates.
 R3 copy()
          Performs a deep copy operation.
 R3 cylindrical2Cartesian()
          Apply coordinate transform from cylindrical to cartesian coordinates
 double get1()
          Return first coordinate value.
 double get2()
          Return second coordinate value.
 double get3()
          Return third coordinate value.
 double getx()
          Return first coordinate value.
 double gety()
          Return second coordinate value.
 double getz()
          Return third coordinate value.
 R3 minus(R3 r)
          Vector subtraction.
 double norm2()
          Compute the l2 norm of the vector in R3.
static R3 parse(java.lang.String strTokens)
          Create a new instance of R3 with initial value determined by the formatted string argument.
 R3 plus(R3 r)
          Vector addition.
 void print(java.io.PrintWriter os)
          Print out centents on an output stream.
 void println(java.io.PrintWriter os)
          Print out centents on an output stream, terminate with new line character.
 void set(double s)
          Set all coordinates to value
 void set(int i, double val)
          Set index to value.
 void set1(double x1)
          Set first coordinate value.
 void set2(double x2)
          Set second coordinate value.
 void set3(double x3)
          Set third coordinate value.
 void setx(double x)
          Set first coordinate value.
 void sety(double y)
          Set second coordinate value.
 void setz(double z)
          Set third coordinate value.
 R3 spherical2Cartesian()
          Apply coordinate tranform from spherical to cartesian coordinates
 R3 times(double s)
          Scalar multiplication.
 R3 times(R3 r)
          Vector multiplication using three-dimensional cross product.
 java.lang.String toString()
          Convert the vector contents to a string.
static R3 zero()
          Create a new instance of the zero vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x1

public double x1
first coordinate


x2

public double x2
second coordinate


x3

public double x3
third coordinate

Constructor Detail

R3

public R3()
Creates a new instance of R3, the zero element.


R3

public R3(double x1,
          double x2,
          double x3)
Creates a new instance of R3 initialized to arguments.

Parameters:
x1 - first coordinate value
x2 - first coordinate value
x3 - first coordinate value

R3

public R3(double[] arrVals)
Creates a new instance of R3 initialized to argument. If the initializing array has length greater than 3 the first three values are taken, if it has length less than three then the remain coordinates of the new R3 object are zero.

Parameters:
arrVals - double array of initializing values

R3

public R3(R3 vecPt)
Creates a new instance of R3 initialized to argument.

Parameters:
vecPt - deep copies this value

R3

public R3(java.lang.String strTokens)
   throws java.lang.NumberFormatException,
          java.lang.IllegalArgumentException
Create a new instance of R3 with specified initial value specified by the formatted string argument. The string should be formatted as "(x,y,z)" where x, y, z are floating point representations.

Parameters:
strTokens - token string representing values phase coordinates
Throws:
java.lang.IllegalArgumentException - wrong number of tokens in argument (must be 6 or 7)
java.lang.NumberFormatException - bad numeric value, unparseable
Method Detail

zero

public static R3 zero()
Create a new instance of the zero vector.

Returns:
zero vector

parse

public static R3 parse(java.lang.String strTokens)
                throws java.lang.NumberFormatException,
                       java.lang.IllegalArgumentException
Create a new instance of R3 with initial value determined by the formatted string argument. The string should be formatted as "(x,y,z)" where x, y, z are floating point representations.

Parameters:
strTokens - six-token string representing values phase coordinates
Throws:
java.lang.IllegalArgumentException - wrong number of tokens in argument (must be 6)
java.lang.NumberFormatException - bad numeric value, unparseable

copy

public R3 copy()
Performs a deep copy operation.

Returns:
cloned R3 object

set

public void set(int i,
                double val)
         throws java.lang.ArrayIndexOutOfBoundsException
Set index to value.

Parameters:
i - element index 0<=i<=2
val - new element value
java.lang.ArrayIndexOutOfBoundsException

set1

public void set1(double x1)
Set first coordinate value.


set2

public void set2(double x2)
Set second coordinate value.


set3

public void set3(double x3)
Set third coordinate value.


setx

public void setx(double x)
Set first coordinate value.


sety

public void sety(double y)
Set second coordinate value.


setz

public void setz(double z)
Set third coordinate value.


set

public void set(double s)
Set all coordinates to value


get1

public double get1()
Return first coordinate value.


get2

public double get2()
Return second coordinate value.


get3

public double get3()
Return third coordinate value.


getx

public double getx()
Return first coordinate value.


gety

public double gety()
Return second coordinate value.


getz

public double getz()
Return third coordinate value.


toString

public java.lang.String toString()
Convert the vector contents to a string.

Overrides:
toString in class java.lang.Object
Returns:
vector value as a string (v0, v1, ..., v5)

cartesian2Cylindrical

public R3 cartesian2Cylindrical()
Apply coordinate transform from cartesian to cylindrical coordinates.

Returns:
polar coordinates (r,phi,z) of this cartesian point

cartesian2Spherical

public R3 cartesian2Spherical()
Apply coordinate transform from cartesian to spherical coordinates.

Returns:
polar coordinates (R, theta, phi) of this cartesian point

cylindrical2Cartesian

public R3 cylindrical2Cartesian()
Apply coordinate transform from cylindrical to cartesian coordinates

Returns:
cartesian coordinates (x,y,z) of this cylindrical point

spherical2Cartesian

public R3 spherical2Cartesian()
Apply coordinate tranform from spherical to cartesian coordinates

Returns:
cartesian coordinates (x,y,z) of this sphereical point

times

public R3 times(double s)
Scalar multiplication.

Parameters:
s - scalar to multiply this vector
Returns:
new R3 object scaled by s

plus

public R3 plus(R3 r)
Vector addition.

Parameters:
r - vector displacement
Returns:
new R3 object equal to this displaced by r

minus

public R3 minus(R3 r)
Vector subtraction.

Parameters:
r - vector displacement
Returns:
new R3 object equal to this displaced by r

times

public R3 times(R3 r)
Vector multiplication using three-dimensional cross product.

Parameters:
r - second (right) operand in cross-product (this is first operand)
Returns:
result of vector cross product in three space

norm2

public double norm2()
Compute the l2 norm of the vector in R3.

Returns:
l2 norm = (x1^2 + x2^2 + x2^2)^1/2

print

public void print(java.io.PrintWriter os)
Print out centents on an output stream.

Parameters:
os - output stream receive content dump

println

public void println(java.io.PrintWriter os)
Print out centents on an output stream, terminate with new line character.

Parameters:
os - output stream receive content dump