예제 #1
0
 /// <summary>
 /// Calculates whether this box contains another box
 /// </summary>
 /// <param name="other">The box.</param>
 /// <returns>True if this box contains the given box; False otherwise.</returns>
 /// <remarks>This does consider a box that touches the edge contained.</remarks>
 public bool Contains(Box3D <T> other)
 => Scalar.GreaterThanOrEqual(other.Min.X, this.Min.X) && Scalar.GreaterThanOrEqual(other.Min.Y, this.Min.Y) &&
 Scalar.GreaterThanOrEqual(other.Min.Z, this.Min.Z) &&
 Scalar.LessThanOrEqual(other.Max.X, this.Max.X) && Scalar.LessThanOrEqual(other.Max.Y, this.Max.Y) &&
 Scalar.LessThanOrEqual(other.Max.Z, this.Max.Z);
예제 #2
0
        /// <summary>
        /// Calculates the distance to the nearest edge from the point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>The distance.</returns>
        public T GetDistanceToNearestEdge(Vector3D <T> point)
        {
            var dx = Scalar.Max(Scalar.Max(Scalar.Subtract(Min.X, point.X), Scalar <T> .Zero), Scalar.Subtract(point.X, Max.X));
            var dy = Scalar.Max(Scalar.Max(Scalar.Subtract(Min.Y, point.Y), Scalar <T> .Zero), Scalar.Subtract(point.Y, Max.Y));
            var dz = Scalar.Max(Scalar.Max(Scalar.Subtract(Min.Z, point.Z), Scalar <T> .Zero), Scalar.Subtract(point.Z, Max.Z));

            return(Scalar.Sqrt(Scalar.Add(Scalar.Add(Scalar.Multiply(dx, dx), Scalar.Multiply(dy, dy)), Scalar.Multiply(dz, dz))));
        }
예제 #3
0
 /// <summary>
 /// Calculates whether this box contains another box
 /// </summary>
 /// <param name="other">The box.</param>
 /// <returns>True if this box contains the given box; False otherwise.</returns>
 /// <remarks>This does consider a box that touches the edge contained.</remarks>
 public bool Contains(Box2D <T> other)
 => Scalar.GreaterThanOrEqual(other.Min.X, Min.X) && Scalar.GreaterThanOrEqual(other.Min.Y, Min.Y) &&
 Scalar.LessThanOrEqual(other.Max.X, Max.X) && Scalar.LessThanOrEqual(other.Max.Y, Max.Y);
예제 #4
0
 /// <summary>
 /// Calculates whether this box contains a point.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>True if this box contains the point; False otherwise.</returns>
 /// <remarks>This does consider a point on the edge contained.</remarks>
 public bool Contains(Vector3D <T> point)
 => Scalar.GreaterThanOrEqual(point.X, Min.X) && Scalar.GreaterThanOrEqual(point.Y, Min.Y) &&
 Scalar.GreaterThanOrEqual(point.Z, Min.Z) &&
 Scalar.LessThanOrEqual(point.X, Max.X) && Scalar.LessThanOrEqual(point.Y, Max.Y) &&
 Scalar.LessThanOrEqual(point.Z, Max.Z);
예제 #5
0
        /// <summary>
        /// Calculates whether this rectangle contains another rectangle
        /// </summary>
        /// <param name="other">The rectangle.</param>
        /// <returns>True if this rectangle contains the given rectangle; False otherwise.</returns>
        /// <remarks>This does consider a rectangle that touches the edge contained.</remarks>
        public bool Contains(Rectangle <T> other)
        {
            var tMax = this.Max;
            var oMax = other.Max;

            return(Scalar.GreaterThanOrEqual(other.Origin.X, this.Origin.X) && Scalar.GreaterThanOrEqual
                       (other.Origin.Y, this.Origin.Y) && Scalar.LessThanOrEqual(oMax.X, tMax.X) && Scalar.LessThanOrEqual
                       (oMax.Y, tMax.Y));
        }
예제 #6
0
        /// <summary>
        /// Calculates the distance to the nearest edge from the point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>The distance.</returns>
        public T GetDistanceToNearestEdge(Vector2D <T> point)
        {
            var max = Max;
            var dx  = Scalar.Max(Scalar.Max(Scalar.Subtract(Origin.X, point.X), Scalar <T> .Zero), Scalar.Subtract(point.X, max.X));
            var dy  = Scalar.Max(Scalar.Max(Scalar.Subtract(Origin.Y, point.Y), Scalar <T> .Zero), Scalar.Subtract(point.Y, max.Y));

            return(Scalar.Sqrt(Scalar.Add(Scalar.Multiply(dx, dx), Scalar.Multiply(dy, dy))));
        }
예제 #7
0
 public readonly bool Equals(Plane <T> other)
 {
     return(Normal.Equals(other.Normal) && Scalar.Equal(Distance, other.Distance));
 }
예제 #8
0
        /// <summary>
        /// Calculates whether this rectangle contains a point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <returns>True if this rectangle contains the point; False otherwise.</returns>
        /// <remarks>This does consider a point on the edge contained.</remarks>
        public bool Contains(Vector2D <T> point)
        {
            var max = Max;

            return(Scalar.GreaterThanOrEqual(point.X, Origin.X) && Scalar.GreaterThanOrEqual
                       (point.Y, Origin.Y) && Scalar.LessThanOrEqual(point.X, max.X) && Scalar.LessThanOrEqual(point.Y, max.Y));
        }
예제 #9
0
        /// <summary>Creates a matrix that rotates around an arbitrary vector.</summary>
        /// <param name="axis">The axis to rotate around.</param>
        /// <param name="angle">The angle to rotate around the given axis, in radians.</param>
        /// <returns>The rotation matrix.</returns>
        public static Matrix2X3 <T> CreateFromAxisAngle <T>(Vector3D <T> axis, T angle)
            where T : unmanaged, IFormattable, IEquatable <T>, IComparable <T>
        {
            // a: angle
            // x, y, z: unit vector for axis.
            //
            // Rotation matrix M can compute by using below equation.
            //
            //        T               T
            //  M = uu + (cos a)( I-uu ) + (sin a)S
            //
            // Where:
            //
            //  u = ( x, y, z )
            //
            //      [  0 -z  y ]
            //  S = [  z  0 -x ]
            //      [ -y  x  0 ]
            //
            //      [ 1 0 0 ]
            //  I = [ 0 1 0 ]
            //      [ 0 0 1 ]
            //
            //
            //     [  xx+cosa*(1-xx)   yx-cosa*yx-sina*z zx-cosa*xz+sina*y ]
            // M = [ xy-cosa*yx+sina*z    yy+cosa(1-yy)  yz-cosa*yz-sina*x ]
            //     [ zx-cosa*zx-sina*y zy-cosa*zy+sina*x   zz+cosa*(1-zz)  ]
            //
            T x = axis.X, y = axis.Y, z = axis.Z;
            T sa = Scalar.Sin(angle), ca = Scalar.Cos(angle);
            T xx = Scalar.Multiply(x, x), yy = Scalar.Multiply(y, y), zz = Scalar.Multiply(z, z);
            T xy = Scalar.Multiply(x, y), xz = Scalar.Multiply(x, z), yz = Scalar.Multiply(y, z);

            Matrix2X3 <T> result = Matrix2X3 <T> .Identity;

            result.M11 = Scalar.Add(xx, Scalar.Multiply(ca, Scalar.Subtract(Scalar <T> .One, xx)));
            result.M12 = Scalar.Add(Scalar.Subtract(xy, Scalar.Multiply(ca, xy)), Scalar.Multiply(sa, z));
            result.M13 = Scalar.Subtract(Scalar.Subtract(xz, Scalar.Multiply(ca, xz)), Scalar.Multiply(sa, y));

            result.M21 = Scalar.Subtract(Scalar.Subtract(xy, Scalar.Multiply(ca, xy)), Scalar.Multiply(sa, z));
            result.M22 = Scalar.Add(yy, Scalar.Multiply(ca, Scalar.Subtract(Scalar <T> .One, yy)));
            result.M23 = Scalar.Add(Scalar.Subtract(yz, Scalar.Multiply(ca, yz)), Scalar.Multiply(sa, x));

            return(result);
        }
예제 #10
0
 public static bool operator ==(Plane <T> value1, Plane <T> value2)
 => value1.Normal == value2.Normal && Scalar.Equal(value1.Distance, value2.Distance);
예제 #11
0
        /// <summary>Creates a rotation matrix from the given Quaternion rotation value.</summary>
        /// <param name="quaternion">The source Quaternion.</param>
        /// <returns>The rotation matrix.</returns>
        public static Matrix2X3 <T> CreateFromQuaternion <T>(Quaternion <T> quaternion)
            where T : unmanaged, IFormattable, IEquatable <T>, IComparable <T>
        {
            Matrix2X3 <T> result = Matrix2X3 <T> .Identity;

            T xx = Scalar.Multiply(quaternion.X, quaternion.X);
            T yy = Scalar.Multiply(quaternion.Y, quaternion.Y);
            T zz = Scalar.Multiply(quaternion.Z, quaternion.Z);

            T xy = Scalar.Multiply(quaternion.X, quaternion.Y);
            T wz = Scalar.Multiply(quaternion.Z, quaternion.W);
            T xz = Scalar.Multiply(quaternion.Z, quaternion.X);
            T wy = Scalar.Multiply(quaternion.Y, quaternion.W);
            T yz = Scalar.Multiply(quaternion.Y, quaternion.Z);
            T wx = Scalar.Multiply(quaternion.X, quaternion.W);

            result.M11 = Scalar.Subtract(Scalar <T> .One, Scalar.Multiply(Scalar <T> .Two, Scalar.Add(yy, zz)));
            result.M12 = Scalar.Multiply(Scalar <T> .Two, Scalar.Add(xy, wz));
            result.M13 = Scalar.Multiply(Scalar <T> .Two, Scalar.Subtract(xz, wy));

            result.M21 = Scalar.Multiply(Scalar <T> .Two, Scalar.Subtract(xy, wz));
            result.M22 = Scalar.Subtract(Scalar <T> .One, Scalar.Multiply(Scalar <T> .Two, Scalar.Add(zz, xx)));
            result.M23 = Scalar.Multiply(Scalar <T> .Two, Scalar.Add(yz, wx));

            return(result);
        }
예제 #12
0
파일: Sphere.cs 프로젝트: KangWeon/Silk.NET
 /// <summary>
 /// Calculates the squared distance to the nearest edge from the point.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>The distance squared.</returns>
 public T GetDistanceToNearestEdgeSquared(Vector3D <T> point)
 {
     return(Scalar.Subtract(Vector3D.DistanceSquared(Center, point), SquaredRadius));
 }
예제 #13
0
파일: Sphere.cs 프로젝트: KangWeon/Silk.NET
 /// <summary>
 /// Calculates whether this sphere contains a point.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>True if this sphere contains the point; False otherwise.</returns>
 /// <remarks>This does consider a point on the edge contained.</remarks>
 public bool Contains(Vector3D <T> point)
 {
     return(Scalar.LessThanOrEqual(Vector3D.DistanceSquared(point, Center), Radius));
 }
예제 #14
0
파일: Sphere.cs 프로젝트: KangWeon/Silk.NET
 /// <summary>
 /// Returns this sphere casted to <typeparamref name="TOther"></typeparamref>
 /// </summary>
 /// <typeparam name="TOther">The type to cast to</typeparam>
 /// <returns>The casted sphere</returns>
 public Sphere <TOther> As <TOther>() where TOther : unmanaged, IFormattable, IEquatable <TOther>, IComparable <TOther>
 {
     return(new(Center.As <TOther>(), Scalar.As <T, TOther>(Radius)));
 }
예제 #15
0
파일: Sphere.cs 프로젝트: KangWeon/Silk.NET
 /// <summary>
 /// Calculates the distance to the nearest edge from the point.
 /// </summary>
 /// <param name="point">The point.</param>
 /// <returns>The distance.</returns>
 public T GetDistanceToNearestEdge(Vector3D <T> point) => Scalar.Sqrt(GetDistanceToNearestEdgeSquared(point));