private void MaxTextRegion(Size size, CircleF circle, double angle, double fratio, out float mxlen, out PointF center) { // ew(Ex-Width)=(len*fratio)/2 // half-rect // { w=ew+len*|cosa|/2 // h=ew+len*|sina|/2 } // { c0=... // c1=... } double vx = Math.Cos(angle); double vy = Math.Sin(angle); double c0 = (fratio + Math.Abs(vx)) / 2; double c1 = (fratio + Math.Abs(vy)) / 2; double mxlenx = Math.Min(size.Width / (2 * c0), size.Height / (2 * c1)); RectV rect = new RectV() { C0 = c0, C1 = c1, W = size.Width, H = size.Height }; PtV fp = FarthestPointToPoint(rect, circle.Center); float cx = circle.Center.X, cy = circle.Center.Y; double l = 0, r = mxlenx; Point2D c = new Point2D(cx, cy); for (int i = 0; i < 16; i++) { double mid = (l + r) / 2; double px = fp.X(mid); double py = fp.Y(mid); double px0 = px + vx * mid / 2; double py0 = py + vy * mid / 2; double px1 = px - vx * mid / 2; double py1 = py - vy * mid / 2; Line2D line = new Line2D(new Point2D(px0, py0), new Point2D(px1, py1)); Point2D cp = line.ClosestPointTo(c, true); if (cp.DistanceTo(c) < circle.Radius + mid * fratio / 2) { r = mid; } else { l = mid; } } mxlenx = (l + r) / 2; mxlen = (float)mxlenx; center = new PointF((float)fp.X(mxlenx), (float)fp.Y(mxlenx)); }
//Assumption: this method would never be called when the intersector's end points lie in the middle of an intersectee line //This is the case for meshes defined by an ordered set of vertices public static bool Intersects(this Line2D intersectee, Line2D intersector, double tolerance) { var intPtIntersection = intersectee.IntersectWith(intersector); if (!intPtIntersection.HasValue) { return(false); } var intPt = intPtIntersection.Value; //There is no intersection if it's at the end points of the line doing the suppposed intersection if (intersector.StartPoint.EqualsWithinTolerance(intPt, tolerance) || intersector.EndPoint.EqualsWithinTolerance(intPt, tolerance)) { return(false); } //By default MathNet defines lines with infinite length so determine if the intersection point is actually within the original bounds of the line var intersecteePt = intersectee.ClosestPointTo(intPt, true); var intersectorPt = intersector.ClosestPointTo(intPt, true); return(intersecteePt.EqualsWithinTolerance(intersectorPt, tolerance)); }