source: trunk/MagicSoft/slalib/tpv2c.c@ 765

Last change on this file since 765 was 732, checked in by tbretz, 23 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#include "slalib.h"
2#include "slamac.h"
3void slaTpv2c ( float xi, float eta, float v[3], float v01[3],
4 float v02[3], int *n )
5/*
6** - - - - - - - - -
7** s l a T p v 2 c
8** - - - - - - - - -
9**
10** Given the tangent-plane coordinates of a star and its direction
11** cosines, determine the direction cosines of the tangent-point.
12**
13** (single precision)
14**
15** Given:
16** xi,eta float tangent plane coordinates of star
17** v float[3] direction cosines of star
18**
19** Returned:
20** v01 float[3] direction cosines of TP, solution 1
21** v02 float[3] direction cosines of TP, solution 2
22** *n int number of solutions:
23** 0 = no solutions returned (note 2)
24** 1 = only the first solution is useful (note 3)
25** 2 = both solutions are useful (note 3)
26**
27** Notes:
28**
29** 1 The vector v must be of unit length or the result will be wrong.
30**
31** 2 Cases where there is no solution can only arise near the poles.
32** For example, it is clearly impossible for a star at the pole
33** itself to have a non-zero xi value, and hence it is meaningless
34** to ask where the tangent point would have to be.
35**
36** 3 Also near the poles, cases can arise where there are two useful
37** solutions. The argument n indicates whether the second of the
38** two solutions returned is useful; n=1 indicates only one useful
39** solution, the usual case. Under these circumstances, the second
40** solution can be regarded as valid if the vector v02 is interpreted
41** as the "over-the-pole" case.
42**
43** 4 This routine is the Cartesian equivalent of the routine slaTps2c.
44**
45** Last revision: 5 June 1995
46**
47** Copyright P.T.Wallace. All rights reserved.
48*/
49{
50 float x, y, z, rxy2, xi2, eta2p1, sdf, r2, r, c;
51
52
53 x = v[0];
54 y = v[1];
55 z = v[2];
56 rxy2 = x * x + y * y;
57 xi2 = xi * xi;
58 eta2p1 = eta*eta + 1.0f;
59 sdf = z * (float) sqrt ( (double) ( xi2 + eta2p1 ) );
60 r2 = rxy2 * eta2p1 - z * z * xi2;
61 if ( r2 > 0.0f ) {
62 r = (float) sqrt( (double) r2 );
63 c = ( sdf * eta + r ) /
64 ( eta2p1 * (float) sqrt ( (double) ( rxy2 * ( r2 + xi2 ) ) ) );
65 v01[0] = c * ( x * r + y * xi );
66 v01[1] = c * ( y * r - x * xi );
67 v01[2] = ( sdf - eta * r ) / eta2p1;
68 r = - r;
69 c = ( sdf * eta + r ) /
70 ( eta2p1 * (float) sqrt ( (double) ( rxy2 * ( r2 + xi2 ) ) ) );
71 v02[0] = c * ( x * r + y * xi );
72 v02[1] = c * ( y * r - x * xi );
73 v02[2] = ( sdf - eta * r ) / eta2p1;
74 *n = ( fabs ( sdf ) < 1.0f ) ? 1 : 2;
75 } else {
76 *n = 0;
77 }
78}
Note: See TracBrowser for help on using the repository browser.