mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 21:28:40 +00:00
Remove this from polygon
This commit is contained in:
parent
1f600d535c
commit
7cbd8d6081
|
|
@ -218,13 +218,13 @@ class Polygon implements D2ShapeInterface
|
||||||
public function getPerimeter() : float
|
public function getPerimeter() : float
|
||||||
{
|
{
|
||||||
$count = count($this->coord);
|
$count = count($this->coord);
|
||||||
$this->perimeter = sqrt(($this->coord[0]['x'] - $this->coord[$count - 1]['x']) ** 2 + ($this->coord[0]['y'] - $this->coord[$count - 1]['y']) ** 2);
|
$perimeter = sqrt(($this->coord[0]['x'] - $this->coord[$count - 1]['x']) ** 2 + ($this->coord[0]['y'] - $this->coord[$count - 1]['y']) ** 2);
|
||||||
|
|
||||||
for ($i = 0; $i < $count - 1; $i++) {
|
for ($i = 0; $i < $count - 1; $i++) {
|
||||||
$this->perimeter += sqrt(($this->coord[$i + 1]['x'] - $this->coord[$i]['x']) ** 2 + ($this->coord[$i + 1]['y'] - $this->coord[$i]['y']) ** 2);
|
$perimeter += sqrt(($this->coord[$i + 1]['x'] - $this->coord[$i]['x']) ** 2 + ($this->coord[$i + 1]['y'] - $this->coord[$i]['y']) ** 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->perimeter;
|
return $perimeter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -236,26 +236,26 @@ class Polygon implements D2ShapeInterface
|
||||||
*/
|
*/
|
||||||
public function getBarycenter() : array
|
public function getBarycenter() : array
|
||||||
{
|
{
|
||||||
$this->barycenter['x'] = 0;
|
$barycenter['x'] = 0;
|
||||||
$this->barycenter['y'] = 0;
|
$barycenter['y'] = 0;
|
||||||
|
|
||||||
$count = count($this->coord);
|
$count = count($this->coord);
|
||||||
|
|
||||||
for ($i = 0; $i < $count - 1; $i++) {
|
for ($i = 0; $i < $count - 1; $i++) {
|
||||||
$mult = ($this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']);
|
$mult = ($this->coord[$i]['x'] * $this->coord[$i + 1]['y'] - $this->coord[$i + 1]['x'] * $this->coord[$i]['y']);
|
||||||
$this->barycenter['x'] += ($this->coord[$i]['x'] + $this->coord[$i + 1]['x']) * $mult;
|
$barycenter['x'] += ($this->coord[$i]['x'] + $this->coord[$i + 1]['x']) * $mult;
|
||||||
$this->barycenter['y'] += ($this->coord[$i]['y'] + $this->coord[$i + 1]['y']) * $mult;
|
$barycenter['y'] += ($this->coord[$i]['y'] + $this->coord[$i + 1]['y']) * $mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mult = ($this->coord[$count - 1]['x'] * $this->coord[0]['y'] - $this->coord[0]['x'] * $this->coord[$count - 1]['y']);
|
$mult = ($this->coord[$count - 1]['x'] * $this->coord[0]['y'] - $this->coord[0]['x'] * $this->coord[$count - 1]['y']);
|
||||||
$this->barycenter['x'] += ($this->coord[$count - 1]['x'] + $this->coord[0]['x']) * $mult;
|
$barycenter['x'] += ($this->coord[$count - 1]['x'] + $this->coord[0]['x']) * $mult;
|
||||||
$this->barycenter['y'] += ($this->coord[$count - 1]['y'] + $this->coord[0]['y']) * $mult;
|
$barycenter['y'] += ($this->coord[$count - 1]['y'] + $this->coord[0]['y']) * $mult;
|
||||||
|
|
||||||
$surface = $this->getSignedSurface();
|
$surface = $this->getSignedSurface();
|
||||||
|
|
||||||
$this->barycenter['x'] = 1 / (6 * $surface) * $this->barycenter['x'];
|
$barycenter['x'] = 1 / (6 * $surface) * $barycenter['x'];
|
||||||
$this->barycenter['y'] = 1 / (6 * $surface) * $this->barycenter['y'];
|
$barycenter['y'] = 1 / (6 * $surface) * $barycenter['y'];
|
||||||
|
|
||||||
return $this->barycenter;
|
return $barycenter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user