/// <summary>
        /// Get the cell slope in radians based on its circular neighborhood. The results is the angle between vertical axis and normal of the cell.
        /// E.g. 0 = cell is completely flat, pi/2 = the cell is a vertical wall.
        /// </summary>
        /// <param name="cellY">Y coordinate of the cell</param>
        /// <param name="cellX">X coordinate of the cell</param>
        /// <returns>Cell slope in radians</returns>
        private double GetCellSlope(int cellY, int cellX)
        {
            double cn = Math.Sqrt(2);
            double northsouth;
            double eastwest;

            if (cellX <= 0 || cellY <= 0 || cellX >= ElevationMap.GetLength(1) - 1 || cellY >= ElevationMap.GetLength(0) - 1)
            {
                return(0);
            }

            try {
                northsouth = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY - 1, cellX] + cn * ElevationMap[cellY - 1, cellX + 1]) / 4
                             - (cn * ElevationMap[cellY + 1, cellX - 1] + ElevationMap[cellY + 1, cellX] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;

                eastwest = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY, cellX - 1] + cn * ElevationMap[cellY + 1, cellX - 1]) / 4
                           - (cn * ElevationMap[cellY - 1, cellX + 1] + ElevationMap[cellY, cellX + 1] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;
            } catch (IndexOutOfRangeException) {
                System.Diagnostics.Debug.WriteLine("{0}, {1}", cellX, cellY);
                return(0);
            }

            Vector3 northVector = Vector3.Normalize(new Vector3(0, 2 * (float)cellResolution, (float)northsouth));
            Vector3 eastVector  = Vector3.Normalize(new Vector3(2 * (float)cellResolution, 0, (float)eastwest));

            Vector3 slopeVector = Vector3.Cross(eastVector, northVector);

            return(GetVectorAngle(slopeVector, verticalVector));
        }
        /// <summary>
        ///  Calculate West-East and North-South components of the cell slope.
        /// </summary>
        /// <param name="cellY">Y coordinate of the cell</param>
        /// <param name="cellX">X coordinate of the cell</param>
        /// <param name="westeast">output West-East component</param>
        /// <param name="southnorth">output North-South component</param>
        private void GetCellSlopeComponents(int cellY, int cellX, out double eastwest, out double northsouth)
        {
            double cn = Math.Sqrt(2);

            if (cellX <= 0 || cellY <= 0 || cellX >= ElevationMap.GetLength(1) - 1 || cellY >= ElevationMap.GetLength(0) - 1)
            {
                northsouth = eastwest = 0;
                return;
            }

            try {
                northsouth = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY - 1, cellX] + cn * ElevationMap[cellY - 1, cellX + 1]) / 4
                             - (cn * ElevationMap[cellY + 1, cellX - 1] + ElevationMap[cellY + 1, cellX] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;

                eastwest = (cn * ElevationMap[cellY - 1, cellX - 1] + ElevationMap[cellY, cellX - 1] + cn * ElevationMap[cellY + 1, cellX - 1]) / 4
                           - (cn * ElevationMap[cellY - 1, cellX + 1] + ElevationMap[cellY, cellX + 1] + cn * ElevationMap[cellY + 1, cellX + 1]) / 4;
            } catch (IndexOutOfRangeException) {
                System.Diagnostics.Debug.WriteLine("{0}, {1}", cellX, cellY);
                northsouth = eastwest = 0;
            }
        }