//-------------------------------------------------------------------------------------------- //Проверка параллельности прямых public static bool AreLinesParallel(LineDescriptor lineOne, LineDescriptor lineTwo) { bool isParallel = (lineOne.coefficientOfX / lineOne.coefficientOfY) == (lineTwo.coefficientOfX / lineTwo.coefficientOfY); return(isParallel); }
//----------------------------------------------------------------------------------------------- //Расстояние от точки до прямой public static double DistanceFromPointToLine(Point2D point, LineDescriptor lineDescriptor) { double a = lineDescriptor.CoefficientOfX; double b = lineDescriptor.CoefficientOfY; double c = lineDescriptor.AbsoluteTerm; double distance = (a * point.X + b * point.Y + c) / Math.Sqrt(a * a + b * b); return(distance); }
//----------------------------------------------------------------------------------------------- //Прямя по двум точкам public static LineDescriptor GetLineDescriptor(Point2D pointOne, Point2D pointTwo) { double coefficientOfX = pointTwo.Y; double coefficientOfY = pointOne.X - pointTwo.X; double absoluteTerm = pointOne.X * pointTwo.Y + pointOne.Y * pointTwo.X; LineDescriptor lineDescriptor = new LineDescriptor(coefficientOfX, coefficientOfY, absoluteTerm); return(lineDescriptor); }
//------------------------------------------------------------------------------------------------ //Нормаль к кривой в точке public LineDescriptor GetNormalAtPoint(Point2D point) { double x0 = point.X; double y0 = point.Y; double a = a12 * x0 + a22 * y0 + a23; double b = -a11 * x0 - a12 * y0 - a13; double c = a11 * x0 * y0 + a12 * y0 * y0 + a13 * y0 - a12 * x0 * x0 - a22 * y0 * x0 - a23 * x0; LineDescriptor normalLineDescriptor = new LineDescriptor(a, b, c); return(normalLineDescriptor); }
//----------------------------------------------------------------------------------------------- //Точки пересечения прямой и окружности public static Point2D[] IntersectionPointsOfLineAndCircle( LineDescriptor lineDescriptor, CircleDescriptor circleDescriptor ) { double a = lineDescriptor.CoefficientOfX; double b = lineDescriptor.CoefficientOfY; double c = lineDescriptor.AbsoluteTerm; double xc = circleDescriptor.Centre.X; double yc = circleDescriptor.Centre.Y; double r = circleDescriptor.Radius; double x1, x2, y1, y2; if (b != 0) { double koefficientA = 1 + ((a * a) / (b * b)); double koefficientB = 2 * (c * a / (b * b) + yc * a / b - xc); double koefficientC = xc * xc + yc * yc + (c * c) / (b * b) + 2 * yc * c / b - r * r; QuadraticEquation quadraticEquation = new QuadraticEquation(koefficientA, koefficientB, koefficientC); Complex[] complexRoots = quadraticEquation.GetRoots(); double[] realRoots = NumbersManager.GetRealParts(complexRoots); x1 = realRoots[0]; y1 = (-c - a * x1) / b; x2 = realRoots[1]; y2 = (-c - a * x2) / b; } else { double x = -c / a; x1 = x2 = x; double[] coordinatesY = circleDescriptor.GetCoordinatesY(x); y1 = coordinatesY[0]; y2 = coordinatesY[1]; } Point2D intersectionPoint1 = new Point2D(x1, y1); Point2D intersectionPoint2 = new Point2D(x2, y2); Point2D[] intersectionPoints = new Point2D[] { intersectionPoint1, intersectionPoint2 }; return(intersectionPoints); }
//----------------------------------------------------------------------------------------------- //Точка пересечения двух прямых линий public static Point2D IntersectionPointOfLines(LineDescriptor lineOne, LineDescriptor lineTwo) { double a1 = lineOne.CoefficientOfX; double b1 = lineOne.CoefficientOfY; double c1 = lineOne.AbsoluteTerm; double a2 = lineTwo.CoefficientOfX; double b2 = lineTwo.CoefficientOfY; double c2 = lineTwo.AbsoluteTerm; double y = ((a2 * c1 / a1) - c2) / (b2 - (a2 * b1 / a1)); double x = (-c1 - b1 * y) / a1; Point2D intersectionPoint = new Point2D(x, y); return(intersectionPoint); }