Example #1
0
    public void Lerp()
    {
        for (int i = 0; i < count; i++)
        {
            float ax, ay, az, aw;
            float bx, by, bz, bw;
            float p = UnityEngine.Random.Range(-2F, 2F);

            ax = UnityEngine.Random.Range(-10F, 10F);
            ay = UnityEngine.Random.Range(-10F, 10F);
            az = UnityEngine.Random.Range(-10F, 10F);
            aw = UnityEngine.Random.Range(-10F, 10F);

            bx = UnityEngine.Random.Range(-10F, 10F);
            by = UnityEngine.Random.Range(-10F, 10F);
            bz = UnityEngine.Random.Range(-10F, 10F);
            bw = UnityEngine.Random.Range(-10F, 10F);

            Vector4 a = new Vector4(ax, ay, az, aw);
            Vector4 b = new Vector4(bx, by, bz, bw);

            Vector4d ad = new Vector4d(ax, ay, az, aw);
            Vector4d bd = new Vector4d(bx, by, bz, bw);

            Vector4  value  = Vector4.Lerp(a, b, p);
            Vector4d valued = Vector4d.Lerp(ad, bd, p);

            Assert.True(Approximate(value, valued));
        }
    }
            /// <summary>
            /// Evaluate tabulated LRTF by trilinear interpolation.
            /// </summary>
            /// <param name="table"></param>
            /// <param name="incomingParams"></param>
            /// <returns></returns>
            public Parameters EvaluateLrtf3D(Parameters incomingParams)
            {
                double step = Size - 1;
                double x    = incomingParams.PositionTheta * step;
                double y    = incomingParams.DirectionTheta * step;
                double z    = incomingParams.DirectionPhi * step;

                int xFloor = (int)Math.Floor(x);
                int yFloor = (int)Math.Floor(y);
                int zFloor = (int)Math.Floor(z);
                int xCeil  = (int)Math.Ceiling(x);
                int yCeil  = (int)Math.Ceiling(y);
                int zCeil  = (int)Math.Ceiling(z);

                double xFloat = x - xFloor;
                double yFloat = y - yFloor;
                double zFloat = z - zFloor;

                // trilinear interpolation over position theta, direction theta, direction phi:
                // position phi is ignored here

                // first linear interpolation
                Vector4d i0 = Vector4d.Lerp(
                    Table[xFloor, yFloor, zFloor],
                    Table[xFloor, yFloor, zCeil], zFloat);
                Vector4d i1 = Vector4d.Lerp(
                    Table[xFloor, yCeil, zFloor],
                    Table[xFloor, yCeil, zCeil], zFloat);
                Vector4d i2 = Vector4d.Lerp(
                    Table[xCeil, yFloor, zFloor],
                    Table[xCeil, yFloor, zCeil], zFloat);
                Vector4d i3 = Vector4d.Lerp(
                    Table[xCeil, yCeil, zFloor],
                    Table[xCeil, yCeil, zCeil], zFloat);

                // second linear interpolation
                Vector4d j0 = Vector4d.Lerp(i0, i1, yFloat);
                Vector4d j1 = Vector4d.Lerp(i2, i3, yFloat);

                // third linear interpolation
                Vector4d k = Vector4d.Lerp(j0, j1, xFloat);

                var outgoingParams = new Parameters(k);

                // rotate the resulting ray as rotation is separated from the 3D table
                outgoingParams.PositionPhi += incomingParams.PositionPhi;
                return(outgoingParams);
            }
Example #3
0
        public static IEnumerable <object[]> Data()
        {
            var objs = new[]
            {
                new object[] { Vector256.Create(0d), Vector256.Create(0d), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(0d), Vector256.Create(0d), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(0d), Vector256.Create(0d), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(0d), Vector256.Create(0d), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(1d), Vector256.Create(1d), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(1d), Vector256.Create(1d), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(1d), Vector256.Create(1d), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(1d), Vector256.Create(1d), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(-1d), Vector256.Create(-1d), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(-1d), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(-1d), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(-1d), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(-1d), Vector256.Create(1d, 4d, 9d, 16d), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(1d, 4d, 9d, 16d), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(1d, 4d, 9d, 16d), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(-1d), Vector256.Create(1d, 4d, 9d, 16d), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(1d, 2d, 3d, 4d), Vector256.Create(4d, -5d, 6d, 9d), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(1d, 2d, 3d, 4d), Vector256.Create(4d, -5d, 6d, 9d), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(1d, 2d, 3d, 4d), Vector256.Create(4d, -5d, 6d, 9d), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(1d, 2d, 3d, 4d), Vector256.Create(4d, -5d, 6d, 9d), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.PositiveInfinity), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.PositiveInfinity), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.PositiveInfinity), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.PositiveInfinity), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.NegativeInfinity), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.NegativeInfinity), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.NegativeInfinity), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(double.PositiveInfinity), Vector256.Create(double.NegativeInfinity), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(double.NaN), Vector256.Create(double.NegativeInfinity), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(double.NaN), Vector256.Create(double.NegativeInfinity), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(double.NaN), Vector256.Create(double.NegativeInfinity), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(double.NaN), Vector256.Create(double.NegativeInfinity), 1.0d, default(Vector4d) },

                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), 0.1d, default(Vector4d) },
                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), 0.5d, default(Vector4d) },
                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), 0.0d, default(Vector4d) },
                new object[] { Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), Vector256.Create(double.MaxValue, double.MinValue, double.NaN, 0), 1.0d, default(Vector4d) },
            };

            foreach (object[] set in objs)
            {
                Vector4d v1     = TestHelpers.ByValToSlowVector4d((Vector256 <double>)set[0]);
                Vector4d v2     = TestHelpers.ByValToSlowVector4d((Vector256 <double>)set[1]);
                var      weight = (double)set[2];

                set[3] = Vector4d.Lerp(v1, v2, weight);
            }

            return(objs);
        }