For successful automated astrophotography, the slot in the observatory dome must be synhronised with the telescope as it tracks the sky and performs slews. In most cases, use of ASCOM will mean that you do not have to worry about the calculation of the dome azimuth - this is all done for you after correct configuration. In some cases you may wish to implment your own code to perform this calculation. The problem is not as simple as it might first appear. One cannot simply set the dome slot azimuth to the pointing azimuth of the telescope. With a GEM mount the correct solution can appear unintuitive.

Take the following example:

Telescope pointing due south at the horizon. Scope on the east side of the pier. Putting the dome slit at
180 is not the correct solution. The scope is hanging out to one side. The required dome azimuth is more
like 160 degrees - depending on various factors.

The "factors" are broadly......

- First of all, introduce a COG, centre of gravity, of the mount, this is the intersection of the RA and DEC axis.
- Also define the "origin" of the dome. The dome is a hemisphere. The origin is the middle of the sphere.
- Immediately we notice the COG of the mount is never going to be at the origin of the dome unless your building is very well designed. There will be a fixed x,y,z offset. We will say that x = north+ and y = east+. Z is up/down
- Next the radius of the dome is a factor. In my case it is not a fixed radius.
- The optical axis of the telescope will not pass through this COG. There will be an Optical-COG offset. PRobably in the order of 100-300mm

Taking the above case, even with x=y=z=0 the COG-Optical (COGO) will mean the dome azimuth has to be a bit further east than 180. If x=y=z=COGO then the azimuth would be 180. This is now aparently a more complex problem but the solution is straightfoward using the proper mathematics.

**Be warned**
: Some of the solutions I have seen on the internet are horrendously over complicated and try and
do the whole thing with trigonometry.

With vectors, the solution is a joy.

- First we define c, the origin, centre of the dome. (0,0,0)
- Next we have the vector to the mount cog, this never changes. (x1,y1,z1).
- Now we need to find the intersection of the Dec-optical (DOI) relative to (x1,y1,z1), we call this (x2,y2,z2). This does move around. If we say r is the
COG-optical length, we imediately see that the DOI perscribes parts of a sphere around (x1,y1,z1) with
radius r. So we simply use the standard 3d polar to cartesian conversion from any geometry text book. Note
that the DOI point will not reach all parts of the sphere.

In our case, θ is hour angle and φ is latitude - all assuming we are on a polar aligned mount!

- We add (x1,y1,z1) to (x2,y2,z2) whic gives us a vector, o, which is the DOI point relative to the dome origin.
- Now we define unit vector , l, which is the direction the telescope is pointing. Here we can just use the alt and azimuth from the telescope.
- Now we have the components of a classic problem from the world of ray-tracing. Calculation of the
intersection of a line and a sphere.

- This gives d, the distance along the unit vector l where the line intersects the sphere.
- Then we simply add all the vectors together, (x3,y3,z3) = c + o + (l * d)
- Finally with a standard Cartesian to Polar conversion, Dome Azimuith = Π / 2 - Atan2(y2, x2);
- For changes to the mount sideofpier we simply negate (x2,y2,z2) before adding to (x1,y1,z1)
- In my case, the radius of my dome is not constant with elevation. It is more box shaped. However Acos(z / domeR ) gives the elevation of the intersection, and one can simply iterate the above algorithm for a different radius.

For practical programming, the Math.net programming library makes this into a few simple lines of code.

Sample C# code

` ````
public DomeAltAz Get(double domeR, double HourAngle, double pierside, double ALT, double AZ)
{
double inc = M_PI / 2 - ALT;
double az = M_PI / 2 - AZ;
//origin of dome, 0,0,0
var c = new DenseVector(new double[] { 0, 0, 0 });
//setup the intersection of RA And DEC axis which is constant.
var cog = new DenseVector(new double[] { offsetEW, offsetNS, offsetUP });
//now work out the cogo point, intersection of optical axis and dec axis, i.e. the bit that moves
var cogtoO = new DenseVector(new double[] {
pierside*r*cos(HourAngle), //x
pierside*-r*sin(latitude)*sin(HourAngle), //y
pierside*r*cos(latitude)*sin(HourAngle) //z
});
var o = cog + cogtoO;
double xm, ym, zm;
//3d cartesian coordinates or unit vector for the actual OTA pointing direction
xm = Math.Sin(inc) * Math.Cos(az);
ym = Math.Sin(inc) * Math.Sin(az);
zm = Math.Cos(inc);
var l = new DenseVector(new double[] { xm, ym, zm });
l = l.Normalize(2);
//do the actual equation
var underRoot = sqr(l.DotProduct(o - c))- sqr((o - c).Norm(2)) + sqr(domeR);
var d = -l.DotProduct(o - c) + Math.Sqrt(underRoot);
var s = c + o + (l * d);
var domealtaz = new DomeAltAz();
domealtaz.DomeAzimuth = M_PI / 2 - Math.Atan2(s[1], s[0]);
if (domealtaz.DomeAzimuth < 0) domealtaz.DomeAzimuth += 2 * M_PI;
domealtaz.DomeAltitude = M_PI / 2 - Math.Acos(s[2] / domeR);
domealtaz.cogtoO = cogtoO;
return domealtaz;
}
```