예제 #1
0
 public static double CalcDistanceBetween3DPoints(Point3D p1, Point3D p2)
 {
     double distance = Math.Sqrt((p2.X - p1.X) * (p2.X - p1.X) +
                                 (p2.Y - p1.Y) * (p2.Y - p1.Y) +
                                 (p2.Z - p1.Z) * (p2.Z - p1.Z));
     return distance;
 }
예제 #2
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));
        }
        static void Main()
        {
            Console.WriteLine(StringUtils.GetFileExtension("example"));
            Console.WriteLine(StringUtils.GetFileExtension("example.pdf"));
            Console.WriteLine(StringUtils.GetFileExtension("example.new.pdf"));

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

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

            double width = 3;
            double height = 4;
            double depth = 5;
            Point3D start = new Point3D();
            Point3D end = new Point3D(width, height, depth);

            Console.WriteLine("Volume = {0:f2}", MathUtils.CalcParallelepipedVolume(width, height, depth));
            Console.WriteLine("Diagonal XYZ = {0:f2}", MathUtils.ParallelepipedCalcDiagonalXYZ(start, end));
            Console.WriteLine("Diagonal XY = {0:f2}", MathUtils.ParallelepipedCalcDiagonalXY(start, end));
            Console.WriteLine("Diagonal XZ = {0:f2}", MathUtils.ParallelepipedCalcDiagonalXZ(start, end));
            Console.WriteLine("Diagonal YZ = {0:f2}", MathUtils.ParallelepipedCalcDiagonalYZ(start, end));
        }
예제 #4
0
파일: Examples.cs 프로젝트: abaditsegay/SVN
        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 static double GetDistance(Point3D first, Point3D second)
        {
            double distance = Math.Sqrt((second.X - first.X) * (second.X - first.X) +
                (second.Y - first.Y) * (second.Y - first.Y) +
                (second.Z - first.Z) * (second.Z - first.Z));

            return distance;
        }
예제 #6
0
 /// <summary>
 /// Calculates the volume of square shape by using coordinates of the four <see cref="Point3D"/>s.
 /// </summary>
 /// <param name="pointOne">Coordinates of the first <see cref="Point3D"/>.</param>
 /// <param name="pointTwo">Coordinates of the second <see cref="Point3D"/>.</param>
 /// <param name="pointThree">Coordinates of the third <see cref="Point3D"/>.</param>
 /// <param name="pointFour">Coordinates of the fourth <see cref="Point3D"/>.</param>
 /// <returns>Returns the volume of square shape.</returns>
 public static double CalcVolume(Point3D pointOne, Point3D pointTwo, Point3D pointThree, Point3D pointFour)
 {
     double sideA = CalculateDistance(pointOne, pointTwo);
     double sideB = CalculateDistance(pointOne, pointThree);
     double sideC = CalculateDistance(pointOne, pointFour);
     double volume = sideA * sideB * sideC;
     return volume;
 }
예제 #7
0
        public double CalcDistance3D(Point3D a, Point3D b)
        {
            double distance = Math.Sqrt(
                ((b.X - a.X) * (b.X - a.X)) +
                ((b.Y - a.Y) * (b.Y - a.Y)) +
                ((b.Z - a.Z) * (b.Z - a.Z)));

            return distance;
        }
예제 #8
0
        public static double CalculateDistance3D(Point3D firstPoint, Point3D secondPoint)
        {
            double diferenceX = Math.Pow(secondPoint.X - firstPoint.X, 2);
            double diferenceY = Math.Pow(secondPoint.Y - firstPoint.Y, 2);
            double diferenceZ = Math.Pow(secondPoint.Z - firstPoint.Z, 2);

            double distance = Math.Sqrt(diferenceX + diferenceY + diferenceZ);
            return distance;
        }
예제 #9
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;
        }
예제 #10
0
        public static double CalcDistance3D(Point3D first, Point3D second)
        {
            double xDistance = first.X - second.X;
            double yDistance = first.Y = second.Y;
            double zDistance = first.Z = second.Z;
            double distance = Math.Sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);

            return distance;
        }
예제 #11
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));
        }
예제 #12
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());
            }
        }
        public static double CalcDistance3D(Point3D pointOne, Point3D pointTwo)
        {
            if (pointOne == null)
            {
                throw new ArgumentNullException("Point one cannot be null");
            }

            if (pointTwo == null)
            {
                throw new ArgumentNullException("Point two cannot be null");
            }

            double widthDistance = (pointTwo.X - pointOne.X) * (pointTwo.X - pointOne.X);
            double heightDistance = (pointTwo.Y - pointOne.Y) * (pointTwo.Y - pointOne.Y);
            double depthDistance = (pointTwo.Z - pointOne.Z) * (pointTwo.Z - pointOne.Z);

            double distance = widthDistance + heightDistance + depthDistance;
            distance = Math.Sqrt(distance);
            return distance;
        }
예제 #14
0
 public static double ParallelepipedCalcDiagonalXYZ(Point3D start, Point3D end)
 {
     double distance = CalcDistance3D(start, end);
     return distance;
 }
예제 #15
0
 /// <summary>
 /// Calculates the distance between points in XY plane
 /// </summary>
 internal static double CalcDistance2D(Point3D p1, Point3D p2)
 {
     double distance = Math.Sqrt(((p2.X - p1.X) * (p2.X - p1.X)) + ((p2.Y - p1.Y) * (p2.Y - p1.Y)));
     return distance;
 }