Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
907 B
1
Indexable
Never
<?php
function isInCircle($dot, $circle)
{ //dot[x,y] circle[x,y,r]
    //distance of dot and center of circle
    $distance = sqrt(pow($dot[0] - $circle[0], 2) + pow($dot[1] - $circle[1], 2));
    return ($distance < $circle[2]) ? true : false; //true if inside $ false
}
$dot = [0, 5];
$redCircle = [-2, 1, 4];
$greenCircle = [3, 2, 4];
$blueCircle = [-1, -3, 4];
$isInRed = isInCircle($dot, $redCircle);
$isInGreen = isInCircle($dot, $greenCircle);
$isInBlue = isInCircle($dot, $blueCircle);
//  echo "$isInRed,$isInGreen,$isInBlue";
if ($isInRed & $isInGreen & $isInBlue) {
    echo '8';
} elseif ($isInRed & $isInGreen) {
    echo '4';
} elseif ($isInRed & $isInBlue) {
    echo '6';
} elseif ($isInBlue & $isInGreen) {
    echo '7';
} elseif ($isInRed) {
    echo '2';
} elseif ($isInGreen) {
    echo '3';
} elseif ($isInBlue) {
    echo '5';
} else {
    echo '1';
}