cds.astro
Class Coo

java.lang.Object
  extended by cds.astro.Coo
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Astrocoo, Coocube

public class Coo
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Class that manipulates the coordinates defining a point on the celestial sphere. The class includes conversions between polar angles (lon,lat) expressed in degrees, and Cartesian 3-vectors. The typical way of converting between polar and cartesian is:

 Coo aCoo = new Coo ; double u[] = new double[3] ;
 while (true) {
     aCoo.set(stdin.readLine()) ;
     System.out.println("Coordonnees   : " + aCoo) ;
     u[0] = aCoo.x; u[1] = aCoo.y; u[2] = aCoo.z;
     System.out.println("Cos. directeurs: " + Coo.toString(u)) ;
 }
 
This class also deals with 3x3 matrices.

Version:
1.0 : 03-Mar-2000
, 1.1 : 24-Mar-2000: Bug in dist
, 1.2 : 17-Apr-2002: Accept decimal degrees in scientific notation
, 1.3 : 17-Sep-2002: Method "dist" between 2 coordinates
, 1.4 : 21-Jan 2004 (BB): ajout de la methode equals.
, 1.5 : 12-Aug 2004: methods rotate rotate_1 dlon and dlat moved to Astrocoo, 1.6 : 24-Apr-2006: methods moveMatrix, 1.7 : 04-Jun-2006: methods add sub, 1.8 : 02-Feb-2007: editingDecimals
Author:
Pierre Fernique, Francois Ochsenbein [CDS]
See Also:
Serialized Form

Field Summary
static int decimals
          Number of decimals edited in the default toString method.
static Editing ed
          The edition of Coordinates
static double[][] Umatrix3
          The unit 3-D unit matrix .
 double x
          Components of unit vector (direction cosines)
 double y
          Components of unit vector (direction cosines)
 double z
          Components of unit vector (direction cosines)
 
Constructor Summary
Coo()
          The basic contructor: undefined position
Coo(double lon, double lat)
          Define a coordinate from its angles
Coo(double x, double y, double z)
          Define a coordinate from its direction cosines.
Coo(java.lang.String text)
          Define a coordinate from a string
 
Method Summary
 double add(double[] du)
          Addition of a vector (addition, then normalisation)
static double add(double[] u, double[] du)
          Addition of a vector (addition, then normalisation)
 java.lang.Object clone()
          Clone the Coo object
 void copyAngles(double[] o)
          Get the spherical angles (lon, lat) as a 2-vector
 void copyUvector(double[] u)
          Get the unit vector (x, y, z) as a 3-vector
 double distance(Coo pos)
          Distance between 2 points on the sphere.
static double distance(double lon1, double lat1, double lon2, double lat2)
          Distance between 2 points on the sphere.
 void dump(java.lang.String title)
          Dump the contents of a Coordinate
 java.lang.StringBuffer edit(java.lang.StringBuffer b, int nd)
          Default Edition of the Coordinates, as 2 numbers expressing the angles in degrees.
 java.lang.StringBuffer editCoo(java.lang.StringBuffer b, int nd)
          Edition of the Coordinates with specified number of decimals.
 boolean equals(java.lang.Object o)
          Test equality of Coo.
static double[][] eulerMatrix(double z, double theta, double zeta)
          Generate the rotation matrix from the Euler angles
 double getLat()
          Get the Latitude (Dec) in degrees.
 double getLon()
          Get the Longitude (RA) in degrees.
 double[][] localMatrix()
          Compute the rotation matrix associated to current position.
 void localMatrix(double[][] R)
          Compute the rotation matrix associated to current position.
static double[][] localMatrix(double lon, double lat)
          Compute the rotation matrix that transforms a direction into the local frame.
 double[][] moveMatrix(Coo coo2)
          Compute the rotation matrix to move between 2 directions.
 double normalize()
          Normalisation of coordinates (set its norm to 1)
static double normalize(double[] u)
          Normalisation of a vector (set its norm to 1)
 int parse(java.lang.String text, int offset)
          Interpret the string and convert to Coo.
 boolean parsing(Parsing acoo)
          Interpret the string and convert to Coo.
 void rotate_1(double[][] R)
          Rotate a coordinate (apply a rotation to the position) in reverse direction.
 void rotate(double[][] R)
          Rotate a coordinate (apply a rotation to the position).
static void rotateVector_1(double[][] R, double[] v)
          Reversely rotate a vector.
static void rotateVector(double[][] R, double[] v)
          Rotate a vector.
 void set()
          Sets the position to its default (unknown)
 void set(Coo coo)
          Set the position from an existing one.
 void set(double lon, double lat)
          Set a position from its longitude and latitude (RA/Dec).
 void set(double x, double y, double z)
          Set a position from its unit vectors.
 void set(java.lang.String text)
          Define a non-equatorial coordinate from its text (RA is in degrees)
static int setDecimals(int nd)
          Set (and get) the number of decimals for the default edition of the cordinates.
static void setUvec(double lon, double lat, double[] u)
          Compute the unit vector from angles in degrees.
 double sub(double[] du)
          Subtraction of a vector (subtravtion, then normalisation)
static double sub(double[] u, double[] du)
          Subtraction of a vector (subtravtion, then normalisation)
 java.lang.String toString()
          Default Edition of the Coordinates, as 2 numbers expressing the angles in degrees.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public double x
Components of unit vector (direction cosines)


y

public double y
Components of unit vector (direction cosines)


z

public double z
Components of unit vector (direction cosines)


ed

public static Editing ed
The edition of Coordinates


decimals

public static int decimals
Number of decimals edited in the default toString method. Can be changed with the setDecimals() method.


Umatrix3

public static double[][] Umatrix3
The unit 3-D unit matrix .

Constructor Detail

Coo

public Coo()
The basic contructor: undefined position


Coo

public Coo(double lon,
           double lat)
Define a coordinate from its angles

Parameters:
lon - longitude angle in degrees
lat - latitude angle in degrees

Coo

public Coo(double x,
           double y,
           double z)
Define a coordinate from its direction cosines. (Note that (x,y,z) doesn't need to have a norm=1)

Parameters:
x - x item in unit vector (direction cosines)
y - y item in unit vector (direction cosines)
z - z item in unit vector (direction cosines)

Coo

public Coo(java.lang.String text)
    throws java.text.ParseException
Define a coordinate from a string

Parameters:
text - a position as a string
Throws:
java.text.ParseException - when the string is not interpretable
Method Detail

clone

public java.lang.Object clone()
Clone the Coo object

Overrides:
clone in class java.lang.Object

set

public void set()
Sets the position to its default (unknown)


set

public void set(Coo coo)
Set the position from an existing one. It is faster than the set methods from angles or vector components because there is no conversion.

Parameters:
coo - the coordinates

setUvec

public static final void setUvec(double lon,
                                 double lat,
                                 double[] u)
Compute the unit vector from angles in degrees.

Parameters:
lon - longitude in degrees
lat - latitude angle in degrees
u - resulting unit vector

set

public void set(double lon,
                double lat)
Set a position from its longitude and latitude (RA/Dec). Convert (lon,lat) into its direction cosines (x,y,z)

Parameters:
lon - longitude in degrees
lat - latitude angle in degrees

set

public void set(double x,
                double y,
                double z)
Set a position from its unit vectors. Revert conversion of (x,y,z) into (lon,lat).
(Note that (x,y,z) is assxumed to have a norm=1)

Parameters:
x - x item in unit vector (direction cosines)
y - y item in unit vector (direction cosines)
z - z item in unit vector (direction cosines)

parsing

public boolean parsing(Parsing acoo)
Interpret the string and convert to Coo. Called from set(...) and parse(...) methods

Parameters:
acoo - a text ready for parsing (may contain the hms or °'" characters)
Returns:
true if OK.

parse

public int parse(java.lang.String text,
                 int offset)
Interpret the string and convert to Coo.

Parameters:
text - a text containing 2 angles, in decimal or Sexagesimal (may contain the hms or °'" characters)
offset - where to start the analysis
Returns:
new position in text after interpretation.

set

public void set(java.lang.String text)
         throws java.text.ParseException
Define a non-equatorial coordinate from its text (RA is in degrees)

Parameters:
text - a text containing 2 angles, in decimal or Sexagesimal
Throws:
java.text.ParseException - when the string is not interpretable

getLon

public double getLon()
Get the Longitude (RA) in degrees.

Returns:
the longitude (RA) in degrees

getLat

public double getLat()
Get the Latitude (Dec) in degrees.

Returns:
the latitude (Dec) in degrees

copyAngles

public void copyAngles(double[] o)
Get the spherical angles (lon, lat) as a 2-vector


copyUvector

public void copyUvector(double[] u)
Get the unit vector (x, y, z) as a 3-vector


distance

public static final double distance(double lon1,
                                    double lat1,
                                    double lon2,
                                    double lat2)
Distance between 2 points on the sphere.

Parameters:
lon1 - longitude of first point in degrees
lat1 - latitude of first point in degrees
lon2 - longitude of second point in degrees
lat2 - latitude of second point in degrees
Returns:
distance in degrees in range [0, 180]

distance

public final double distance(Coo pos)
Distance between 2 points on the sphere.

Parameters:
pos - another position on the sphere
Returns:
distance in degrees in range [0, 180]

rotateVector

public static final void rotateVector(double[][] R,
                                      double[] v)
Rotate a vector. The vector v becomes R . v

Parameters:
R - [3][3] Rotation Matrix
v - Vector to rotate, may be of dimension 3 or 6.

rotateVector_1

public static final void rotateVector_1(double[][] R,
                                        double[] v)
Reversely rotate a vector. The vector v becomes R-1 . v

Parameters:
R - [3][3] Rotation Matrix
v - Vector to rotate, may be of dimension 3 or 6.

rotate

public void rotate(double[][] R)
Rotate a coordinate (apply a rotation to the position).

Parameters:
R - [3][3] Rotation Matrix

rotate_1

public void rotate_1(double[][] R)
Rotate a coordinate (apply a rotation to the position) in reverse direction. The method is the inverse of rotate.

Parameters:
R - [3][3] Rotation Matrix

eulerMatrix

public static double[][] eulerMatrix(double z,
                                     double theta,
                                     double zeta)
Generate the rotation matrix from the Euler angles

Parameters:
z - Euler angle
theta - Euler angle
zeta - Euler angles
Returns:
R [3][3] the rotation matrix The rotation matrix is defined by:
    R =      R_z(-z)      ·        R_y(theta)     ·     R_z(-zeta)
             |cos.z -sin.z  0|   |cos.the  0 -sin.the|   |cos.zet -sin.zet 0|
           = |sin.z  cos.z  0| x |   0     1     0   | x |sin.zet  cos.zet 0|
             |   0      0   1|   |sin.the  0  cos.the|   |   0        0    1|
 

localMatrix

public static final double[][] localMatrix(double lon,
                                           double lat)
Compute the rotation matrix that transforms a direction into the local frame. The axises of the local frame are defined by:
  +-                             -+   +-                  -+
  | cosb.cosl   cosb.sinl    sinb |   |  x        y      z |
  |  -sinl        cosl        0   | = | (-y/r)   (x/r)   0 |
  |-sinb.cosl  -sinb.sinl    cosb |   |-z(x/r)  z(-y/r)  r |
  +-                             -+   +-                  -+
  
r = sqrt(x*x+y*y) ; if r==0,take (x/r)=1, (y/r)=0

Parameters:
lon - longitude of the center of local frame
lat - latitude of the center of local frame
Returns:
R[3][3] = Rotation Matrix [(x,y,z)_local = R * (x,y,z)_global]. With the result matrix, rotate(R) converts the position to (0,0).

localMatrix

public final void localMatrix(double[][] R)
Compute the rotation matrix associated to current position. Simple mathematics R[0][i] = I (x y z) R[1][i] = J (u v 0) R[2][i] = K (u v 0)

Parameters:
R - = Rotation Matrix[3][3] to transform the current position into (0,0)

localMatrix

public final double[][] localMatrix()
Compute the rotation matrix associated to current position.

Returns:
R[3][3] = Rotation Matrix to transform the current position into (0,0)

moveMatrix

public final double[][] moveMatrix(Coo coo2)
Compute the rotation matrix to move between 2 directions. This matrix is coo.localMatrix · t(this.localMatrix)

Parameters:
coo2 - target direction.
Returns:
R[3][3] = Rotation Matrix to transform the current position into the position given in argument

normalize

public static final double normalize(double[] u)
Normalisation of a vector (set its norm to 1)

Parameters:
u - 3- or 6-Vector to normalize
Returns:
the norm of the 3-D vector

normalize

public double normalize()
Normalisation of coordinates (set its norm to 1)

Returns:
the norm of the 3-D vector

add

public static final double add(double[] u,
                               double[] du)
Addition of a vector (addition, then normalisation)

Parameters:
u - 3- or 6-Vector to modify
du - 3-Vector to add
Returns:
the norm of the 3-D vector

sub

public static final double sub(double[] u,
                               double[] du)
Subtraction of a vector (subtravtion, then normalisation)

Parameters:
u - 3- or 6-Vector to modify
du - 3-Vector to subtract
Returns:
the norm of the 3-D vector

add

public final double add(double[] du)
Addition of a vector (addition, then normalisation)

Parameters:
du - 3-Vector to add
Returns:
the norm of the 3-D vector

sub

public final double sub(double[] du)
Subtraction of a vector (subtravtion, then normalisation)

Parameters:
du - 3-Vector to subtract
Returns:
the norm of the 3-D vector

equals

public boolean equals(java.lang.Object o)
Test equality of Coo.

Overrides:
equals in class java.lang.Object
Parameters:
o - Object to compare
Returns:
True if o is identical to Coo.

editCoo

public final java.lang.StringBuffer editCoo(java.lang.StringBuffer b,
                                            int nd)
Edition of the Coordinates with specified number of decimals.

Parameters:
b - the StringBuffer for edition
nd - the number of decimals in the edition of each coordinate. Possible to use a negative nd to minimize the length.
Returns:
the StringBuffer

edit

public java.lang.StringBuffer edit(java.lang.StringBuffer b,
                                   int nd)
Default Edition of the Coordinates, as 2 numbers expressing the angles in degrees.

Parameters:
b - the StringBuffer for edition
nd - the number of decimals in the edition of each coordinate. Possible to use a negative nd to minimize the length.
Returns:
the StringBuffer

setDecimals

public static int setDecimals(int nd)
Set (and get) the number of decimals for the default edition of the cordinates.

Parameters:
nd - the number of decimals in the edition of each coordinate. Possible to use a negative nd to minimize the length.
Returns:
the previous deifnition.

toString

public java.lang.String toString()
Default Edition of the Coordinates, as 2 numbers expressing the angles in degrees.

Overrides:
toString in class java.lang.Object
Returns:
The edited coordinates

dump

public void dump(java.lang.String title)
Dump the contents of a Coordinate

Parameters:
title - A title to precede the dump


Copyright © 2009 UDS/CNRS