You are here

public function Polygon::outermostPoint in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/geometry/Polygon.class.php \Polygon::outermostPoint()

* Find the outermost point from the centroid * * @returns Point The outermost point

File

geoPHP/lib/geometry/Polygon.class.php, line 83

Class

Polygon
Polygon: A polygon is a plane figure that is bounded by a closed path, composed of a finite sequence of straight line segments

Code

public function outermostPoint() {
  $centroid = $this
    ->getCentroid();
  $max = array(
    'length' => 0,
    'point' => null,
  );
  foreach ($this
    ->getPoints() as $point) {
    $lineString = new LineString(array(
      $centroid,
      $point,
    ));
    if ($lineString
      ->length() > $max['length']) {
      $max['length'] = $lineString
        ->length();
      $max['point'] = $point;
    }
  }
  return $max['point'];
}