/** * Create a cap given its axis and the cap opening angle, i.e. maximum angle * between the axis and a point on the cap. 'axis' should be a unit-length * vector, and 'angle' should be between 0 and 180 degrees. */ public static function fromAxisAngle(S2Point $axis, S1Angle $angle) { // The height of the cap can be computed as 1-cos(angle), but this isn't // very accurate for angles close to zero (where cos(angle) is almost 1). // Computing it as 2*(sin(angle/2)**2) gives much better precision. // assert (S2.isUnitLength(axis)); $d = sin(0.5 * $angle->radians()); return new S2Cap($axis, 2 * $d * $d); }
/** * This is internal to avoid ambiguity about which units are expected. * @param double|S1Angle $latRadians * @param double|S1Angle $lngRadians */ public function __construct($latRadians = null, $lngRadians = null) { if ($latRadians instanceof S1Angle && $lngRadians instanceof S1Angle) { $this->latRadians = $latRadians->radians(); $this->lngRadians = $lngRadians->radians(); } else { if ($lngRadians === null && $latRadians instanceof S2Point) { $this->latRadians = atan2($latRadians->z, sqrt($latRadians->x * $latRadians->x + $latRadians->y * $latRadians->y)); $this->lngRadians = atan2($latRadians->y, $latRadians->x); } else { if ($latRadians === null && $lngRadians === null) { $this->latRadians = 0; $this->lngRadians = 0; } else { $this->latRadians = $latRadians; $this->lngRadians = $lngRadians; } } } }
public function greaterOrEquals(S1Angle $that) { return $this->radians() >= $that->radians(); }