﻿ Codec ░ Proportional Venn diagram

## 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
\$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;
}