Пример #1
0
        public void Rays_Test()
        {
            var microphone = new List <MicrophoneSphere>()
            {
                new MicrophoneSphere(new System.Numerics.Vector3(2, 1.6f, 1.7f), 0.1f)
            };
            var rayGeometryGenerator = new RayGeometry(new Vector3(0, 0.5f, 0),
                                                       microphone,
                                                       70000,
                                                       3,
                                                       200);

            rayGeometryGenerator.GenerateRays();

            var rays = rayGeometryGenerator.GetIntersectedRays(microphone[0]);

            rays.Sort((first, second) => first.GetDistance().CompareTo(second.GetDistance()));

            var myRays = new Dictionary <int, List <AcousticRay> >();

            myRays.Add(microphone[0].Id, rays);

            var intensityCalculator = new IntensityCalculator(myRays, microphone, 1);

            intensityCalculator.ComputePower();

            var distanceCalculator = new DistanceCalculator(myRays, microphone);

            distanceCalculator.ComputeDistances();

            double epsilon = 1e-4;

            Assert.IsTrue(Math.Abs(intensityCalculator.Intensities[microphone[0].Id][0] - 0.0098243) < epsilon);
        }
Пример #2
0
        public void DistanceForMultipleCollisionPoints_Test()
        {
            var origin      = new Vector3(0, 0, 0);
            var microphones = new List <MicrophoneSphere>()
            {
                new MicrophoneSphere(new Vector3(1, 5, 3), 0.5f)
            };

            var firstRay = new AcousticRay(origin, microphones[0].Center);

            var firstRayVectors = new List <Vector3>()
            {
                new Vector3(1, 2, 3),
                new Vector3(1, 2, 4),
                new Vector3(1, 3, 3),
                new Vector3(1, 5.02f, 3)
            };

            foreach (var vec in firstRayVectors)
            {
                firstRay.CollisionPoints.Add(vec);
            }

            var rays = new List <AcousticRay>
            {
                firstRay
            };

            var raysDictionary = new Dictionary <int, List <AcousticRay> >();

            raysDictionary[microphones[0].Id] = rays;

            var distanceCalculator = new DistanceCalculator(raysDictionary, microphones);

            distanceCalculator.ComputeDistances();

            var distancesResults = new List <float>()
            {
                3.74f, 4.74f, 6.15f, 8.17f, 8.19f
            };

            Assert.IsTrue(Math.Abs(distancesResults[4] - raysDictionary[microphones[0].Id][0].GetDistance()) < 1e-2);
        }
Пример #3
0
        public void TimeForMultipleCollisionPoints_Test()
        {
            var origin      = new Vector3(0, 0, 0);
            var microphones = new List <MicrophoneSphere>()
            {
                new MicrophoneSphere(new Vector3(1, 5, 3), 0.5f)
            };

            var firstRay = new AcousticRay(origin, microphones[0].Center);

            var firstRayVectors = new List <Vector3>()
            {
                new Vector3(1, 2, 3),
                new Vector3(1, 2, 4),
                new Vector3(1, 3, 3),
                new Vector3(1, 5.02f, 3)
            };

            foreach (var vec in firstRayVectors)
            {
                firstRay.CollisionPoints.Add(vec);
            }

            var rays = new List <AcousticRay>
            {
                firstRay
            };

            var raysDictionary = new Dictionary <int, List <AcousticRay> >();

            raysDictionary[microphones[0].Id] = rays;

            var distanceCalculator = new DistanceCalculator(raysDictionary, microphones);

            distanceCalculator.ComputeDistances();

            var times = TimeCalculator.GetTime(raysDictionary, microphones);

            Assert.IsTrue(Math.Abs(times[microphones[0].Id][0] - 0.0238) < 1e-3);
        }