Exemple #1
0
        /// <summary>
        /// Create a 2-dimensional line of type T.
        /// </summary>
        /// <param name="Pixel">A pixel of type T.</param>
        /// <param name="X">The x-component.</param>
        /// <param name="Y">The y-component.</param>
        public Line2D(IPixel <T> Pixel, T X, T Y)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given pixel must not be null!");
            }

            if (X == null)
            {
                throw new ArgumentNullException("The given x-component must not be null!");
            }

            if (Y == null)
            {
                throw new ArgumentNullException("The given y-component must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.X1 = Pixel.X;
            this.Y1 = Pixel.Y;
            this.X2 = Math.Add(Pixel.X, X);
            this.Y2 = Math.Add(Pixel.Y, Y);

            this.Pixel1 = new Pixel <T>(X1, Y1);
            this.Pixel2 = new Pixel <T>(X2, Y2);

            this.Length = Pixel1.DistanceTo(Pixel2);
        }
Exemple #2
0
        /// <summary>
        /// Create a rectangle of type T.
        /// </summary>
        /// <param name="Pixel">A pixel of type T in the upper left corner of the rectangle.</param>
        /// <param name="Width">The width of the rectangle.</param>
        /// <param name="Height">The height of the rectangle.</param>
        public Rectangle(IPixel <T> Pixel, T Width, T Height)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given pixel must not be null!");
            }

            if (Width == null || Width.Equals(Math.Zero))
            {
                throw new ArgumentNullException("The given width must not be null or zero!");
            }

            if (Height == null || Height.Equals(Math.Zero))
            {
                throw new ArgumentNullException("The given height must not be null or zero!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.Left   = Pixel.X;
            this.Top    = Pixel.Y;
            this.Right  = Math.Add(Pixel.X, Width);
            this.Bottom = Math.Add(Pixel.Y, Height);

            this.Pixel1 = new Pixel <T>(Left, Top);
            this.Pixel2 = new Pixel <T>(Right, Bottom);

            this.Width    = Math.Distance(Left, Right);
            this.Height   = Math.Distance(Top, Bottom);
            this.Diameter = Pixel1.DistanceTo(Pixel2);
        }
Exemple #3
0
        /// <summary>
        /// A method to calculate the distance between this
        /// voxel and the given coordinates of type T.
        /// </summary>
        /// <param name="x">A x-coordinate of type T</param>
        /// <param name="y">A y-coordinate of type T</param>
        /// <param name="z">A z-coordinate of type T</param>
        /// <returns>The distance between this voxel and the given coordinates.</returns>
        public T DistanceTo(T x, T y, T z)
        {
            #region Initial Checks

            if (x == null)
            {
                throw new ArgumentNullException("The given x-coordinate must not be null!");
            }

            if (y == null)
            {
                throw new ArgumentNullException("The given y-coordinate must not be null!");
            }

            if (z == null)
            {
                throw new ArgumentNullException("The given z-coordinate must not be null!");
            }

            #endregion

            var dX = Math.Distance(X, x);
            var dY = Math.Distance(Y, y);
            var dZ = Math.Distance(Z, z);

            return(Math.Sqrt(Math.Add(Math.Mul(dX, dX), Math.Mul(dY, dY), Math.Mul(dZ, dZ))));
        }
Exemple #4
0
        /// <summary>
        /// Create a cube of type T.
        /// </summary>
        /// <param name="Voxel">A Voxel of type T in the upper left front corner of the cube.</param>
        /// <param name="Width">The width of the cube.</param>
        /// <param name="Height">The height of the cube.</param>
        /// <param name="Depth">The depth of the cube.</param>
        public Cube(Voxel <T> Voxel, T Width, T Height, T Depth)
        {
            #region Initial Checks

            if (Voxel == null)
            {
                throw new ArgumentNullException("The given voxel must not be null!");
            }

            if (Width == null)
            {
                throw new ArgumentNullException("The given width must not be null!");
            }

            if (Height == null)
            {
                throw new ArgumentNullException("The given height must not be null!");
            }

            if (Depth == null)
            {
                throw new ArgumentNullException("The given depth must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Math.Distance(Left, Right).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting width must not be zero!");
            }

            if (Math.Distance(Top, Bottom).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting height must not be zero!");
            }

            if (Math.Distance(Front, Behind).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting depth must not be zero!");
            }

            #endregion

            this.Left   = Voxel.X;
            this.Top    = Voxel.Y;
            this.Front  = Voxel.Z;
            this.Right  = Math.Add(Voxel.X, Width);
            this.Bottom = Math.Add(Voxel.Y, Height);
            this.Behind = Math.Add(Voxel.Z, Depth);
        }
Exemple #5
0
        /// <summary>
        /// Checks if the given pixel is located on this line.
        /// </summary>
        /// <param name="Pixel">A pixel of type T.</param>
        /// <returns>True if the pixel is located on this line; False otherwise.</returns>
        public Boolean Contains(IPixel <T> Pixel)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given pixel must not be null!");
            }

            #endregion

            #region Check line bounds

            if (Pixel.X.IsLessThan(X1) && Pixel.X.IsLessThan(X2))
            {
                return(false);
            }

            if (Pixel.X.IsLargerThan(X1) && Pixel.X.IsLargerThan(X2))
            {
                return(false);
            }

            if (Pixel.Y.IsLessThan(Y1) && Pixel.Y.IsLessThan(Y2))
            {
                return(false);
            }

            if (Pixel.Y.IsLargerThan(Y1) && Pixel.Y.IsLargerThan(Y2))
            {
                return(false);
            }

            #endregion

            // Check equation: Pixel.Y = m*Pixel.X + t
            return(Pixel.Y.Equals(Math.Add(Math.Mul(Gradient, Pixel.X), YIntercept)));
        }
Exemple #6
0
        /// <summary>
        /// A method to add vectors.
        /// </summary>
        /// <param name="Summands">An array of vectors.</param>
        /// <returns>The addition of all summands: v1 + v2 + ...</returns>
        public IVector2D <T> Add(params IVector2D <T>[] Summands)
        {
            if (Summands == null || Summands.Length == 0)
            {
                throw new ArgumentException("The given summands must not be null!");
            }

            if (Summands.Length == 1)
            {
                return(Summands[0]);
            }

            var _X = Summands[0].X;
            var _Y = Summands[0].Y;

            for (var i = Summands.Length - 1; i >= 1; i--)
            {
                _X = Math.Add(_X, Summands[i].X);
                _Y = Math.Add(_Y, Summands[i].Y);
            }

            return(new Vector2D <T>(Math.Zero, Math.Zero, _X, _Y));
        }
Exemple #7
0
        /// <summary>
        /// Checks if the given circle shares some
        /// area with this circle.
        /// </summary>
        /// <param name="Circle">A circle of type T.</param>
        /// <returns>True if the circle shares some area with this circle; False otherwise.</returns>
        public Boolean Overlaps(ICircle <T> Circle)
        {
            #region Initial Checks

            if (Circle == null)
            {
                throw new ArgumentNullException("The given circle must not be null!");
            }

            #endregion

            if (Center.DistanceTo(Circle.Center).IsLessThanOrEquals(Math.Add(Radius, Circle.Radius)))
            {
                return(true);
            }

            return(true);
        }
Exemple #8
0
 public double GetInterest(double principalAmount, int Year, double rate, int n) =>
 Maths.Multiply(principalAmount, Math.Pow(Maths.Add(1, Maths.Divide(rate, n)), Maths.Multiply(n, Year)));