/// <summary>
        /// This method will create a circle around the centre point founf within
        /// this instantiated object. The method will make use of Earth's Radius at
        /// the centre of the circle, as this is a good enough approximation for
        /// small circle.
        /// </summary>
        /// <param name="n">The number of points to be generated</param>
        /// <param name="offset">the offset of radius value</param>
        /// <returns>A list of coordiantes</returns>
        public List <Coordinate> CreateRadialCircle(int n = 360, double offset = 0)
        {
            // Mean Radius of Earth in meters
            double offsetRadians = offset * (Math.PI / 180);

            // Get the longitude and latitudes as radians for further calculations
            double longitude = Centre.LongitudeAsRadians();
            double latitude  = Centre.LatitudeAsRadians();

            // compute longitude degrees (in radians) at the latitude
            double r = (Radius / (Distance.EarthRadius(Centre.Latitude) * Math.Cos(latitude)));

            // Create a new centre Spherical point
            SphericalCoordinate centre = new SphericalCoordinate(longitude, latitude);

            // Create one outer point to use for rotating N times
            SphericalCoordinate point = new SphericalCoordinate(longitude + r, latitude);

            // Create a new coordinates list for all the radial points
            List <Coordinate> coordinates = new List <Coordinate>();

            // Rotate around the centre n number of times
            for (int i = 0; i < n; i++)
            {
                // Generate new Coordinate
                double     phi = offsetRadians + (2.0 * Math.PI / n) * i;
                Coordinate c   = rotatePoint(point, phi);
                coordinates.Add(c);
            }
            // To create a complete circle
            coordinates.Add(coordinates[0]);

            return(coordinates);
        }
        /// <summary>
        /// This method will rotate a given point around the given centre centroid
        /// within this object by phi radians.
        /// </summary>
        /// <param name="point">The point to be rotated</param>
        /// <param name="phi">The number of radians to move the point by</param>
        /// <returns>A coordinate</returns>
        private Coordinate rotatePoint(SphericalCoordinate point, double phi)
        {
            // Map values to new variables for reasons of maintaining sanity
            double u = Spherical.X;
            double v = Spherical.Y;
            double w = Spherical.Z;
            double x = point.X;
            double y = point.Y;
            double z = point.Z;

            double a = u * x + v * y + w * z;
            double d = Math.Cos(phi);
            double e = Math.Sin(phi);

            // Create a new Spherical Coordinate
            double newX = (a * u + (x - a * u) * d + (v * z - w * y) * e);
            double newY = (a * v + (y - a * v) * d + (w * x - u * z) * e);
            double newZ = (a * w + (z - a * w) * d + (u * y - v * x) * e);

            return(new SphericalCoordinate(newX, newY, newZ).ToCoordinate());
        }
 public void TestToSphericalCoordinate()
 {
     // Obtain the Longitude and Latitude as Radians
       double lon = centroid.LongitudeAsRadians();
       double lat = centroid.LatitudeAsRadians();
       // Create an expected SphericalCoordinate object
       SphericalCoordinate expected = new SphericalCoordinate(lon, lat);
       // Obtain the actual SphericalCoordinate
       SphericalCoordinate result = centroid.ToSphericalCoordinate();
       // Ensure the X values are the same
       Assert.AreEqual(expected.X, result.X);
       // Ensure the Y values are the same
       Assert.AreEqual(expected.Y, result.Y);
       // Ensure the Z values are the same
       Assert.AreEqual(expected.Z, result.Z);
 }
 /// <summary>
 /// Primary Constructor
 /// </summary>
 /// <param name="centre">the centroid of the radius</param>
 /// <param name="radius">the radius of the circle in meters</param>
 public RadialCircle(Centroid centre, double radius)
 {
     Centre    = centre;
     Radius    = radius;
     Spherical = centre.ToSphericalCoordinate();
 }
 public void Initalise()
 {
     coordinate = new SphericalCoordinate(LONGITUDE, LATITUDE);
 }
        /// <summary>
        /// This method will create a circle around the centre point founf within 
        /// this instantiated object. The method will make use of Earth's Radius at 
        /// the centre of the circle, as this is a good enough approximation for 
        /// small circle.
        /// </summary>
        /// <param name="n">The number of points to be generated</param>
        /// <param name="offset">the offset of radius value</param>
        /// <returns>A list of coordiantes</returns>
        public List<Coordinate> CreateRadialCircle(int n = 360, double offset = 0)
        {
            // Mean Radius of Earth in meters
              double offsetRadians = offset * (Math.PI / 180);

              // Get the longitude and latitudes as radians for further calculations
              double longitude = Centre.LongitudeAsRadians();
              double latitude = Centre.LatitudeAsRadians();

              // compute longitude degrees (in radians) at the latitude
              double r = (Radius / (Distance.EarthRadius(Centre.Latitude) * Math.Cos(latitude)));

              // Create a new centre Spherical point
              SphericalCoordinate centre = new SphericalCoordinate(longitude, latitude);

              // Create one outer point to use for rotating N times
              SphericalCoordinate point = new SphericalCoordinate(longitude + r, latitude);

              // Create a new coordinates list for all the radial points
              List<Coordinate> coordinates = new List<Coordinate>();

              // Rotate around the centre n number of times
              for (int i = 0; i < n; i++)
              {
            // Generate new Coordinate
            double phi = offsetRadians + (2.0 * Math.PI / n) * i;
            Coordinate c = rotatePoint(point, phi);
            coordinates.Add(c);
              }
              // To create a complete circle
              coordinates.Add(coordinates[0]);

              return coordinates;
        }
        /// <summary>
        /// This method will rotate a given point around the given centre centroid 
        /// within this object by phi radians.
        /// </summary>
        /// <param name="point">The point to be rotated</param>
        /// <param name="phi">The number of radians to move the point by</param>
        /// <returns>A coordinate</returns>
        private Coordinate rotatePoint(SphericalCoordinate point, double phi)
        {
            // Map values to new variables for reasons of maintaining sanity
              double u = Spherical.X;
              double v = Spherical.Y;
              double w = Spherical.Z;
              double x = point.X;
              double y = point.Y;
              double z = point.Z;

              double a = u * x + v * y + w * z;
              double d = Math.Cos(phi);
              double e = Math.Sin(phi);

              // Create a new Spherical Coordinate
              double newX = (a * u + (x - a * u) * d + (v * z - w * y) * e);
              double newY = (a * v + (y - a * v) * d + (w * x - u * z) * e);
              double newZ = (a * w + (z - a * w) * d + (u * y - v * x) * e);

              return new SphericalCoordinate(newX, newY, newZ).ToCoordinate();
        }