private void AlignDynamic()
        {
            double equAngleFactor = 1;

            for (int i = 0; i < precesions_.iterCnt_; ++i)
            {
                Vect3 star1horz_corrected = new Rotation3((stars_[1].EquAngle - stars_[0].EquAngle) * equAngleFactor, equAxis_).Apply(stars_[1].Horz);
                Vect3 star3horz_corrected = new Rotation3((stars_[3].EquAngle - stars_[2].EquAngle) * equAngleFactor, equAxis_).Apply(stars_[3].Horz);

                double    altOffset0;
                Rotation3 rotationToStand0;
                double    quality0;
                TwoStarsAlignment.Align(stars_[0].Horz, stars_[0].Scope, star1horz_corrected, stars_[1].Scope, precesions_, out altOffset0, out rotationToStand0, out quality0);

                double    altOffset1;
                Rotation3 rotationToStand1;
                double    quality1;
                TwoStarsAlignment.Align(stars_[2].Horz, stars_[2].Scope, star3horz_corrected, stars_[3].Scope, precesions_, out altOffset1, out rotationToStand1, out quality1);

                Rotation3 eqRotation = rotationToStand0.Conj * rotationToStand1;    // actual equatorial rotation
                Vect3     equAxisNew = eqRotation.Axis;
                double    diff       = Vect3.VMul(equAxis_, equAxisNew).Abs;
                equAxis_ = equAxisNew;
                if (diff < precesions_.iterEquAxisDiff_)
                {
                    equHorzDiff_     = eqRotation.Angle;                            // Generally, it isn't equal to equScopeDiff_. It depends on platform accuracy.
                    rotationToStand_ = rotationToStand0;
                    altOffset_       = (altOffset0 + altOffset1) / 2;               // average offset
                    quality_         = (quality0 > quality1) ? quality0 : quality1; // maximal quality
                    iterationCnt_    = i + 1;
                    return;
                }
                equAngleFactor = eqRotation.Angle / equScopeDiff_;
            }
            throw new ApplicationException("too many iterations");
        }
示例#2
0
        public static void Align(Vect3 horz0, PairA scope0, Vect3 horz1, PairA scope1, Precisions precesions,
                                 out double altOffset, out Rotation3 rotationToStand, out double quality)
        {
            altOffset = CalcAltOffset(horz0, scope0, horz1, scope1);
            Vect3 s0 = new Vect3(scope0.Offset(0, -altOffset));
            Vect3 s1 = new Vect3(scope1.Offset(0, -altOffset));

            double abs;

            Vect3 n0 = horz0 - s0;

            abs = n0.Abs;
            if (abs < precesions.rotation_)
            {
                double angle = CalcRotationAngle(s0, horz1, s1);
                if (angle == 0 || angle == Math.PI)
                {
                    throw new ApplicationException("Error7");
                }

                quality         = -1;
                rotationToStand = new Rotation3(angle, s0);
                return;
            }
            n0 /= abs;

            Vect3 n1 = horz1 - s1;

            abs = n1.Abs;
            if (abs < precesions.rotation_)
            {
                double angle = CalcRotationAngle(s1, horz0, s0);
                if (angle == 0 || angle == Math.PI)
                {
                    throw new ApplicationException("Error8");
                }

                quality         = -2;
                rotationToStand = new Rotation3(angle, s1);
                return;
            }
            n1 /= abs;

            // axis
            Vect3 axis = Vect3.VMul(n0, n1);

            abs = axis.Abs;
            if (abs < precesions.axis_)
            {
                throw new ApplicationException("Error4");
            }
            axis /= abs;

            double angle0 = CalcRotationAngle(axis, horz0, s0);

            if (angle0 == 0 || angle0 == Math.PI)
            {
                throw new ApplicationException("Error5");
            }

            double angle1 = CalcRotationAngle(axis, horz1, s1);

            if (angle1 == 0 || angle1 == Math.PI)
            {
                throw new ApplicationException("Error6");
            }

            quality         = Math.Abs(angle0 - angle1);
            rotationToStand = new Rotation3((angle0 + angle1) / 2, axis);
        }
示例#3
0
        private static double CalcRotationAngle(Vect3 n, Vect3 a0, Vect3 a1)
        {
            double an = Vect3.SMul(a0, n);

            return(Math.Atan2(Vect3.SMul(n, Vect3.VMul(a0, a1)), Vect3.SMul(a0, a1) - an * an));
        }