public static Facing ToFacing(this Angle heading, Vector relativePosition)
        {
            var azimuth         = Math.Atan2(relativePosition.Y, relativePosition.X);
            var relativeAzimuth = azimuth - heading.Value;

            relativeAzimuth = Angle.ReduceAngle(relativeAzimuth);

            Facing facing = Facing.None;

            // err on the side of gnerosity and consider all edge cases in both facings
            if (relativeAzimuth >= -PiOnFour && relativeAzimuth <= PiOnFour)
            {
                facing = facing | Facing.Bow;
            }
            if (relativeAzimuth <= -PiOnFour && relativeAzimuth >= -3 * PiOnFour)
            {
                facing = facing | Facing.Starboard;
            }
            if (relativeAzimuth >= PiOnFour && relativeAzimuth <= 3 * PiOnFour)
            {
                facing = facing | Facing.Port;
            }
            if (relativeAzimuth >= 3 * PiOnFour || relativeAzimuth <= -3 * PiOnFour)
            {
                facing = facing | Facing.Stern;
            }

            return(facing);
        }
Beispiel #2
0
        public void DetermineTurnEndWestAntiClockwise()
        {
            Vector turningCircle       = new Vector(2, 0);
            Vector destination         = new Vector(-3, 0);
            double turningCircleRadius = 2;

            Vector turnPointToDestinationOffset = destination - turningCircle;
            Angle  tangle        = new Angle(turnPointToDestinationOffset);
            Angle  cosangle      = new Angle(Math.Acos(2.0 / 5.0));
            Angle  expectedAngle = tangle - cosangle;

            expectedAngle.ReduceAngle();
            var path = new Path();


            Assert.AreEqual(expectedAngle, path.DetermineTurnEnd(turnPointToDestinationOffset, turningCircleRadius, TurnDirection.AntiClockwise));
        }
        /// <summary>
        /// Determines the positions of the two possible turning circles
        /// Relative to the initial position which is not passed into the function
        /// </summary>
        /// <param name="initialVelocity">The current velocity of the object</param>
        /// <param name="radius">The desired radius of the object</param>
        /// <param name="circleOne">The first of the two possible turning circles</param>
        /// <param name="circleTwo">The second of the two possible turning circles</param>
        public void DetermineTurningCircles(Vector initialVelocity, double radius, out Vector circleOne, out Vector circleTwo)
        {
            Angle velocityAngle;

            // calculate the angle of the current velocity
            velocityAngle = new Angle(initialVelocity);
            velocityAngle.ReduceAngle();

            //double vesselSpeed = initialVelocity.Length;
            // calculate the radius if the turning circle based on the acceleration and current speed
            //double radius = CalcRadius(vesselSpeed, acceleration);

            // calcualte both of the turning circles
            Angle angleOne = new Angle(velocityAngle.Value + (Math.PI / 2));

            circleOne = CoordinateConversions.RadialToVector(angleOne, radius);

            Angle angleTwo = new Angle(velocityAngle.Value - (Math.PI / 2));

            circleTwo = CoordinateConversions.RadialToVector(angleTwo, radius);
        }
        /// <summary>
        /// Determines the positions of the two possible turning circles 
        /// Relative to the initial position which is not passed into the function
        /// </summary>
        /// <param name="initialVelocity">The current velocity of the object</param>
        /// <param name="radius">The desired radius of the object</param>
        /// <param name="circleOne">The first of the two possible turning circles</param>
        /// <param name="circleTwo">The second of the two possible turning circles</param>
        public void DetermineTurningCircles(Vector initialVelocity, double radius, out Vector circleOne, out Vector circleTwo)
        {
            Angle velocityAngle;

            // calculate the angle of the current velocity
            velocityAngle = new Angle(initialVelocity);
            velocityAngle.ReduceAngle();

            //double vesselSpeed = initialVelocity.Length;
            // calculate the radius if the turning circle based on the acceleration and current speed
            //double radius = CalcRadius(vesselSpeed, acceleration);

            // calcualte both of the turning circles
            Angle angleOne = new Angle(velocityAngle.Value + (Math.PI / 2));
            circleOne = CoordinateConversions.RadialToVector(angleOne, radius);

            Angle angleTwo = new Angle(velocityAngle.Value - (Math.PI / 2));
            circleTwo = CoordinateConversions.RadialToVector(angleTwo, radius);
        }