Sunrise & Sunset Calculator - page 2 - General Discussion and Assistance - CHDK Forum

Sunrise & Sunset Calculator

  • 15 Replies
  • 12220 Views
*

Offline reyalp

  • ******
  • 14121
Re: Sunrise & Sunset Calculator
« Reply #10 on: 08 / July / 2009, 19:49:01 »
Advertisements
EDIT... Is this "^" supposed to be XOR?
No, of course not. That wouldn't make sense on floats, would it ? It means "raised to the power" in this context. I'd suggest you familiarize yourself with the math before attempting to implement it.

Keep in mind the camera doesn't have an FPU, so this kind of thing will be very very slow. Depending on your needs a http://en.wikipedia.org/wiki/Lookup_table can be a good workaround on FP impaired platforms. Of course, CHDK is memory impaired as well...
Don't forget what the H stands for.

*

Offline nonno

  • *
  • 15
Re: Sunrise & Sunset Calculator
« Reply #11 on: 09 / July / 2009, 12:04:18 »
EDIT... Is this "^" supposed to be XOR?
No, of course not. That wouldn't make sense on floats, would it ? It means "raised to the power" in this context. I'd suggest you familiarize yourself with the math before attempting to implement it.

Keep in mind the camera doesn't have an FPU, so this kind of thing will be very very slow. Depending on your needs a http://en.wikipedia.org/wiki/Lookup_table can be a good workaround on FP impaired platforms. Of course, CHDK is memory impaired as well...

you're right, but i think that it's not so important the calculation time, it isn't a real time task so you just run it and wait (a reasonable time) for the result. Maybe the power consumpion can be a problem for a long task?

*

MrSpoon

Re: Sunrise & Sunset Calculator
« Reply #12 on: 09 / July / 2009, 12:22:40 »
Lookup table is the way to go IMO. Of course if you're going to include a sine lookup table you could instead just generate a list of sunrise times for the next year on the computer and have the cam read it from a file on the SD card...

Anywho, to optimise a lookup table you could use 'linear interpolation' (averaging between two known points) and 'non-linear sampling' (not taking so many samples when dy/dx is small). There's no doubt lots of example implementations on graphics programming websites :)

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Sunrise & Sunset Calculator
« Reply #13 on: 09 / July / 2009, 14:08:09 »
Lookup tables could of course be loaded from a file when needed only, in both in Lua and in C.


*

Offline Aged

  • *
  • 39
Re: Sunrise & Sunset Calculator
« Reply #14 on: 11 / July / 2009, 15:50:59 »
Here is a compact  Sine calculator script for your perusal which is fairly accurate and quick.
No lookup or FPU needed

rem Parabola Sine Approximation
rem For explanation of method visit:-
rem http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
rem uses 1/10 degree as input, output 1/10000, accuracy varies about 1/1000
rem deg/180 = rad/pi, sine < 10 deg approx = rad

rem rad= deg*pi/180
rem 1st approx.  s= 4d/180(1-d/180)
rem refined by Q= 225/1000 ((s*s) - s) + s

s=0
for i = 5 to 50 step 10
d=i*15 +3
if d < 100 then
     r= d*3550/2034
   print, "Sine(",d/10,".",d %10,")  = 0. 0",r
   
else
rem 1st approximation
   s= (1800-d)*4/18*d/18
rem  refinement   
   k=s/40*9
   p=s-10000
   q=p/100*k /100
rem   print "d,r,Sine-S ",d,r,s,q
   print, "Sine(",d/10,".",d %10,") = 0.",q+s
rem print  "[adjustment] s,K,P q ", s,k,p,q,(q+s)
endif

next i
end

Re: Sunrise & Sunset Calculator
« Reply #15 on: 27 / March / 2013, 20:24:32 »
In case anyone stumbles across this page after a forum search,  this wiki page contains a script that answers the request discussed here :  http://chdk.wikia.com/wiki/Sunrise_and_Sunset_Time_Calculation_Script
Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal