Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Quadrilateral | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
| getSurfaceFromSidesAndAngle | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package TBD |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Math\Geometry\Shape\D2; |
| 16 | |
| 17 | /** |
| 18 | * Quadrilateral shape. |
| 19 | * |
| 20 | * @package phpOMS\Math\Geometry\Shape\D2 |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | final class Quadrilateral implements D2ShapeInterface |
| 26 | { |
| 27 | /** |
| 28 | * Calculate the surface area from the length of all sides and the angle between a and b |
| 29 | * |
| 30 | * @param float $a Side a length (DA) |
| 31 | * @param float $b Side b length (AB) |
| 32 | * @param float $c Side c length (BC) |
| 33 | * @param float $d Side d length (CD) |
| 34 | * @param float $alpha Angle between side a and b |
| 35 | * |
| 36 | * @return float |
| 37 | * |
| 38 | * @since 1.0.0 |
| 39 | */ |
| 40 | public static function getSurfaceFromSidesAndAngle(float $a, float $b, float $c, float $d, float $alpha) : float |
| 41 | { |
| 42 | $s = ($a + $b + $c + $d) / 2; |
| 43 | $gamma = \acos(($c ** 2 + $d ** 2 - $a ** 2 - $b ** 2 + 2 * $a * $b * \cos(\deg2rad($alpha))) / (2 * $c * $d)); |
| 44 | |
| 45 | return \sqrt(($s - $a) * ($s - $b) * ($s - $c) * ($s - $d) - $a * $b * $c * $d * \cos((\deg2rad($alpha) + $gamma) / 2) ** 2); |
| 46 | } |
| 47 | } |