public void Cross_product_is_anticommutative()
        {
            var a = new Vector(1, 2, 3);
            var b = new Vector(6, 4, 5);

            Assert.Equal(Vector.CrossProduct(a, b), -Vector.CrossProduct(b, a));
        }
        public void The_operation_is_commutative()
        {
            var a = new Vector(1, 2, 3);
            var b = new Vector(6, -7, -8);

            Assert.Equal(Vector.DotProduct(a, b), Vector.DotProduct(b, a));
        }
        public void The_operation_is_commutative()
        {
            var vector = new Vector(3, -49, 17);
            var scalar = 14.7f;

            Assert.Equal(vector * scalar, scalar * vector);
        }
        public void The_operation_is_commutative()
        {
            var a = new Vector(18, 4, -91);
            var b = new Vector(63, 86, -12);

            Assert.Equal(a + b, b + a);
        }
        public void The_result_is_a_vector_whos_dot_product_with_the_original_vector_equals_the_original_vectors_length()
        {
            var x = new Vector(10, 4.7f, -13);

            Assert.Equal(
                x.Length,
                Vector.DotProduct(x.ToUnitVector(), x), EpsilonComparer.DoubleComparer);
        }
示例#6
0
文件: Ray.cs 项目: pritisutar/kelly
        public Ray(Point origin, Vector direction)
        {
            if (!direction.IsUnit) {
                throw new ArgumentException("Rays can only be constructed with unit-vector directions.");
            }

            Origin = origin;
            Direction = direction;
        }
        public void The_resulting_vector_has_a_dot_product_of_zero_with_both_input_vectors()
        {
            var a = new Vector(2, 3, 4);
            var b = new Vector(4, 5, 6);

            var cross = Vector.CrossProduct(a, b);

            Assert.Equal(0f, Vector.DotProduct(a, cross));
            Assert.Equal(0f, Vector.DotProduct(cross, b));
        }
        public void A_translation_matrix_should_result_in_the_same_vector()
        {
            var vector = new Vector(1, 2, 3);

            var matrix = new Matrix(
                1, 0, 0, 1,
                0, 1, 0, 2,
                0, 0, 1, 3,
                0, 0, 0, 1);

            Assert.Equal(vector, matrix * vector);
        }
示例#9
0
        /// <summary>
        ///		Creates a matrix that represents a rotation of <paramref name="angle"/> radians about <paramref name="axis"/>.
        /// </summary>
        /// <remarks>
        ///		We use the same coordinate system as OpenGL (right-handed), and we use their matrix rotation specs as a spec for our rotations.
        ///		<see cref="http://opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/rotate.html"/>
        /// </remarks>
        public static Matrix Rotation(Vector axis, double angle)
        {
            axis = axis.ToUnitVector();

            var x = axis.X;
            var y = axis.Y;
            var z = axis.Z;

            var sin = System.Math.Sin(angle);
            var cos = System.Math.Cos(angle);

            return new Matrix(
                x * x * (1 - cos) + cos,		x * y * (1 - cos) - (z * sin),	x * z * (1 - cos) + y * sin,	0,
                y * x * (1 - cos) + z * sin,	y * y * (1 - cos) + cos,		y * z * (1 - cos) - x * sin,	0,
                x * z * (1 - cos) - y * sin,	y * z * (1 - cos) + x * sin,	z * z * (1 - cos) + cos,		0,
                0,								0,								0,								0
                );
        }
示例#10
0
 public AxisAlignedBoundingBox GetBoundingBox()
 {
     var vec = new Vector(Radius, Radius, Radius);
     return new AxisAlignedBoundingBox(Position - vec, Position + vec);
 }
示例#11
0
        public void Equals_the_square_root_of_the_SquaredLength_property()
        {
            var a = new Vector(43, 29, -14);

            Assert.Equal(System.Math.Sqrt(a.SquaredLength), a.Length);
        }
 private static Vector Rotate90Degrees(Vector vectorToRotate, Vector rotationAxis)
 {
     var transformation = Matrix.Rotation(rotationAxis, 90d.ToRadians());
     return transformation * vectorToRotate;
 }
示例#13
0
 public static Matrix Rotate(this Matrix matrix, Vector axis, double angle)
 {
     return matrix * Matrix.Rotation(axis, angle);
 }
示例#14
0
 public static Matrix PerspectiveProjection(Vector position, Vector view, Vector up, double fieldOfView, double aspectRatio)
 {
     throw new NotImplementedException();
 }
        public void The_result_is_equal_to_the_SquaredLength_property_when_a_vector_is_dotted_with_itself()
        {
            var vector = new Vector(82408, 42, 1337);

            Assert.Equal(vector.SquaredLength, Vector.DotProduct(vector, vector));
        }
        public void The_identity_matrix_should_result_in_the_same_vector()
        {
            var vector = new Vector(1, 2, 3);

            Assert.Equal(vector, Matrix.Identity * vector);
        }