-
Notifications
You must be signed in to change notification settings - Fork 0
/
CircleAndCircleClass.php
50 lines (46 loc) · 1.17 KB
/
CircleAndCircleClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Created by PhpStorm.
* User: dobrodeev
* Date: 14.08.2018
* Time: 13:49
*/
class CircleAndCircleClass
{
private $x;
private $y;
private $r;
public function __construct($x, $y, $r)
{
$this->x = $x;
$this->y = $y;
$this->r = $r;
}
public function setCircle($x, $y, $r)
{
$this->x = $x;
$this->y = $y;
$this->r = $r;
}
public function countIntersections($another)
{
// abs(), min(), max() if $distance > abs(r1-r2)
$distance = sqrt(pow($this->x - $another->x, 2) + pow($this->y - $another->y, 2));
if ($distance > $this->r + $another->r || $distance < abs($this->r - $another->r))
{
return 0;
}
elseif ($distance == $this->r + $another->r || ($distance == abs($this->r - $another->r) && $distance != 0))
{
return 1;
}
elseif ($distance < $this->r + $another->r && $distance > abs($this->r - $another->r))
{
return 2;
}
elseif ($this->x == $another->x && $this->y == $another->y && $this->r == $another->r)
{
return -1;
}
}
}