1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
package ru.olamedia.astronomy;
/*
* Copyright 2011 Brad Parks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//package com.bradsbrain.simpleastronomy;
import static ru.olamedia.astronomy.BaseUtils.sinDegrees;
import java.util.Calendar;
public class MoonPosition {
// some handy constants
private double EPOCH = 2447891.5; // 1990 January 0.0
private double MEAN_LONGITUDE_AT_EPOCH = 318.351648;
private double MEAN_LONGITUDE_OF_PERIGREE_AT_EPOCH = 36.340410;
/**
* The True Longitude
*/
private double trueOrbitalLongitude;
/**
* This is from section 65, page 144
*
* @param cal
* the calendar date for which to compute the moon position
*/
public MoonPosition(Calendar cal) {
Calendar myCal = BaseUtils.getSafeLocalCopy(cal.getTimeInMillis());
double daysSince = BaseUtils.exactDaysSince(myCal, EPOCH);
// l
double moonMeanLongitude = computeMeanLongitude(daysSince);
// M m
double moonMeanAnomaly = computeMeanAnomaly(daysSince,
moonMeanLongitude);
SunPosition sunPos = new SunPosition(myCal);
MoonCorrections corrections = new MoonCorrections(moonMeanLongitude,
moonMeanAnomaly, sunPos.getEclipticLongitude(),
sunPos.getMeanAnomaly());
trueOrbitalLongitude = corrections.getCorrectedLongitude()
- corrections.getVariationCorrection();
}
public double getTrueLongitude() {
return trueOrbitalLongitude;
}
/**
* Compute the Moon Mean Longitude l
*
* @param daysSince
* @return
*/
private double computeMeanLongitude(double daysSince) {
double moonMeanLongitude = 13.1763966 * daysSince
+ MEAN_LONGITUDE_AT_EPOCH;
return BaseUtils.adjustTo360Range(moonMeanLongitude);
}
/**
* Compute the Moon Mean Anomaly M m
*
* @param daysSince
* @param moonMeanLongitude
* @return
*/
private double computeMeanAnomaly(double daysSince, double moonMeanLongitude) {
double moonMeanAnomaly = moonMeanLongitude - (0.1114041 * daysSince)
- MEAN_LONGITUDE_OF_PERIGREE_AT_EPOCH;
return BaseUtils.adjustTo360Range(moonMeanAnomaly);
}
/**
* Private internal class used for lots of computations and corrections
*/
private static class MoonCorrections {
private double moonMeanLongitude;
private double moonMeanAnomaly;
private double sunLongitude;
private double sunMeanAnomaly;
MoonCorrections(double moonMeanLongitude, double moonMeanAnomaly,
double sunLongitude, double sunMeanAnomaly) {
this.moonMeanAnomaly = moonMeanAnomaly;
this.sunMeanAnomaly = sunMeanAnomaly;
this.moonMeanLongitude = moonMeanLongitude;
this.sunLongitude = sunLongitude;
}
/**
* V
*
* @return
*/
public double getVariationCorrection() {
return 0.6583 * sinDegrees(2 * (getCorrectedLongitude() - sunLongitude));
}
/**
* l'
*
* @return
*/
public double getCorrectedLongitude() {
return moonMeanLongitude + getEvictionCorrection()
+ getCorrectionForEquationCentre()
- getAnnualEquationCorrection()
+ getYetAnotherCorrectionTerm();
}
/**
* A 4
*
* @return
*/
private double getYetAnotherCorrectionTerm() {
return 0.214 * sinDegrees(2 * getMoonCorrectedAnomaly());
}
/**
* E c
*
* @return
*/
private double getCorrectionForEquationCentre() {
return 6.2886 * sinDegrees(getMoonCorrectedAnomaly());
}
/**
* M' m
*
* @return
*/
private double getMoonCorrectedAnomaly() {
return moonMeanAnomaly + getEvictionCorrection()
- getAnnualEquationCorrection()
- getUnnamedThirdCorrection();
}
/**
* E v
*
* @return
*/
public double getEvictionCorrection() {
double C = moonMeanLongitude - sunLongitude;
return 1.2739 * sinDegrees(2.0 * C - moonMeanAnomaly);
}
/**
* A e
*
* @return
*/
public double getAnnualEquationCorrection() {
return 0.1858 * sinDegrees(sunMeanAnomaly);
}
/**
* A 3
*
* @return
*/
public double getUnnamedThirdCorrection() {
return 0.37 * sinDegrees(sunMeanAnomaly);
}
}
}
|