//-------------------------------------------------------------------------------------------
        //Ближайшая точка эллипса
        public Point2D GetNearestEllipsePoint(Point2D point)
        {
            double a = this.radiusX;
            double b = this.radiusY;

            double x = point.X;
            double y = point.Y;

            double a0 = (b * b * b * b * y * y) / (a * a);
            double a1 = 2 * b * b * (1 - (b * b) / (a * a)) * y;
            double a2 =
                a * a - 2 * b * b - x * x + (b * b * b * b) / (a * a) -
                (b * b * y * y) / (a * a);
            double a3 = 2 * ((b * b) / (a * a) - 1) * y;
            double a4 = -Math.Pow((a * a - b * b) / (a * b), 2);

            Complex[] roots        = QuarticEquation.GetRoots(a4, a3, a2, a1, a0);
            Complex[] integerRoots = NumbersManager.GetNumbersWithZeroImaginaryPart(roots);

            double[] coordinatesY = NumbersManager.GetRealParts(integerRoots);
            double[] coordinatesX = this.GetCoordinatesXOfPossiblePoints(point, coordinatesY);

            Point2D[] possiblePoints = PlaneManager.CreatePoints2D(coordinatesX, coordinatesY);
            Point2D[] ellipsePoints  = this.SelectPoints(possiblePoints, 0.01);

            Point2D nearestPoint = PlaneManager.GetNearestPoint(point, ellipsePoints);

            return(nearestPoint);
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------
        //Перемещение точек в первый квадрант
        public static Point2D[] DisplacePointsToFirstQuadrant(Point2D[] points)
        {
            double[] minimalCoordinates = PlaneManager.GetMinimalCoordinates(points);
            double   displacementX      = minimalCoordinates[0];
            double   displacementY      = minimalCoordinates[1];

            Point2D[] newPoints = PlaneManager.DisplacePoints(points, -displacementX, -displacementY);
            return(newPoints);
        }
Example #3
0
 //-----------------------------------------------------------------------------------------------
 //Расстояния между точками массива и заданной точкой
 public static double[] GetDistances(Point2D[] points, Point2D targetPoint)
 {
     double[] distances = new double[points.Length];
     for (int index = 0; index < points.Length; index++)
     {
         Point2D point    = points[index];
         double  distance = PlaneManager.DistanceBetweenTwoPoints(point, targetPoint);
         distances[index] = distance;
     }
     return(distances);
 }
Example #4
0
        //-----------------------------------------------------------------------------------------------
        //Минимальные координаты точек
        public static double[] GetMinimalCoordinates(Point2D[] points)
        {
            double[] coordinatesX = PlaneManager.GetCoordinatesX(points);
            double[] coordinatesY = PlaneManager.GetCoordinatesY(points);

            double minX = coordinatesX.Min();
            double minY = coordinatesY.Min();

            double[] minimalCoordinates = new double[] { minX, minY };
            return(minimalCoordinates);
        }
Example #5
0
 //----------------------------------------------------------------------------------------------
 //Повернуть векторы
 public static RealVector[] RotateVectros(
     RealVector[] vectors,
     RealMatrix rotationMatrix
     )
 {
     RealVector[] newVectors = new RealVector[vectors.Length];
     for (int index = 0; index < vectors.Length; index++)
     {
         RealVector vector    = vectors[index];
         RealVector newVector = PlaneManager.RotateVector(vector, rotationMatrix);
         newVectors[index] = newVector;
     }
     return(newVectors);
 }
Example #6
0
        //-----------------------------------------------------------------------------------------------
        //Выбрать ближайшую к данной точке точку из массива
        public static Point2D GetNearestPoint(Point2D point, Point2D[] points)
        {
            if (points.Length == 1)
            {
                return(points[0]);
            }
            Point2D nearestPoint = points[0];
            double  minDistance  = PlaneManager.DistanceBetweenTwoPoints(point, nearestPoint);

            for (int index = 1; index < points.Length; index++)
            {
                Point2D currentPoint = points[index];
                double  distance     = PlaneManager.DistanceBetweenTwoPoints(point, currentPoint);
                if (distance < minDistance)
                {
                    minDistance  = distance;
                    nearestPoint = currentPoint;
                }
            }
            return(nearestPoint);
        }
Example #7
0
        //------------------------------------------------------------------------------------------------
        //Расстояние до заданной точки
        public double GetDistanceToPoint(Point2D point)
        {
            double distance = PlaneManager.DistanceBetweenTwoPoints(this, point);

            return(distance);
        }