You are here

public function Polygon::outermostPoint in geoPHP 7

Same name and namespace in other branches
  1. 8 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 88

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'];
}