666Proportional Venn diagram

Everybody loves Venn diagrams. But despite their omnipresence, I found little resources, that would allow me to construct proportional Venn diagrams, meaning the overlapping area depicts the actual amount of overlap.

The function calculateVennDistance() takes the area of one circle, the are of the other one, and the intersected area, and calculates the distance between these circles that match the intersected area. Not as straight-forward as I initially thought it would be, if you have a better implementation, please let me know.

This is the code for calculating the distance between 2 circles, the overlapping area is proportionally in relation to the size of the other circles. I guess it would not be that difficult to adapt it for a Venn diagram with 3 circles.

function calculateVennDistance($area1, $area2, $intersectedArea) {

    $r1 = sqrt($area1 / M_PI);      // area to radius
    $r2 = sqrt($area2 / M_PI);

    $lower = 0;                         // lower test boundery
    $chordLength = 0;                   // start with 0
    $upper = 2 * min($r1, $r2);         // smaller diameter

    for($i=0; $i<50;$i++) {
        // run 50 interations... should be plenty
        $testArea = segmentArea($r1, $chordLength) + segmentArea($r2, $chordLength);

        if ($testArea > $intersectedArea) {
            $upper = $chordLength;
        } else {
            $lower = $chordLength;
        }
        $chordLength = ($lower + $upper)/2;
    }   

    $h1 = $r1 - sqrt( pow($r1,2) - pow($chordLength/2,2) );
    $h2 = $r2 - sqrt( pow($r2,2) - pow($chordLength/2,2) );

    $circleDistance = $r1 + $r2 - ($h1 + $h2);  
    return $circleDistance;
}

function segmentArea($radius, $chordLength) {
    $segmentHeight = $radius - sqrt( pow($radius,2) - pow(($chordLength/2),2));
    $alpha = 2 * acos(1 - $segmentHeight/$radius);
    return pow($radius,2)/2 * ($alpha - sin($alpha));
}

PS The numbers for the post get assigned automatically, but this one truly reflects my fight with this problem.