Hey fellas,
Would any of you mind telling me how to calculate the equation of time in VB.Net?
Printable View
Hey fellas,
Would any of you mind telling me how to calculate the equation of time in VB.Net?
Exactly what equation of time would that be? There isn't one almighty equation of time that I'm aware of. Presumably you want to calculate something specific. Please tell us what that is.
T=D/S if I'm not mistaken
T = Time
D= Distance
S= Speed
I think that's the order its in. If you have any two, you can find all three. (Aka, you have time and speed, but not distance, time and distance but not speed, etc)
EDIT: or do you mean this:
Code:http://en.wikipedia.org/wiki/Equation_of_time
Thanks for pointing me to that article, formlesstree4. THAT's what I'm looking for. I actually looked at that article and it's missing some "calculation information."
try typing
apparent solar time and mean solar time calculate
into the search bar of your browser
Thanks for the reply. However, I'd kinda like to see the actual equation here.
in post #3 of this thread there is a link. did you look at it?
Yes, I looked at the link. I've actually checked it out before the guy posted.
So you've actually already got the equation and you want us to help you implement it in VB. That's what you should have said in the first place, and you should have provided that link yourself.
To add to jmc's point; we'll be glad to answer any specific questions you have but we're not going to just do the work for you. This could very well be a homework assignment.Quote:
Originally Posted by jmcilhinney
Please show us what you've attempted thus far.
Well, there's an online JavaScript calculator I tried to copy off of, but for some reason that didn't work. I tried typing a few longitudes into the box, and all the program returned was 0. Turns out it was about 20 minutes off. If any of you will dedicate your time to looking into this code and what I may be doing wrong, that will be great. The code is below, and the calculator is located at http://adsabs.harvard.edu/
Code:Public Class Sun
Dim tzone
Dim _longitude As Integer
Dim y As Integer
Dim m As Byte
Dim d As Byte
Dim t As Byte
Dim _EquationofTime
Private Sub LongCorr(ByVal fm)
tzone = Math.Round(_longitude / 15)
Dim degcorr = _longitude - 15 * tzone
End Sub
Private Function calculateJD(ByVal myDate As DateTime) As Long
y = myDate.Year
m = myDate.Month
d = myDate.Day
Dim t As Byte = Today.Hour + (Today.Minute / 60)
If m > 2 Then
y = y - 1
m = m + 12
End If
Dim a As Byte = Math.Floor(y / 100)
Dim b As Integer = 2 - a + Math.Floor(a / 4)
d += t / 24
Dim JDG As Long = Math.Floor(365.25 * (y + 4716)) + Math.Floor(30.6001 * (m + 1)) + d + b - 1524.5
JDG -= tzone
Dim JD0 As Long = Math.Floor(JDG + 0.5) - 0.5
Return JD0
End Function
Private Function getEquationOfTime(ByVal JD As Integer)
Dim L As Long
Dim e As Long
Dim M As Long
Dim y As Long
Dim ET As Long
Dim radian As Long = 180 / Math.PI
Dim tau As Long
Dim obl As Long
tau = t / 10
obl = 23.439291 - 0.0013 * t
obl = obl / radian
t = (JD - 2451545.0) / 36525
L = 280.46644567 + 360007.6982779 * tau + 0.03032 * tau * tau + Math.Pow(tau, 3) / 49931 - Math.Pow(tau, 4) / 15299
L = L / radian
M = 357.05291 + 35999.0503 * t - 0.0001559 * t * t - 0.00000048 * t * t * t
M = M / radian
e = 0.01670617 - 0.000042037 * t - 0.0000001236 * t * t
y = Math.Pow(Math.Tan(obl / 2), 2)
ET = y * Math.Sin(2 * L) - 2 * e * Math.Sin(M) + 4 * e * y * Math.Sin(M) * Math.Cos(2 * L) - y * y / 2 * Math.Sin(4 * L)
Return ET
End Function
Public Sub getSunData(ByVal longitude As Integer)
Dim JD0 As Integer = calculateJD(Today)
Dim JD1 As Integer = JD0 + ((t - tzone) / 24)
If t - tzone >= 24 Then
JD1 -= 1
End If
_EquationofTime = getEquationOfTime(JD1)
End Sub
Public ReadOnly Property EquationofTime()
Get
Return _EquationofTime
End Get
End Property
End Class
i didn't see a formula in the link you posted. i suggest you add the formula as a comment to your code.
based on the formula's i saw on a wiki you may want to move this thread to the math forum.
You can't see it, because it's actually kinda scattered about like so:
The getSunData() method, which needs to be called first in order for the program to get anything but a null value, calls the function calculateJD(), passing along the Date object as an argument, then it calls the function getEquationOfTime() (passing along the Julian date as an argument), which then calculates and returns the equation of time.
It seems very complicated, check your code again, to see if you made a typo, or something is not getting assigned. You should also put this at the top:
That is a good way to see if your code contains any errors that a general check won't get. I did it on mine, and I had an additional 16 errors in one application I thought was debugged.vb Code:
Option Strict On
Dear formlesstree4,
Thanks, I'll remember that next time I get a bug. But, one last question before I dismiss the forum. There WAS an error that VB.Net DID catch. For some strange reason, the Date.Now.Minute & Date.Now.Hour properties always seem to return 0. And this is a bad thing, because I want my class library to actually be able to give me the equation of time, as well as the solar time.
Sincerely,
Montana
no it does not. post your code that refs. date.now.minute
Oh, yeah, I took that part out of the class library's code. Here it is:
Code:Public ReadOnly Property SolarTime()
Get
Return Date.Now.Hour + (Date.Now.Minute / 60) + EquationofTime
End Get
End Property
couple of things.
Specify a return type for your property. If its a string (which i assume it is) then call the static ToString() method at the end.
Try putting a breakpoint there and see if the value is what you really expect.
Well, I tried using Option Strict On & setting a breakpoint..a thank you to those who suggested doing those two things...but it still did not help. Equation of time property still returns zero. Checked it using an online solar tempometer.
Code:Public Function SolarTime() As Double
Return Date.Now.Hour + (Date.Now.Minute / 60) + EquationofTime
End Function
To everyone who tried to help me solve this problem,
Thank you for doing so. The solution is in an e-book located at http://adsabs.harvard.edu/, thus I hereby dismiss you all from helping me solve this problem.