コード例 #1
0
        } // End Property Slope


        // https://stackoverflow.com/questions/17692922/check-is-a-point-x-y-is-between-two-points-drawn-on-a-straight-line
        public bool IsPointOnLine(MyPoint2D <T> p)
        {
            T norm = this.Vector.MagnitudeSquared;
            MyVector2D <T> vec1 = new MyVector2D <T>(this.m_start, p);
            MyVector2D <T> vec2 = new MyVector2D <T>(this.m_end, p);

            T dist = Arithmetics <T> .Add(vec1.MagnitudeSquared, vec2.MagnitudeSquared);

            if (norm.Equals(dist))
            {
                return(true);
            }

            T delta = Arithmetics <T> .Subtract(vec1.MagnitudeSquared, vec2.MagnitudeSquared);

            decimal decDelta = System.Convert.ToDecimal(delta);

            decDelta = System.Math.Abs(decDelta);

            // Greatest possible floating-point difference
            decimal decFloatEpsilon = System.Convert.ToDecimal(float.Epsilon);

            if (decDelta <= decFloatEpsilon)
            {
                return(true);
            }

            return(false);
        } // End Function IsPointOnLine
コード例 #2
0
        } // End Function IsPointOnLine

        public static MyVector2D <T> ToVector(MyPoint2D <T> start, MyPoint2D <T> end)
        {
            T x = Arithmetics <T> .Subtract(end.X, start.X);

            T y = Arithmetics <T> .Subtract(end.Y, start.Y);

            return(new MyVector2D <T>(x, y));
        } // End Function ToVector
コード例 #3
0
ファイル: Line3D.cs プロジェクト: ststeiger/AnySqlWebAdmin
        public MyVector3D(MyPoint3D <T> a, MyPoint3D <T> b)
        {
            this.X = Arithmetics <T> .Subtract(a.X, b.X);

            this.Y = Arithmetics <T> .Subtract(a.Y, b.Y);

            this.Z = Arithmetics <T> .Subtract(a.Z, b.Z);
        } // End Constructor
コード例 #4
0
        } // End Function Schnittpunktli

        // https://en.wikipedia.org/wiki/Determinant
        // | a  b |
        // | c  d |
        private static T Determinant2d(T a, T b, T c, T d)
        {
            T f1 = Arithmetics <T> .Multiply(a, d);

            T f2 = Arithmetics <T> .Multiply(b, c);

            T result = Arithmetics <T> .Subtract(f1, f2);

            return(result);
        } // End Function Determinant2d
コード例 #5
0
        } // End Operator +

        public static MyVector2D <T> operator -(MyVector2D <T> a, MyVector2D <T> b)
        {
            MyVector2D <T> v = a.Clone();

            v.X = Arithmetics <T> .Subtract(v.X, b.X);

            v.Y = Arithmetics <T> .Subtract(v.Y, b.Y);

            return(v);
        } // End Operator -
コード例 #6
0
        } // End Property NormalVector


        // http://mathworld.wolfram.com/CrossProduct.html
        // the cross product is a vector that is perpendicular to both
        // a and b and thus normal to the plane containing them
        // |u x v| = |u| x |v| * sin(phi)
        public static T CrossP(MyVector2D <T> a, MyVector2D <T> b)
        {
            // crossp = det(a,b) = a.X*b.Y- a.Y*b.X
            T s1 = Arithmetics <T> .Multiply(a.X, b.Y);

            T s2 = Arithmetics <T> .Multiply(a.Y, b.X);

            T retValue = Arithmetics <T> .Subtract(s1, s2);

            return(retValue);
        } // End function CrossP
コード例 #7
0
        public void Test_0_subtract_0()
        {
            // Arrange
            var a = new Byte2(0);
            var b = new Byte2(0);

            // Act
            var byteResult = Arithmetics.Subtract(a, b);

            // Assert
            byteResult.ToInt16().Should().Be(0);
        }
コード例 #8
0
        public void Test_MinValue_subtract_1()
        {
            // Arrange
            var a = new Byte2(short.MinValue);
            var b = new Byte2(1);

            // Act
            var byteResult = Arithmetics.Subtract(a, b);

            // Assert
            byteResult.ToInt16().Should().Be(short.MaxValue);
        }
コード例 #9
0
        } // End Function ToString

        /// <summary>
        /// Returns a new Vector that is the linear blend of the 2 given Vectors
        /// </summary>
        /// <param name="a">First input vector</param>
        /// <param name="b">Second input vector</param>
        /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
        /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
        public static MyPoint2D <T> Lerp(MyPoint2D <T> a, MyPoint2D <T> b, T blend)
        {
            T bxax = Arithmetics <T> .Subtract(b.X, a.X);

            T byay = Arithmetics <T> .Subtract(b.Y, a.Y);

            T f1 = Arithmetics <T> .Multiply(blend, bxax);

            T f2 = Arithmetics <T> .Multiply(blend, byay);

            T x = Arithmetics <T> .Add(f1, a.X);

            T y = Arithmetics <T> .Add(f2, a.Y);

            return(new MyPoint2D <T>(x, y));
        } // End Function Lerp
コード例 #10
0
ファイル: Line3D.cs プロジェクト: ststeiger/AnySqlWebAdmin
        } // End Function ToString

        /// <summary>
        /// Returns a new Vector that is the linear blend of the 2 given Vectors
        /// </summary>
        /// <param name="a">First input vector</param>
        /// <param name="b">Second input vector</param>
        /// <param name="blend">The blend factor. a when blend=0, b when blend=1.</param>
        /// <returns>a when blend=0, b when blend=1, and a linear combination otherwise</returns>
        public static MyVector3D <T> Lerp(MyVector3D <T> a, MyVector3D <T> b, T blend)
        {
            T bxax = Arithmetics <T> .Subtract(b.X, a.X);

            T byay = Arithmetics <T> .Subtract(b.Y, a.Y);

            T bzaz = Arithmetics <T> .Subtract(b.Z, a.Z);

            T f1 = Arithmetics <T> .Multiply(blend, bxax);

            T f2 = Arithmetics <T> .Multiply(blend, byay);

            T f3 = Arithmetics <T> .Multiply(blend, bzaz);

            T x = Arithmetics <T> .Add(f1, a.X);

            T y = Arithmetics <T> .Add(f2, a.Y);

            T z = Arithmetics <T> .Add(f3, a.Z);

            return(new MyVector3D <T>(x, y, z));
        } // End Function Lerp
コード例 #11
0
ファイル: Line3D.cs プロジェクト: ststeiger/AnySqlWebAdmin
        } // End Function GetNormalVector

        /// <summary>
        /// Returns the CrossProduct.
        /// </summary>
        /// <returns>Vector&lt;T&gt; containing the value of the CrossProduct.</returns>
        public static MyVector3D <T> CrossP(MyVector3D <T> a, MyVector3D <T> b)
        {
            T x1 = Arithmetics <T> .Multiply(a.Y, b.Z);

            T x2 = Arithmetics <T> .Multiply(a.Z, b.Y);


            T y1 = Arithmetics <T> .Multiply(a.Z, b.X);

            T y2 = Arithmetics <T> .Multiply(a.X, b.Z);

            T z1 = Arithmetics <T> .Multiply(a.X, b.Y);

            T z2 = Arithmetics <T> .Multiply(a.Y, b.X);

            //A × B = [(ay*bz-az*by),(az*bx-ax*bz),(ax*by-ay*bx)]
            MyVector3D <T> vecReturnValue = new MyVector3D <T>(
                Arithmetics <T> .Subtract(x1, x2)
                , Arithmetics <T> .Subtract(y1, y2)
                , Arithmetics <T> .Subtract(z1, z2)
                );

            return(vecReturnValue);
        } // End function CrossP