double bowArea(double r, point p1, point p2) { double d = p1.distTo(p2); var b1 = d / 2; double b2 = Math.Sqrt(r * r - b1 * b1); var tg = b1 / b2; var angle = Math.Atan(tg) * 2; //Console.WriteLine(angle * (180 / Math.PI)); var fanA = r * r * angle / 2; var tranA = b1 * b2; return(fanA - tranA); }
private double calcPass(double vstring, double hstring) { var x1 = vstring + r; var x2 = x1 + g; var y1 = hstring + r; var y2 = y1 + g; x1 += f; x2 -= f; y1 += f; y2 -= f; var leftBottom = new point(x1, y1); // totally out if (OrgPoint.distTo(leftBottom) >= flyR) { return(0); } var rightTop = new point(x2, y2); if (rightTop.distTo(OrgPoint) <= flyR) { return(sqPass); } var rightBottom = new point(x2, y1); bool rightBottomOut = rightBottom.distTo(OrgPoint) >= flyR; var leftTop = new point(x1, y2); bool leftTopOut = leftTop.distTo(OrgPoint) >= flyR; double res = 0; // 1 if (!rightBottomOut && !leftTopOut) { var p1 = new point(x2, otherCood(flyR, x2)); var p2 = new point(otherCood(flyR, y2), y2); res += bowArea(flyR, p1, p2); res += sqPass; res -= ((x2 - p2.x) * (y2 - p1.y)) / 2; } else if (rightBottomOut && !leftTopOut) { var p1 = new point(otherCood(flyR, y1), y1); var p2 = new point(otherCood(flyR, y2), y2); res += bowArea(flyR, p1, p2); var lx = Math.Max(p1.x, p2.x); var sx = Math.Min(p1.x, p2.x); res += passG * (sx - x1); res += (passG * (lx - sx)) / 2; } else if (!rightBottomOut && leftTopOut) { var p1 = new point(x2, otherCood(flyR, x2)); var p2 = new point(x1, otherCood(flyR, x1)); res += bowArea(flyR, p1, p2); var ly = Math.Max(p1.y, p2.y); var sy = Math.Min(p1.y, p2.y); res += passG * (sy - y1); res += (passG * (ly - sy)) / 2; } else if (rightBottomOut && leftTopOut) { var p1 = new point(x1, otherCood(flyR, x1)); var p2 = new point(otherCood(flyR, y1), y1); res += bowArea(flyR, p1, p2); res += ((p1.y - y1) * (p2.x - x1)) / 2; } return(res); }