Пример #1
0
        public static void Main()
        {
            Console.WriteLine(FileUtils.GetFileExtension("example"));
            Console.WriteLine(FileUtils.GetFileExtension("example.pdf"));
            Console.WriteLine(FileUtils.GetFileExtension("example.new.pdf"));

            Console.WriteLine(FileUtils.GetFileNameWithoutExtension("example"));
            Console.WriteLine(FileUtils.GetFileNameWithoutExtension("example.pdf"));
            Console.WriteLine(FileUtils.GetFileNameWithoutExtension("example.new.pdf"));

            var pointOne2D = new Point2D(1, -2);
            var pointTwo2D = new Point2D(3, 4);
            Console.WriteLine("Distance in the 2D space = {0:f2}", GraphicUtils.CalculateDistance(pointOne2D, pointTwo2D));
            var pointOne3D = new Point3D(5, 2, -1);
            var pointTwo3D = new Point3D(3, -6, 4);
            Console.WriteLine("Distance in the 3D space = {0:f2}", GraphicUtils.CalculateDistance(pointOne3D, pointTwo3D));

            pointOne3D = new Point3D(0, 0, 0);
            pointTwo3D = new Point3D(1, 0, 0);
            var pointThree3D = new Point3D(0, 1, 0);
            var pointFour3D = new Point3D(0, 0, 1);
            var farPoint3D = new Point3D(1, 1, 1);

            Console.WriteLine("Volume = {0:f2}", GraphicUtils.CalcVolume(pointOne3D, pointTwo3D, pointThree3D, pointFour3D));
            Console.WriteLine("Diagonal XYZ = {0:f2}", GraphicUtils.CalcDistanceToCenter(farPoint3D));
            Console.WriteLine("Diagonal XY = {0:f2}", GraphicUtils.CalcDistanceToCenter(pointTwo3D));
            Console.WriteLine("Diagonal XZ = {0:f2}", GraphicUtils.CalcDistanceToCenter(pointFour3D));
            Console.WriteLine("Diagonal YZ = {0:f2}", GraphicUtils.CalculateDistance(pointThree3D, pointFour3D));
        }
Пример #2
0
        public static double GetDistance(Point2D first, Point2D second)
        {
            double distance = Math.Sqrt((second.X - first.X) * (second.X - first.X) +
                (second.Y - first.Y) * (second.Y - first.Y));

            return distance;
        }
Пример #3
0
        /// <summary>
        /// Calculates distance between two Points in space (2D or 3D).  
        /// Accepts both <see cref="Point2D"/> or <see cref="Point3D"/> and  
        /// calculation is done in 2D space or in 3D space. In one call to method,
        /// both parameters need to be from one and the same type, otherwise an 
        /// <see cref="ArgumentException"/> is thrown.
        /// </summary>
        /// <param name="pointOne">Coordinates of the first Point.</param>
        /// <param name="pointTwo">Coordinates of the second Point.</param>
        /// <exception cref="ArgumentNullException">Thrown when one or both of the provided arguments is/are null.</exception>
        /// <exception cref="ArgumentException">Thrown when provided parameters are not from one and the same type.</exception>
        /// <returns>Distance between two Points.</returns>
        public static double CalculateDistance(Point2D pointOne, Point2D pointTwo)
        {
            if (pointOne != null && pointTwo != null)
            {
                if (pointOne.GetType().Name == pointTwo.GetType().Name)
                {
                    double distance;
                    double deltaX = pointTwo.CoordinateX - pointOne.CoordinateX;
                    double deltaY = pointTwo.CoordinateY - pointOne.CoordinateY;
                    if (pointOne.GetType() == typeof(Point3D))
                    {
                        var pointOne3D = pointOne as Point3D;
                        var pointTwo3D = pointTwo as Point3D;
                        double deltaZ = pointTwo3D.CoordinateZ - pointOne3D.CoordinateZ;
                        distance = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));
                    }
                    else
                    {
                        distance = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
                    }

                    return distance;
                }

                throw new ArgumentException("Both points need to be from one and the saame type!");
            }

            throw new ArgumentNullException("Point(s) cannot be null!");
        }
Пример #4
0
        static void Main()
        {
            Console.WriteLine(FileWorker.GetFileExtension("example.new.pdf"));
            Console.WriteLine(FileWorker.GetFileName("example.pdf"));

            var firstPoint = new Point2D(0, 10);
            var secondPoint = new Point2D(15, 15);
            var distance = PointMath.GetDistance(firstPoint, secondPoint);
            Console.Write("Distance between two points 2D: ");
            Console.WriteLine("{0:f2}", distance);

            var firstPoint3D = new Point3D(0, 10, 15);
            var secondPoint3D = new Point3D(0, 0, 0);
            var distance3D = PointMath.GetDistance(firstPoint3D, secondPoint3D);
            Console.Write("Distance between two points 3D: ");
            Console.WriteLine("{0:f2}", distance3D);

            var rectangle = new Rectangle(10, 10);
            Console.Write("Diagonal of the 2d rectangle: ");
            Console.WriteLine("{0:f2}", rectangle.CalculateDiagonal());

            var cube = new Cube(10, 20, 30);
            Console.Write("Volume of the cube: ");
            Console.WriteLine("{0:f2}", cube.CalculateVolume());
            Console.WriteLine("Two of the diagonals of the cube are: ");
            Console.WriteLine("{0:f2}", cube.CalculateDiagonalXYZ());
            Console.WriteLine("{0:f2}", cube.CalculateDiagonalXZ());
        }
Пример #5
0
        public double CalcDistance2D(Point2D a, Point2D b)
        {
            double distance = Math.Sqrt(
                ((b.X - a.X) * (b.X - a.X)) +
                ((b.Y - a.Y) * (b.Y - a.Y)));

            return distance;
        }
Пример #6
0
        public static double CalculateDistance2D(Point2D firstPoint, Point2D secondPoint)
        {
            double diferenceX = Math.Pow(secondPoint.X - firstPoint.X, 2);
            double diferenceY = Math.Pow(secondPoint.Y - firstPoint.Y, 2);

            double distance = Math.Sqrt(diferenceX + diferenceY);
            return distance;
        }
Пример #7
0
        public static double CalcDistance2D(Point2D first, Point2D second)
        {
            double xDistance = first.X - second.X;
            double yDistance = first.Y = second.Y;
            double distance = Math.Sqrt(xDistance * xDistance + yDistance * yDistance);

            return distance;
        }
Пример #8
0
        public static double ParallelepipedCalcDiagonalYZ(Point3D start, Point3D end)
        {
            Point2D start2D = new Point2D(start.Y, start.Z);
            Point2D end2D = new Point2D(end.Y, end.Z);

            double distance = CalcDistance2D(start2D, end2D);

            return distance;
        }
Пример #9
0
        public static void Main()
        {
            IGeometryUtils geometryUtils = new GeometryUtils();
            IFileUtils fileUtils = new FileUtils();

            string[] fileNames = { "example", "example.pdf", "example.new.pdf" };

            foreach (string fileName in fileNames)
            {
                try
                {
                    Console.WriteLine(fileUtils.GetFileExtension(fileName));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            foreach (string fileName in fileNames)
            {
                try
                {
                    Console.WriteLine(fileUtils.GetFileNameWithoutExtension(fileName));
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Point2D firstPoint2D = new Point2D(1, -2);
            Point2D secondPoint2D = new Point2D(3, 4);
            Console.WriteLine(
                "Distance in the 2D space = {0:f2}",
                geometryUtils.CalcDistance2D(firstPoint2D, secondPoint2D));

            Point3D firstPoint3D = new Point3D(5, 2, -1);
            Point3D secondPoint3D = new Point3D(3, -6, 4);
            Console.WriteLine(
                "Distance in the 3D space = {0:f2}",
                geometryUtils.CalcDistance3D(firstPoint3D, secondPoint3D));

            double width = 3;
            double height = 4;
            double depth = 5;
            Volume volume = new Volume(width, height, depth);

            Console.WriteLine("Volume = {0:f2}", volume.CalcVolume());
            Console.WriteLine("Diagonal XYZ = {0:f2}", volume.CalcDiagonalXYZ(geometryUtils));
            Console.WriteLine("Diagonal XY = {0:f2}", volume.CalcDiagonalXY(geometryUtils));
            Console.WriteLine("Diagonal XZ = {0:f2}", volume.CalcDiagonalXZ(geometryUtils));
            Console.WriteLine("Diagonal YZ = {0:f2}", volume.CalcDiagonalYZ(geometryUtils));
        }
Пример #10
0
        /// <summary>
        /// Calculates distance between Point (2D or 3D) and center of coordinate system.
        /// </summary>
        /// <param name="point">Coordinates of the point.</param>
        /// <returns>Distance between the point and coordinate system center.</returns>
        public static double CalcDistanceToCenter(Point2D point)
        {
            if (point != null)
            {
                var center = point.GetType() == typeof(Point3D) ? new Point3D(0, 0, 0) : new Point2D(0, 0);
                double distance = CalculateDistance(center, point);
                return distance;
            }

            throw new ArgumentNullException("Point can not be with a null value!");
        }
Пример #11
0
        static void Main(string[] args)
        {
            // Tests for file extraction methods
            {
                Console.WriteLine(FileExtractor.GetFileExtension("example"));
                Console.WriteLine(FileExtractor.GetFileExtension("example.pdf"));
                Console.WriteLine(FileExtractor.GetFileExtension("example.new.pdf"));

                Console.WriteLine(FileExtractor.GetFileNameWithoutExtension("example"));
                Console.WriteLine(FileExtractor.GetFileNameWithoutExtension("example.pdf"));
                Console.WriteLine(FileExtractor.GetFileNameWithoutExtension("example.new.pdf"));
            }

            Console.WriteLine();

            // Tests for 2D point methods
            {
                Point2D firstPoint2D = new Point2D(2, 2);
                Point2D secondPoint2D = new Point2D(3, 3);

                double distance = Point2D.CalcDistanceBetween2DPoints(firstPoint2D, secondPoint2D);

                Console.WriteLine("Distance in the 2D space = {0:f2}", distance);
                Console.WriteLine("Diagonal XY = {0:f2}", firstPoint2D.CalcDiagonalXY());
            }

            Console.WriteLine();

            // Tests for 3D point methods
            {
                Point3D firstPoint3D = new Point3D(1, 2, 3);
                Point3D secondPoint3D = new Point3D(4, 5, 6);

                double distance = Point3D.CalcDistanceBetween3DPoints(firstPoint3D, secondPoint3D);
                Console.WriteLine("Distance in the 3D space = {0:f2}", distance);

                // To calculate the Volume we should first create a 3D figure - i.e. a rectangular parallelepiped
                // which has width, height and depth.
                // GeometryMethods.CalcVolume(myParallepiped.Width, myParallepiped.Height, myParallepiped.Depth));
                Console.WriteLine("Diagonal XYZ = {0:f2}", firstPoint3D.CalcDiagonalXYZ());
                Console.WriteLine("Diagonal XY = {0:f2}", firstPoint3D.CalcDiagonalXY());
                Console.WriteLine("Diagonal XZ = {0:f2}", firstPoint3D.CalcDiagonalXZ());
                Console.WriteLine("Diagonal YZ = {0:f2}", firstPoint3D.CalcDiagonalYZ());
            }
        }
Пример #12
0
 public static double CalcDistanceBetween2DPoints(Point2D p1, Point2D p2)
 {
     double distance = Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) +
                                 (p2.Y - p1.Y) * (p2.Y - p1.Y));
     return distance;
 }