Results 1 to 21 of 21

Thread: [RESOLVED] [2008] Calculating the equation of time

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Resolved [RESOLVED] [2008] Calculating the equation of time

    Hey fellas,

    Would any of you mind telling me how to calculate the equation of time in VB.Net?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Calculating the equation of time

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Re: [2008] Calculating the equation of time

    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

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the 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."
    Last edited by mburr; Oct 9th, 2008 at 10:52 AM.

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Calculating the equation of time

    try typing

    apparent solar time and mean solar time calculate

    into the search bar of your browser
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    Thanks for the reply. However, I'd kinda like to see the actual equation here.

  7. #7
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Calculating the equation of time

    in post #3 of this thread there is a link. did you look at it?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  8. #8

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    Yes, I looked at the link. I've actually checked it out before the guy posted.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] Calculating the equation of time

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Calculating the equation of time

    Quote Originally Posted by jmcilhinney
    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.

    Please show us what you've attempted thus far.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  11. #11

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    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

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Calculating the equation of time

    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.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    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.

  14. #14

    Re: [2008] Calculating 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:
    vb Code:
    1. Option Strict On
    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.

  15. #15

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    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

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Calculating the equation of time

    no it does not. post your code that refs. date.now.minute
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  17. #17

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    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

  18. #18
    Fanatic Member
    Join Date
    Feb 2006
    Posts
    607

    Re: [2008] Calculating the equation of time

    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.

  19. #19

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [2008] Calculating the equation of time

    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.

  20. #20
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Calculating the equation of time

    Code:
        Public Function SolarTime() As Double
            Return Date.Now.Hour + (Date.Now.Minute / 60) + EquationofTime
        End Function
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  21. #21

    Thread Starter
    Member
    Join Date
    Dec 2007
    Posts
    56

    Re: [RESOLVED] [2008] Calculating the equation of time

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width