| 1 | #!/usr/bin/perl
|
|---|
| 2 |
|
|---|
| 3 | use Math::Trig;
|
|---|
| 4 |
|
|---|
| 5 | $alpha = pi/4; # RA of point of interest
|
|---|
| 6 | $delta = pi/4; # Dec of point of interest
|
|---|
| 7 | print "alpha,delta: $alpha $delta\n";
|
|---|
| 8 |
|
|---|
| 9 | $alphaP = 0; # RA of tangent point
|
|---|
| 10 | $deltaP = 0; # Dec of tangent point
|
|---|
| 11 |
|
|---|
| 12 | # Rotate to appropriate system
|
|---|
| 13 | $theta = asin(sin($delta)*sin($deltaP) + cos($delta)*cos($deltaP)*cos($alpha-$alphaP));
|
|---|
| 14 | $phi = atan2(-cos($delta)*sin($alpha-$alphaP), sin($delta)*cos($deltaP) - cos($delta)*sin($deltaP)*cos($alpha-$alphaP));
|
|---|
| 15 | print "phi,theta: $phi $theta\n";
|
|---|
| 16 |
|
|---|
| 17 | # Projection
|
|---|
| 18 | $x = cos($theta) * sin($phi) / sin($theta);
|
|---|
| 19 | $y = - cos($theta) * cos($phi) / sin($theta);
|
|---|
| 20 | print "x,y: $x $y\n";
|
|---|
| 21 |
|
|---|
| 22 | # Inverse
|
|---|
| 23 | $R = sqrt($x**2 + $y**2);
|
|---|
| 24 | $squiggle = 1/$R;
|
|---|
| 25 | $phiNew = atan2(-$x,$y);
|
|---|
| 26 | $thetaNew = atan2($squiggle, 1);
|
|---|
| 27 | print "phi,theta: $phiNew $thetaNew\n";
|
|---|
| 28 |
|
|---|
| 29 | # Rotate back to sky
|
|---|
| 30 | $deltaNew = asin(sin($theta)*sin($deltaP) + cos($theta)*cos($deltaP)*cos($phi));
|
|---|
| 31 | $alphaNew = $alphaP + atan2(-cos($theta)*sin($phi), sin($theta)*cos($deltaP) - cos($theta)*sin($deltaP)*cos($phi));
|
|---|
| 32 | print "alpha,delta: $alphaNew $deltaNew\n";
|
|---|