Ellipsoid::getA()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Location;
6
7
/**
8
 * Ellipsoid
9
 *
10
 * @author Marcus Jaschen <[email protected]>
11
 */
12
class Ellipsoid
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $name;
18
19
    /**
20
     * The semi-major axis
21
     *
22
     * @var float
23
     */
24
    protected $a;
25
26
    /**
27
     * The Inverse Flattening (1/f)
28
     *
29
     * @var float
30
     */
31
    protected $f;
32
33
    /**
34
     * Some often used ellipsoids
35
     *
36
     * @var array
37
     */
38
    protected static $configs = [
39
        'WGS-84' => [
40
            'name' => 'World Geodetic System 1984',
41
            'a'    => 6378137.0,
42
            'f'    => 298.257223563,
43
        ],
44
        'GRS-80' => [
45
            'name' => 'Geodetic Reference System 1980',
46
            'a'    => 6378137.0,
47
            'f'    => 298.257222100,
48
        ],
49
    ];
50
51
    /**
52
     * @param string $name
53
     * @param float $a
54
     * @param float $f
55
     */
56
    public function __construct(string $name, float $a, float $f)
57
    {
58
        $this->name = $name;
59
        $this->a    = $a;
60
        $this->f    = $f;
61
    }
62
63
    /**
64
     * @param string $name
65
     *
66
     * @return Ellipsoid
67
     */
68
    public static function createDefault($name = 'WGS-84'): Ellipsoid
69
    {
70
        return static::createFromArray(static::$configs[$name]);
71
    }
72
73
    /**
74
     * @param array $config
75
     *
76
     * @return Ellipsoid
77
     */
78
    public static function createFromArray(array $config): Ellipsoid
79
    {
80
        return new self($config['name'], $config['a'], $config['f']);
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getName(): string
87
    {
88
        return $this->name;
89
    }
90
91
    /**
92
     * @return float
93
     */
94
    public function getA(): float
95
    {
96
        return $this->a;
97
    }
98
99
    /**
100
     * Calculation of the semi-minor axis
101
     *
102
     * @return float
103
     */
104
    public function getB(): float
105
    {
106
        return $this->a * (1 - 1 / $this->f);
107
    }
108
109
    /**
110
     * @return float
111
     */
112
    public function getF(): float
113
    {
114
        return $this->f;
115
    }
116
117
    /**
118
     * Calculates the arithmetic mean radius
119
     *
120
     * @see http://home.online.no/~sigurdhu/WGS84_Eng.html
121
     *
122
     * @return float
123
     */
124
    public function getArithmeticMeanRadius(): float
125
    {
126
        return $this->a * (1 - 1 / $this->f / 3);
127
    }
128
}
129