Commit | Line | Data |
---|---|---|
11ade432 AE |
1 | <?php |
2 | namespace wcf\util; | |
3 | ||
4 | /** | |
5 | * Contains math-related functions. | |
6 | * | |
9f959ced | 7 | * @author Marcel Werk |
c839bd49 | 8 | * @copyright 2001-2018 WoltLab GmbH |
11ade432 | 9 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
e71525e4 | 10 | * @package WoltLabSuite\Core\Util |
11ade432 | 11 | */ |
18284789 | 12 | final class MathUtil { |
11ade432 AE |
13 | /** |
14 | * Generates a random value. | |
9f959ced | 15 | * |
11ade432 AE |
16 | * @param integer $min |
17 | * @param integer $max | |
18 | * @return integer | |
19 | */ | |
20 | public static function getRandomValue($min = null, $max = null) { | |
11ade432 AE |
21 | // generate random value |
22 | return (($min !== null && $max !== null) ? mt_rand($min, $max) : mt_rand()); | |
23 | } | |
18284789 | 24 | |
80e131ce | 25 | /** |
1615fc2e | 26 | * Transforms the given latitude and longitude into cartesian coordinates |
80e131ce MS |
27 | * (x, y, z). |
28 | * | |
29 | * @param float $latitude | |
30 | * @param float $longitude | |
7a23a706 | 31 | * @return float[] |
80e131ce MS |
32 | */ |
33 | public static function latitudeLongitudeToCartesian($latitude, $longitude) { | |
34 | $lambda = $longitude * pi() / 180; | |
35 | $phi = $latitude * pi() / 180; | |
36 | ||
058cbd6a | 37 | return [ |
7a23a706 MS |
38 | 6371 * cos($phi) * cos($lambda), // x |
39 | 6371 * cos($phi) * sin($lambda), // y | |
40 | 6371 * sin($phi) // z | |
058cbd6a | 41 | ]; |
80e131ce MS |
42 | } |
43 | ||
1d5f9363 MS |
44 | /** |
45 | * Forbid creation of MathUtil objects. | |
46 | */ | |
47 | private function __construct() { | |
48 | // does nothing | |
49 | } | |
11ade432 | 50 | } |