# Thread: Sun movement in three dimensional coordinate system

1. ## Sun movement in three dimensional coordinate system

Hello

I'm creating simple 3D program for designing house and it involves sun movement (to see the brightness of the building at certain time).

As title says, I have three dimensional coordinate system and I have already defined the sun location at the certain time of the day

Code:
// where angle is from 0 to 180, it increments by 180/24h
x = -Math.cos(angle * Math.PI / 180);
y = Math.sin(angle * Math.PI / 180);
z = 0;
this code works if z is always the same.

My goal is to be able to rotate coordinate system (to rotate xy around z) so that I get new (virtual) x and y-axes. How should I change my formulas so that when I rotate my cs, the sun movement is still aligned with new x axis? (y stays the same, I need to modify x in z formulas).

I hope my question is clear enough. Thanks for your help in advance

Erdo

2. I'm afraid I can't tell what you're trying to do with your code, but it sure looks far too simple. I suspect you need to start from a rigorous framework so that you know what you're doing. If I were to do this, these are the parameters by which I would define the problem, I think:

constants:
1. The earth's axis of rotation relative to the sun (this can be assumed constant at 23.5 degrees)
2. The angle of your house's location relative to the north pole - at the north pole would be 0, pi/2 is on the equator, pi is south pole.
3. The angle you are facing at this position on the Earth's surface. Say you have a south-facing window.

domain variables (parameters):
1. The current time within the day (0 through 2*pi, where one period is one sidereal day, which is 23 hours, 56 minutes and 4 seconds). 0 would be midnight with the time within the year equal to 0.
2. The current time within the year. Equal to 0 in the dead of winter (if you're in the Northern hemisphere). Ok, so January 1 isn't the solstice, but you can worry about fudge factors like that later.

range variables (functions to calculate):
1. The theta spherical coordinate of the sun in the sky from the chosen vantage point (constant #3)
2. The phi spherical coordinate of the sun in the sky from the chosen vantage point (constant #3)

Just set it up this way and it should conceptually fall into place, I think. You can check your solution from known results, for instance at the North or South poles, the periodic variations due to domain variable 1, the time within the day, should fall to 0, at 23.5 degrees (the arctic circle) the magnitude of the daily variation should be just large enough in magnitude so that in the middle of summer the sun falls exactly to the horizon (spherical coordinate phi is pi/2) at midnight and in the middle of winter for it to just reach the horizon at noon, and at the lines of tropics, for the phi coordinate to be able to reach 0 or pi only on the solstices.