## cds.astro Class Coo

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

`public class Cooextends java.lang.Objectimplements 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) {
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.

Serialized Form

Field Summary
`static int` `decimals`
Number of decimals edited in the default toString method.
`static Editing` `ed`
The edition of Coordinates
`protected  double` `lat`
Latitude in degrees, range [-90, +90]
`protected  double` `lon`
Longitude in degrees, range [0, 360[
`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(Coo coo)`
Define a coordinate from another one (clone).
```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)`
`static double` ```add(double[] u, double[] du)```
` double` ```angle(Coo pos1, Coo pos2)```
Angle with 2 directions.
` 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` `dist2(Coo pos)`
Squared distance between 2 points (= 4.sin2(r/2))
` double` `dist2(double[] u)`
Squared distance between point and a vector
`static double` ```dist2(double[] u, double[] v)```
Squared distance between 2 vectors
` 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.
` double` ```distc(Coo pos1, Coo pos2)```
Distance between a point and a circle (defined by 2 coordinates).
` double` `dotprod(Coo pos)`
Compute the dot-product (scalar product)
` double` `dotprod(double[] v)`
Compute the dot-product (scalar product)
`static double` ```dotprod(double[] v1, double[] v2)```
Compute the dot-product (scalar product)
` 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.
`static double` `norm2(double[] v1)`
Compute the square norm of a vector
` 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.
`static Coo` ```perpendicular(Coo pos1, Coo pos2)```
Define a coordinate as the direct perpendicular to 2 positions.
` double` `posAngle(Coo pos)`
Position angle (wrt North) of point (range 0-180).
` 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.
`protected static java.lang.String` `toString(double[] u)`
Edition of the 3 components of a vector.
`protected static java.lang.String` ```toString(java.lang.String title, double[] u)```
Edition of the 3 components of a vector.
`protected static java.lang.String` ```toString(java.lang.String title, double[][] m)```
Edition of a 3x3 matrix
` void` ```vecprod(Coo pos, double[] r)```
Compute the vectorial product (result in vector r)
` void` ```vecprod(double[] v, double[] r)```
Compute the vectorial product (result in vector r)
`static void` ```vecprod(double[] v1, double[] v2, double[] r)```
Compute the vectorial product (result in vector r)

Methods inherited from class java.lang.Object
`finalize, 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)

### lon

`protected double lon`
Longitude in degrees, range [0, 360[

### lat

`protected double lat`
Latitude in degrees, range [-90, +90]

### 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(Coo coo)`
Define a coordinate from another one (clone). It is faster than the creation from the angles or vector because there is no conversion between angles and vectors.

Parameters:
`coo` - the coordinates to clone.

### 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)

### perpendicular

```public static Coo perpendicular(Coo pos1,
Coo pos2)```
Define a coordinate as the direct perpendicular to 2 positions. Is normalized vectorial product.

Parameters:
`pos1` - first position
`pos2` - second position
Returns:
coordinate directly perpendicular pos1{perp}pos2

### 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 {deg}'" 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 {deg}'" 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]

### dist2

`public final double dist2(Coo pos)`
Squared distance between 2 points (= 4.sin2(r/2))

Parameters:
`pos` - another position on the sphere
Returns:
||pos-this||2 = 4.sin2(r/2)

### dist2

`public final double dist2(double[] u)`
Squared distance between point and a vector

Parameters:
`u` - a 3-vector
Returns:
||u-this||2

### dist2

```public static final double dist2(double[] u,
double[] v)```
Squared distance between 2 vectors

Parameters:
`u` - a 3-vector
`v` - a 3-vector
Returns:
||u-v||2

### 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]

### distc

```public final double distc(Coo pos1,
Coo pos2)```
Distance between a point and a circle (defined by 2 coordinates).

Parameters:
`pos1` - First point defining the circle
`pos2` - Second point defining the circle
Returns:
distance to great circle (pos1, pos2). The distance is always between 0 and 90deg.

### angle

```public final double angle(Coo pos1,
Coo pos2)```
Angle with 2 directions.

Parameters:
`pos1` - First point A
`pos2` - Second point B
Returns:
angle (in degrees) AOB The distance is between 0 and 180deg.

### posAngle

`public final double posAngle(Coo pos)`
Position angle (wrt North) of point (range 0-180). Identical to angle(North, pos)

Parameters:
`pos` - Point
Returns:
position angle (in degrees) of pos.

### dotprod

```public static final double dotprod(double[] v1,
double[] v2)```
Compute the dot-product (scalar product)

Parameters:
`v1` - first vector
`v2` - second vector
Returns:
the dot-product

### dotprod

`public final double dotprod(double[] v)`
Compute the dot-product (scalar product)

Parameters:
`v` - second vector
Returns:
the dot-product = (this) . v

### dotprod

`public final double dotprod(Coo pos)`
Compute the dot-product (scalar product)

Parameters:
`pos` - second vector
Returns:
the dot-product = (this) . v

### norm2

`public static final double norm2(double[] v1)`
Compute the square norm of a vector

Parameters:
`v1` - the vector
Returns:
the squared norm

### vecprod

```public static final void vecprod(double[] v1,
double[] v2,
double[] r)```
Compute the vectorial product (result in vector r)

Parameters:
`v1` - first vector
`v2` - second vector
`r` - the returned resulting vector

### vecprod

```public final void vecprod(double[] v,
double[] r)```
Compute the vectorial product (result in vector r)

Parameters:
`v` - second vector
`r` - the returned resulting vector r = this ^ v

### vecprod

```public final void vecprod(Coo pos,
double[] r)```
Compute the vectorial product (result in vector r)

Parameters:
`pos` - second vector
`r` - the returned resulting vector r = this ^ v

### 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:
• R[0] (first axis) = unit vector towards Zenith
• R[1] (second axis) = unit vector towards East
• R[2] (third axis) = unit vector towards North
```  +-                             -+   +-                  -+
| 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

```public static final double add(double[] u,
double[] du)```

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

`public final double add(double[] du)`

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

### toString

`protected static final java.lang.String toString(double[] u)`
Edition of the 3 components of a vector.

Parameters:
`u` - the 3-vector
Returns:
the equivalent string (edited vector)

### toString

```protected static final java.lang.String toString(java.lang.String title,
double[] u)```
Edition of the 3 components of a vector.

Parameters:
`title` - text prefixing each line.
`u` - the 3-vector
Returns:
the equivalent string (edited vector)

### toString

```protected static final java.lang.String toString(java.lang.String title,
double[][] m)```
Edition of a 3x3 matrix

Parameters:
`title` - text prefixing each line of the matrix
`m` - the 3x3 matrix
Returns:
the equivalent string (edited matrix)

### dump

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

Parameters:
`title` - A title to precede the dump