public void RoundTripSphericalPolarTests(double alt, double az)
        {
            AxisPosition        axes       = new AxisPosition(az, alt);
            SphericalCoordinate spherical1 = model.AxesToSpherical(new double[] { az, alt }, timeRecord);
            AxisPosition        outAxes    = model.SphericalToAxes(spherical1, timeRecord, spherical1.WeightsDown);

            Assert.IsTrue(outAxes.Equals(axes, tolerance));
        }
        /// <summary>
        /// Converts to Cartesian coordinates.
        /// </summary>
        /// <returns>CartesianCoordinate.</returns>
        public static CartesianCoordinate3D ToCartesian(SphericalCoordinate coordinate)
        {
            double x = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians) * NMath.Cos(coordinate.Azimuth.Radians);
            double y = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians) * NMath.Sin(coordinate.Azimuth.Radians);
            double z = coordinate.Radius * NMath.Cos(coordinate.Inclination.Radians);

            return(new CartesianCoordinate3D(x, y, z, coordinate.Tolerance));
        }
        /// <summary>
        /// Converts to cylindrical coordinates.
        /// </summary>
        /// <returns>CylindricalCoordinate.</returns>
        public static CylindricalCoordinate ToCylindrical(SphericalCoordinate coordinate)
        {
            double radius  = coordinate.Radius * NMath.Sin(coordinate.Inclination.Radians);
            double height  = coordinate.Radius * NMath.Cos(coordinate.Inclination.Radians);
            double azimuth = coordinate.Azimuth.Radians;

            return(new CylindricalCoordinate(radius, height, azimuth, coordinate.Tolerance));
        }
    /// <summary>
    /// Overriding the equals method to be able to avoid float pooint errors.
    /// </summary>
    /// <param name="obj"></param>
    /// <returns></returns>
    public override bool Equals(object obj)
    {
        double eps = 0.01;
        SphericalCoordinate other = (SphericalCoordinate)obj;

        return(Math.Abs(this.azimuth - other.azimuth) < eps &&
               Math.Abs(this.inclination - other.inclination) < eps &&
               Math.Abs(this.radius - other.radius) < eps);
    }
示例#5
0
        private CartesianCoordinate getWaveVector(
            SpectrumUnit waveLength,
            double refractiveIndex,
            SphericalCoordinate angle)
        {
            SphericalCoordinate radianAngles = angle.ToRadians();

            radianAngles.Radius = waveLength.ToType(SpectrumUnitType.WaveNumber) * refractiveIndex; // k_mod

            return(radianAngles.ConvertToCartesian());
        }
示例#6
0
        /// <summary>
        /// Creates the Cartesian coordinate from Spherical coordinates.
        /// </summary>
        /// <param name="spherical">The spherical.</param>
        /// <returns>
        /// The Cartesian coordinate.
        /// </returns>
        public static CartesianCoordinate ConvertToCartesian(this SphericalCoordinate spherical)
        {
            var sphericalRad = spherical.ToRadians();

            double radsin = sphericalRad.Radius * Math.Sin(sphericalRad.Polar);

            return(new CartesianCoordinate(
                       radsin * Math.Cos(sphericalRad.Azimuth),
                       radsin * Math.Sin(sphericalRad.Azimuth),
                       sphericalRad.Radius * Math.Cos(sphericalRad.Polar)));
        }
        public void RoundTripPolarCartesTests(double alt, double az)
        {
            SphericalCoordinate inSpherical = new SphericalCoordinate()
            {
                X           = az,
                Y           = alt,
                WeightsDown = false
            };
            CarteseanCoordinate outCart      = model.SphericalToCartesean(inSpherical);
            SphericalCoordinate outSpherical = model.CarteseanToSpherical(outCart);

            Assert.AreEqual(inSpherical, outSpherical);
        }
        public void RoundTripAxesToSpherical(double x, double y)
        {
            SphericalCoordinate spherical = model.AxesToSpherical(new double[] { x, y }, timeRecord);

            double[] axes  = model.SphericalToAxes(spherical, timeRecord, spherical.WeightsDown);
            double   cosx  = Math.Cos(Angle.DegreesToRadians(x));
            double   cosy  = Math.Cos(Angle.DegreesToRadians(y));
            double   cosa0 = Math.Cos(Angle.DegreesToRadians(axes[0]));
            double   cosa1 = Math.Cos(Angle.DegreesToRadians(axes[1]));

            Assert.AreEqual(cosx, cosa0, tolerance);
            Assert.AreEqual(cosy, cosa1, tolerance);
        }
            public static Vector3 ToCartesian(SphericalCoordinate sc)
            {
                var cosTheta = Mathf.Cos(sc.m_Theta);
                var cosPhi   = Mathf.Cos(sc.m_Phi);
                var sinTheta = Mathf.Sin(sc.m_Theta);
                var sinPhi   = Mathf.Sin(sc.m_Phi);

                var xzr = sc.m_Radius * sinTheta;
                var x   = xzr * cosPhi;
                var z   = xzr * sinPhi;
                var y   = sc.m_Radius * cosTheta;

                return(new Vector3(x, y, z));
            }
        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);
        }
示例#11
0
        /// <summary>
        /// Converts to degrees.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <returns>
        /// New angles in radians.
        /// </returns>
        /// <exception cref="System.ComponentModel.InvalidEnumArgumentException">Throws if unit do not support conversion.</exception>
        public static SphericalCoordinate ToDegrees(this SphericalCoordinate coordinate)
        {
            switch (coordinate.Units)
            {
            case UnitOfMeasurement.Degree:
                return(coordinate);

            case UnitOfMeasurement.Radian:
                double polar   = coordinate.Polar / RadianTransformationCoefficient;
                double azimuth = coordinate.Azimuth / RadianTransformationCoefficient;

                return(new SphericalCoordinate(coordinate.Radius, polar, azimuth, UnitOfMeasurement.Degree));

            default:
                throw new InvalidEnumArgumentException(string.Format("Cannot convert from unit {0}", coordinate.Units));
            }
        }
示例#12
0
        /// <summary>
        /// Gets the dispersion parameters.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <param name="angle">The angle.</param>
        /// <returns>The dispersion parameters.</returns>
        public DispersionParameter GetDispersionParameters(SpectrumUnit parameter, SphericalCoordinate angle)
        {
            var parameters = new DispersionParameter
            {
                SpectrumParameter     = parameter,
                MediumRefractiveIndex = this.getMediumCoeficient(parameter),
                Permittivity          = this.medium.GetPermittivity(parameter)
            };

            CartesianCoordinate waveVector = this.getWaveVector(
                parameter,
                parameters.MediumRefractiveIndex,
                angle);

            parameters.WaveVector = waveVector;
            return(parameters);
        }
        public static Vector3 ToCartesian(float radius, float theta, float phi)
        {
            var sc = new SphericalCoordinate(radius, phi, theta);

            return(sc.ToCartesian());
        }
示例#14
0
    public static IEnumerator LoadCsv(String filename, LidarStorage storage)
    {
        StreamReader sr = new StreamReader(File.OpenRead(filename));
        Dictionary <float, List <LinkedList <SphericalCoordinate> > > data = new Dictionary <float, List <LinkedList <SphericalCoordinate> > >();
        bool internalData = false; //The data to be read was created by our program


        if (sr.Peek().Equals('s')) // First line starts with "sep..." internal representation.
        {
            internalData = true;
            for (int i = 0; i < 2; i++)
            {
                sr.ReadLine(); // Discard first two lines
            }
        }
        while (!sr.EndOfStream)
        {
            try
            {
                float key = 0;



                List <float> values = new List <float>();
                LinkedList <SphericalCoordinate> coorValues = new LinkedList <SphericalCoordinate>();
                string[] columns = sr.ReadLine().Split(' ');


                try
                {
                    if (columns.Length == 4) // Kitty data
                    {
                        key = 1;
                        float               x      = float.Parse(columns[0]);
                        float               z      = float.Parse(columns[1]);
                        float               y      = float.Parse(columns[2]);
                        Vector3             vector = new Vector3(x, y, z);
                        SphericalCoordinate sc     = new SphericalCoordinate(vector);
                        coorValues.AddLast(sc);
                    }
                    else if (columns.Length == 8)  // Data from simulation
                    {
                        key = float.Parse(columns[0]);
                        float               x           = float.Parse(columns[1]);
                        float               z           = float.Parse(columns[2]);
                        float               y           = float.Parse(columns[3]);
                        float               radius      = float.Parse(columns[4]);
                        float               inclination = float.Parse(columns[5]);
                        float               azimuth     = float.Parse(columns[6]);
                        int                 laserId     = int.Parse(columns[7]);
                        Vector3             vector      = new Vector3(x, y, z);
                        SphericalCoordinate sc          = new SphericalCoordinate(radius, inclination, azimuth, vector, laserId);
                        coorValues.AddLast(sc);
                    }
                    else
                    {
                        throw new FormatException();
                    }
                }
                catch (FormatException e)
                {
                    Debug.Log("Exception! |time|radius|inclination|azimuth" + "|" + columns[0] + "|" + columns[2] + "|" + columns[3] + "|" + columns[4]);
                }
                catch (ArgumentOutOfRangeException e)
                {
                    Debug.Log("Length:" + columns.Length);
                }



                List <LinkedList <SphericalCoordinate> > oldList;
                List <LinkedList <SphericalCoordinate> > dataList = new List <LinkedList <SphericalCoordinate> >();
                dataList.Add(coorValues);
                if (!data.TryGetValue(key, out oldList))
                {
                    data.Add(key, dataList);
                }
                else
                {
                    List <LinkedList <SphericalCoordinate> > existingList = data[key];
                    existingList.Add(coorValues);
                }
            } catch (Exception e)
            {
                Debug.Log("Unreadable data: " + e);
            }
        }

        Debug.Log("Setting data in: " + storage.GetHashCode() + " with length" + data.Count);
        storage.SetData(data);

        yield return(null);
    }
 public void Initalise()
 {
     coordinate = new SphericalCoordinate(LONGITUDE, LATITUDE);
 }
示例#16
0
 private void Awake()
 {
     sphericalCoordinate = new SphericalCoordinate(transform.position);
     wheel = 3.5f;
 }
示例#17
0
 private void Awake()
 {
     pivot = FindObjectOfType <CameraPivot>();
     sphericalCoordinate = new SphericalCoordinate(transform.position, 5.0f, 5.0f, 10.0f, 0.0f, 85.0f);
 }
 public static SphericalCoordinate FromCartesian(Vector3 v)
 {
     return(SphericalCoordinate.FromCartesian(v));
 }
 public static Vector3 ToCartesian(SphericalCoordinate sc)
 {
     return(sc.ToCartesian());
 }
示例#20
0
 private void Start()
 {
     sphericalCoordinate = new SphericalCoordinate(transform.position);
     transform.position  = sphericalCoordinate.GetCartesianCoord() + targetToFollow.position;
 }
示例#21
0
 private void Awake()
 {
     sphericalCoordinate = new SphericalCoordinate(transform.position);
     cameraRig           = FindObjectOfType <AirVRCameraRig>();
 }