Completed
Push — master ( d35909...f740b5 )
by Yannick
06:46
created

Predict_Solar::FindSun()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 30
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 21
nc 2
nop 2
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Ported from gpredict to PHP by Bill Shupp
5
 */
6
7
//require_once 'Predict.php';
8
require_once 'Math.php';
9
require_once 'Time.php';
10
require_once 'Vector.php';
11
require_once 'Geodetic.php';
12
require_once 'ObsSet.php';
13
require_once 'SGPObs.php';
14
15
/*
16
 * Unit Solar
17
 *           Author:  Dr TS Kelso
18
 * Original Version:  1990 Jul 29
19
 * Current Revision:  1999 Nov 27
20
 *          Version:  1.30
21
 *        Copyright:  1990-1999, All Rights Reserved
22
 *
23
 *   Ported to C by: Neoklis Kyriazis  April 1 2001
24
 */
25
class Predict_Solar
26
{
27
    /* Calculates solar position vector */
28
    public static function Calculate_Solar_Position($time, Predict_Vector $solar_vector)
29
    {
30
        $mjd = $time - 2415020.0;
31
        $year = 1900 + $mjd / 365.25;
32
        $T = ($mjd + Predict_Time::Delta_ET($year) / Predict::secday) / 36525.0;
33
        $M = Predict_Math::Radians(Predict_Math::Modulus(358.47583 + Predict_Math::Modulus(35999.04975 * $T, 360.0)
34
             - (0.000150 + 0.0000033 * $T) * ($T * $T), 360.0));
35
        $L = Predict_Math::Radians(Predict_Math::Modulus(279.69668 + Predict_Math::Modulus(36000.76892 * $T, 360.0)
36
             + 0.0003025 * ($T * $T), 360.0));
37
        $e = 0.01675104 - (0.0000418 + 0.000000126 * $T) * $T;
38
        $C = Predict_Math::Radians((1.919460 - (0.004789 + 0.000014 * $T) * $T) * sin($M)
39
             + (0.020094 - 0.000100 * $T) * sin(2 * $M) + 0.000293 * sin(3 * $M));
40
        $O = Predict_Math::Radians(Predict_Math::Modulus(259.18 - 1934.142 * $T, 360.0));
41
        $Lsa = Predict_Math::Modulus($L + $C - Predict_Math::Radians(0.00569 - 0.00479 * sin($O)), Predict::twopi);
42
        $nu = Predict_Math::Modulus($M + $C, Predict::twopi);
43
        $R = 1.0000002 * (1 - ($e * $e)) / (1 + $e * cos($nu));
44
        $eps = Predict_Math::Radians(23.452294 - (0.0130125 + (0.00000164 - 0.000000503 * $T) * $T) * $T + 0.00256 * cos($O));
45
        $R = Predict::AU * $R;
46
47
        $solar_vector->x = $R * cos($Lsa);
0 ignored issues
show
Documentation Bug introduced by
The property $x was declared of type integer, but $R * cos($Lsa) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
48
        $solar_vector->y = $R * sin($Lsa) * cos($eps);
0 ignored issues
show
Documentation Bug introduced by
The property $y was declared of type integer, but $R * sin($Lsa) * cos($eps) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
49
        $solar_vector->z = $R * sin($Lsa) * sin($eps);
0 ignored issues
show
Documentation Bug introduced by
The property $z was declared of type integer, but $R * sin($Lsa) * sin($eps) is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
50
        $solar_vector->w = $R;
0 ignored issues
show
Documentation Bug introduced by
The property $w was declared of type integer, but $R is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
51
    }
52
53
    /* Calculates stellite's eclipse status and depth */
54
    public static function Sat_Eclipsed(Predict_Vector $pos, Predict_Vector $sol, &$depth)
55
    {
56
        $Rho   = new Predict_Vector();
57
        $earth = new Predict_Vector();
58
59
        /* Determine partial eclipse */
60
        $sd_earth = Predict_Math::ArcSin(Predict::xkmper / $pos->w);
61
        Predict_Math::Vec_Sub($sol, $pos, $Rho);
62
        $sd_sun = Predict_Math::ArcSin(Predict::__sr__ / $Rho->w);
63
        Predict_Math::Scalar_Multiply(-1, $pos, $earth);
64
        $delta = Predict_Math::Angle($sol, $earth);
65
        $depth = $sd_earth - $sd_sun - $delta;
66
67
        if ($sd_earth < $sd_sun) {
68
            return 0;
69
        } else if ($depth >= 0) {
70
            return 1;
71
        } else {
72
            return 0;
73
        }
74
    }
75
76
    /**
77
     * Finds the current location of the sun based on the observer location
78
     *
79
     * @param Predict_QTH $qth    The observer location
80
     * @param int         $daynum The daynum or null to use the current daynum
81
     *
82
     * @return Predict_ObsSet
83
     */
84
    public static function FindSun(Predict_QTH $qth, $daynum = null)
85
    {
86
        if ($daynum === null) {
87
            $daynum = Predict_Time::get_current_daynum();
88
        }
89
90
        $obs_geodetic = new Predict_Geodetic();
91
        $obs_geodetic->lon   = $qth->lon * Predict::de2ra;
92
        $obs_geodetic->lat   = $qth->lat * Predict::de2ra;
93
        $obs_geodetic->alt   = $qth->alt / 1000.0;
94
        $obs_geodetic->theta = 0;
95
96
        $solar_vector = new Predict_Vector();
97
        $zero_vector  = new Predict_Vector();
98
        $solar_set    = new Predict_ObsSet();
99
100
        self::Calculate_Solar_Position($daynum, $solar_vector);
101
        Predict_SGPObs::Calculate_Obs(
102
            $daynum,
103
            $solar_vector,
104
            $zero_vector,
105
            $obs_geodetic,
106
            $solar_set
107
        );
108
109
        $solar_set->az = Predict_Math::Degrees($solar_set->az);
110
        $solar_set->el = Predict_Math::Degrees($solar_set->el);
111
112
        return $solar_set;
113
    }
114
}
115