private static void CheckCircle(RBTreeNode <BeachSection> section, MinHeap <FortuneEvent> eventQueue) { //if (section == null) // return; var left = section.Previous; var right = section.Next; if (left == null || right == null) { return; } var leftSite = left.Data.Site; var centerSite = section.Data.Site; var rightSite = right.Data.Site; //if the left arc and right arc are defined by the same //focus, the two arcs cannot converge if (leftSite == rightSite) { return; } // http://mathforum.org/library/drmath/view/55002.html // because every piece of this program needs to be demoed in maple >.< //MATH HACKS: place center at origin and //draw vectors a and c to //left and right respectively float bx = centerSite.X, by = centerSite.Y, ax = leftSite.X - bx, ay = leftSite.Y - by, cx = rightSite.X - bx, cy = rightSite.Y - by; //The center beach section can only dissapear when //the angle between a and c is negative var d = ax * cy - ay * cx; if (d.ApproxGreaterThanOrEqualTo(0)) { return; } var magnitudeA = ax * ax + ay * ay; var magnitudeC = cx * cx + cy * cy; var x = (cy * magnitudeA - ay * magnitudeC) / (2 * d); var y = (ax * magnitudeC - cx * magnitudeA) / (2 * d); //add back offset var ycenter = y + by; //y center is off var circleEvent = new FortuneCircleEvent( new VPoint(x + bx, ycenter + (float)Math.Sqrt(x * x + y * y)), ycenter, section ); section.Data.CircleEvent = circleEvent; eventQueue.Insert(circleEvent); }