Sundial simulation
Some weeks ago, I have implemented the lighting components in VRMath2 Editor. There are three different lights: point light, directional light, and spotlight. In this blog, I am using the directional light to simulate the sunlight for casting a shadow on a sundial.
The idea is that directional light does not concern about its location. Therefore, we can place a directional light anywhere in the 3D space. Of course, the direction of the directional light will be the direction of the turtle. So we can rotate the turtle to the direction or orientation we like, then insert a directional light. Once a directional light is inserted into the 3D virtual world, it simulates the sunlight as shinning from a far away place and all the light rays are parallel.
In the virtual world created by VRMath2 Editor, the lighting and/or shadow effects will be calculated and displayed instantly (Virtual Reality). I then came up with an idea to animate the directional light, so it will simulate the sun rising from the east and set to the west.
Below are the simulation and programming codes.
As can be seen in the virtual world, we are facing north so east is on the right. I did this because Australia is in southern hemisphere, and the sun will pass through the northern part of the sky. In the program below, I also tilt the light to 23.5 degrees so the shadow will cast on the southern part of the ground.
; Sundial simulation using directionallight ; By Andy Yeh (2014) ; CS RESET SETBG 31 ; set background to black color SETSCALE 3 3 1 ; rectangle is on X-Y plane RU 90 RECTANGLE ; create a 3 x 3 rectagle FD 0.5 RD 90 ; move to a location for the sundial SETSCALE 0.03 1 0.03 ; this dial is 1 meter long, 3cm in diamter CYLINDER ; create a cylinder as the sundial HOME FD 3 SETSCALE 1 1 1 LABEL "North HOME LT 90 TR 23.5 ; Turtle is facing west and tilt right 23.5 DIRECTIONALLIGHT ; create a directional shining toward west MAKE "sun OBJECT ; store directionallight's object name into variable :sun TIMESENSOR "time 24 "true ; create a timesensor for 24 second cycle and enable it MAKE "key [] ; make a variable :key as an empty list MAKE "orilist [] ; make a variable :orilist as an empty list QUEUE "key 0 QUEUE "orilist ORI REPEAT 4 [QUEUE "key REPCOUNT / 4 RD 90 QUEUE "orilist ORI] ORIINT "oi :key :orilist ROUTE "route1 "time "fraction_changed "oi "set_fraction ROUTE "route2 "oi "value_changed :sun "rotation
I set the rotation cycle to 24 seconds for a day, so during the 12 seconds of day time, you should be able to see the shadow moving from the west to the east. And I bet you know why the shadow is moving from west to east.
There are some questions you may have for this simulation.
- If you can trace and plot the shadow, what will be the path of the shadow? Is it a straight line or a curve?
- Can you describe the movement of the shadow with regards to speed, length and time?
- For the purpose of observing the shadow, I set a 23.5 degree tilt to the directional light. What do you think when this will happen? and where it will happen?
- If it is on an equinox day, and this sundial is located at equator, what will be the shadow during the day? How short can the shadow be during the day time?
Please leave me a comment about what you think.
Files: sundial.logo sundial.x3d
- Andy's blog
- Login or register to post comments
- 27086 reads
Comments
That's was incredibly