I have not taken a math class outside statistics since about 2001… I know that for some people this will be easy but for me it lives just outside my ability.

I am working on a program to control some lights for my aquarium. I would like to simulate a sunrise and sunset with the brightness of my light. The only thing I have left so far is the brightness of my light.

To keep it simple I want to design math algorithm as follows.

  • In my head I see a sine wave but I am only worried about positive numbers.
  • I would like values from 0-1. 0 is sunrise and sunset, 1 is full brightness. The y-axis is going to represent the intensity of the sun.
  • The length of the day is going to me variable could be represented in minutes/seconds etc. Time is going to be graphed on x-axis

So… In a nut shell this is my question: Given the time of sunrise and sunset I can derive length of the day. I would like to know how I could get the intensity of any given point between sunrise and sunset. I want to write my function so that the variables are sunrise, sunset, and current time and be able to determine intensity. What is the math going to look like on this?

If you need more clarification let me know.


As I play with a graphing calculator I am starting to like what I see BUT… I still can't nail it down…

y=-1/2 cos(x)+.5 gives a nice curve. But… Now how do I translate that to time. I want the first time the line hits y=0 to represent sunrise then the first time the line hits y=1 to represent solar noon and the second time y=0 to represent sunset.

  • $\begingroup$ A simple approximation: Let $y(t)=\left.\begin{cases}0&\text{if $t<r$,}\\\dfrac{4(t-r)(s-t)}{(s-r)^2}&\text{if $r\le t\le s$,}\\0&\text{if $t>s$,}\end{cases}\right\}$ where $r$ and $s$ are time of sunrise and sunset. $\endgroup$
    – user856
    Oct 3, 2014 at 4:37
  • $\begingroup$ @Rahul your approximation is beautiful but 1- it doesn't simulate sine 2- it doesn't cover values from 0-1 (not normalized) $\endgroup$
    – chouaib
    Oct 3, 2014 at 5:22
  • 2
    $\begingroup$ @chouaib: (1) Neither does sunlight necessarily, and (2) yes it does. $\endgroup$
    – user856
    Oct 3, 2014 at 5:29
  • $\begingroup$ @Rahul: (1) Nor a parabola! shouldn't we stick to the question's specifications? btw curious to know the sunlight intensity's equation, (2) Sorry, my mistake $\endgroup$
    – chouaib
    Oct 3, 2014 at 5:55
  • $\begingroup$ Thanks for the help guys. Rahul thanks for thinking outside the question a bit. While I understand this does not exactly represent the intensity of the sun... Both do a wonderful job at describing what I was trying to do. $\endgroup$ Oct 3, 2014 at 15:17

1 Answer 1


you want to use Y = Asin(BX+C) such that the upper part (positive) will be your dayTime, OK:

sin(x) varies in the positive Y-axis range when x varies between [0, $\pi$] in radians

Assume the day is regulated to fit [0, 24] hours

$$ sunrize = sr$$ $$ sunset = ss$$

length of the day (bright side) will be [ss-sr] (whatever the unit of time you use) this should be equal to $\Pi$

Let's apply it to our sine-function :

$$Y = A\sin(\frac{pi}{(ss-sr)}x)$$

Notice that this graph will start from time x=0 but simulate the daytime exactly , to get it starts from the exact sunrize, we have to consider the constant C in the first equation :

$$Y = A\sin(\frac{\pi}{(ss-sr)}x + C)$$

at time x = sr Y = 0, solve for that :

$$0 = A\sin(\frac{\pi}{(ss - sr)}sr + C)$$ $$C= -\frac{\pi*sr}{ss- sr}$$

that's all , to resume :

$$ Y = \left\{ \begin{array}{rl} A\sin(\frac{\pi}{(ss-sr)}x -\frac{\pi*sr}{ss- sr}) &\mbox{ if sr <= x <= ss}\\ 0 &\mbox{ otherwise} \end{array} \right. $$

  • $\begingroup$ Is there any significance in your capital pi there? $\endgroup$ Oct 3, 2014 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.