' This file is part of DomeSync.
'
' DomeSync is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 2 of the License, or
' (at your option) any later version.
'
' DomeSync is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with DomeSync; if not, write to the Free Software
' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'
' The following equations are based on the material presented at
' http://www.brayebrookobservatory.org/BrayObsWebSite/HOMEPAGE/BrayObs.html
' by Mr. Chris Lord using coordinate transformations by Toshimi Taki
'
Public Sub CalcDomeAzAlt(HA As Double, Dec As Double, _
phi As Double, _
Xdome0 As Double, Ydome0 As Double, Zdome0 As Double, _
rDecAxis As Double, Rdome As Double, _
dome_A As Double, dome_h As Double)
' all angles (HA,Dec,phi,dome_A, dome_h) are in radians
' distances (X/Y/Zdome0,rDecAxis,Rdome) must be in same units
' Xdome0 + to S, Ydome0 + to E, Zdome0 + to sky, rDecAxis + when tube W looking
E
' dome_A (azimuth) 0 N, increasing to E
Dim A As Double, B As Double, C As Double
Dim d As Double, E As Double, F As Double
Dim knum As Double, root As Double, k As Double
Dim Xdome As Double, Ydome As Double, Zdome As Double
Dim sin_h As Double
A = Xdome0 + rDecAxis * Cos(phi - PI / 2#) * Sin(HA - PI)
B = Ydome0 + rDecAxis * Cos(HA - PI) ' JPO original
C = Zdome0 - rDecAxis * Sin(phi - PI / 2#) * Sin(HA - PI)
d = Cos(phi - PI / 2#) * Cos(Dec) * Cos(-HA) + Sin(phi - PI / 2#) * Sin(Dec)
E = Cos(Dec) * Sin(-HA)
F = -Sin(phi - PI / 2#) * Cos(Dec) * Cos(-HA) + Cos(phi - PI / 2#) * Sin(Dec)
root = (A * d + B * E + C * F) ^ 2 + (d ^ 2 + E ^ 2 + F ^ 2) * (Rdome ^ 2 -
(A ^ 2 + B ^ 2 + C ^ 2))
frmDsync.lblRoot = root
knum = -(A * d + B * E + C * F) + Sqr(root)
k = knum / (d ^ 2 + E ^ 2 + F ^ 2)
frmDsync.lblk = k
Xdome = A + d * k
Xdome = -Xdome ' reversed X to get az=0 north
Ydome = B + E * k
Zdome = C + F * k
dome_A = -Atn2(Ydome, Xdome)
dome_A = -dome_A ' reversed Az sign to get az=0 north
If dome_A < 0 Then dome_A = 2 * PI + dome_A
sin_h = Zdome / Rdome
dome_h = Asin(sin_h)
End Sub