Vec2 ScallopedSector::sample(RNG &rng) { float angle = calcAngleForArea(area*rng.getFloatL(), rng); float d1 = distToCurve(angle, 0); float d2 = distToCurve(angle, 1); float d = sqrt(d1*d1 + (d2*d2 - d1*d1)*rng.getFloat()); return Vec2(P.x + cos(angle)*d, P.y + sin(angle)*d); }
float ScallopedSector::calcAngleForArea(float area, RNG &rng) { float lo = a1, hi = a2, cur = lo + (hi-lo)*rng.getFloat(); for (int i=0; i<10; i++) { if (calcAreaToAngle(cur)<area) { lo = cur; cur = (cur + hi)*.5f; } else { hi = cur; cur = (lo + cur)*.5f; } } return cur; }