public static Rectangle2D QuadraticBezierBounds0( double ax, double ay, double bx, double by, double cx, double cy) { var sortOfCloseLength = QuadraticBezierSegmentLengthTests.QuadraticBezierArcLength(ax, ay, bx, by, cx, cy); // ToDo: Need to make this more efficient. Don't need to rebuild the point array every time. var points = new List <(double X, double Y)>(FunctionalInterpolationTests.Interpolate0to1((int)(sortOfCloseLength / 3), (i) => InterpolateBezierQuadratic2DTests.QuadraticBezierInterpolate2D(i, ax, ay, bx, by, cx, cy))); var left = points[0].X; var top = points[0].Y; var right = points[0].X; var bottom = points[0].Y; foreach (var(X, Y) in points) { // ToDo: Measure performance impact of overwriting each time. left = X <= left ? X : left; top = Y <= top ? Y : top; right = X >= right ? X : right; bottom = Y >= bottom ? Y : bottom; } return(Rectangle2D.FromLTRB(left, top, right, bottom)); }
public static Rectangle2D CubicBezierBounds1( double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) { var sortOfCloseLength = (int)CubicBezierSegmentLengthTests.CubicBezierArcLength(ax, ay, bx, by, cx, cy, dx, dy); var points = new List <(double X, double Y)>(FunctionalInterpolationTests.Interpolate0to1(sortOfCloseLength, (i) => InterpolateCubic2DTests.CubicInterpolate2D(i, ax, ay, bx, by, cx, cy, dx, dy))); var left = points[0].X; var top = points[0].Y; var right = points[0].X; var bottom = points[0].Y; foreach (var(X, Y) in points) { // ToDo: Measure performance impact of overwriting each time. left = X <= left ? X : left; top = Y <= top ? Y : top; right = X >= right ? X : right; bottom = Y >= bottom ? Y : bottom; } return(Rectangle2D.FromLTRB(left, top, right, bottom)); }
public static Rectangle2D TripointCircleBounds( double PointAX, double PointAY, double PointBX, double PointBY, double PointCX, double PointCY) { (var X, var Y) = CircleCenterThreePointsTests.CenterCircleThreePoints(PointAX, PointAY, PointBX, PointBY, PointCX, PointCY) ?? (0d, 0d); var Radius = Distance2DTests.Distance2D(X, Y, PointAX, PointAY); return(Rectangle2D.FromLTRB(X - Radius, Y - Radius, X + Radius, Y + Radius)); }
public static Rectangle2D EllipseBounds2(double x, double y, double r1, double r2, double angle) { var phi = angle; var aspect = r2 / r1; var ux = r1 * Cos(phi); var uy = r1 * Sin(phi); var vx = r1 * aspect * Cos(phi + (PI * 0.5d)); var vy = r1 * aspect * Sin(phi + (PI * 0.5d)); var bbox_halfwidth = Sqrt((ux * ux) + (vx * vx)); var bbox_halfheight = Sqrt((uy * uy) + (vy * vy)); return(Rectangle2D.FromLTRB( x - bbox_halfwidth, y - bbox_halfheight, x + bbox_halfwidth, y + bbox_halfheight )); }
public static Rectangle2D?CircleBoundsFromPoints0( double p1X, double p1Y, double p2X, double p2Y, double p3X, double p3Y) { var offset = (p2X * p2X) + (p2Y * p2Y); var bc = ((p1X * p1X) + (p1Y * p1Y) - offset) * 0.5d; var cd = (offset - (p3X * p3X) - (p3Y * p3Y)) * 0.5d; var determinant = ((p1X - p2X) * (p2Y - p3Y)) - ((p2X - p3X) * (p1Y - p2Y)); if (Abs(determinant) < DoubleEpsilon) { return(null); } var centerx = ((bc * (p2Y - p3Y)) - (cd * (p1Y - p2Y))) / determinant; var centery = ((cd * (p1X - p2X)) - (bc * (p2X - p3X))) / determinant; var radius = Sqrt(((p2X - centerx) * (p2X - centerx)) + ((p2Y - centery) * (p2Y - centery))); return(Rectangle2D.FromLTRB(centerx - radius, centery - radius, centerx + radius, centery + radius)); }