Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sun vector

Started by kaarigar Feb 24, 2009 at 11:44 AM 10 replies 2k views
Original Post
kaarigar
kaarigar
My apologies for asking a simple question. Given a point on earth (in latitude/longitude) and Sun's position (in azimuth/altitude), how can I find a vector pointing to the sun from point on earth and a vector pointing to the point on earth from sun? I need to feed this vector in ray/triangle intersection algorithm. Will appreciate any help - I am not a mathematician :(
Zakwayda
Zakwayda
I'm not sure what the frame of reference is here, but one way or another I think this will come down to a couple of spherical-to-Cartesian coordinate conversions: one to find a point on the Earth's surface given the point's latitude and longitude, and one to find the position of the sun relative to that point (although, again, I'm not sure what the frame of reference is here).

From there, finding the vectors you need is simple, and involves a single vector subtraction and a single vector negation.

A search for 'spherical coordinates' should lead you to the conversion algorithm you need, but post back if you have any trouble beyond that.
kaarigar
kaarigar
Quote:
Original post by jyk
I'm not sure what the frame of reference is here, but one way or another I think this will come down to a couple of spherical-to-Cartesian coordinate conversions: one to find a point on the Earth's surface given the point's latitude and longitude, and one to find the position of the sun relative to that point (although, again, I'm not sure what the frame of reference is here).

From there, finding the vectors you need is simple, and involves a single vector subtraction and a single vector negation.

A search for 'spherical coordinates' should lead you to the conversion algorithm you need, but post back if you have any trouble beyond that.


The point on the earth is considered to be the origin of the coordinate space - that is the frame of the reference.

I had looked up the spherical to cartesian conversion (x = r*Cos(theta)*Sin(phi) etc.) - but I was concerned by the r parameter. In my case it represents the distance between the sun and the point on the earth. However, since I am interested in the vector to the sun only, can I consider r = 1?

Thanks!
Zakwayda
Zakwayda
Quote:
The point on the earth is considered to be the origin of the coordinate space - that is the frame of the reference.

I had looked up the spherical to cartesian conversion (x = r*Cos(theta)*Sin(phi) etc.) - but I was concerned by the r parameter. In my case it represents the distance between the sun and the point on the earth. However, since I am interested in the vector to the sun only, can I consider r = 1?

Thanks!
A single point does not uniquely define a frame of reference. The elevation can be relative to the surface normal at this point, of course, but what is the azimuth in respect to? (That's the part I'm not quite getting...)

Since the position of the sun is relative to the point on the earth's surface, then yes, I think you can just consider the radius to be 1 for the purpose of the coordinate conversion.
CPPNick
CPPNick
what is the purpose of this vector? are you trying to find the length of it? or just display it graphically?
I guess what I am asking is if it needs to be done to scale? and will the output be graphical or text
and what will be the given input for the program?
kaarigar
kaarigar
Quote:
A single point does not uniquely define a frame of reference. The elevation can be relative to the surface normal at this point, of course, but what is the azimuth in respect to? (That's the part I'm not quite getting...)

I should have mentioned that this is in a coordinate space defined by a celestial sphere where the point on earth is at its center, and the equatorial plane of this sphere is the XY plane, where azimuth is measure clockwise from the northline.
Quote:

Since the position of the sun is relative to the point on the earth's surface, then yes, I think you can just consider the radius to be 1 for the purpose of the coordinate conversion.

Thanks for this clarification.

That was a very important tip, thank you very much :)

[Edited by - kaarigar on February 25, 2009 3:22:59 PM]
kaarigar
kaarigar
Quote:
Original post by CPPNick
what is the purpose of this vector? are you trying to find the length of it? or just display it graphically?
I guess what I am asking is if it needs to be done to scale? and will the output be graphical or text
and what will be the given input for the program?

Here's the background information. There is an object at a location on earth. It's location is specified in lat/long, geographic coordinates, unit is decimal degrees. There are also some other objects around that cast shadow due to the sun. Let's call them obstructions. These obstructions have been triangulated.

I am trying to find out if this object is in the shadow of the obstruction at given time. I am using NOAA's algorithm to get the sun position (azimuth, elevation) for the given time.

Given that I know the sun position, and the position of the object, I can define a vector using them, and determine if it intersects the obstruction. If it does, then it means that it is the shadow. I am using Moller-Trumbore ray-triangle intersection routine for this purpose.

So, basically I want to define the direction that I can use to feed into the Moller-Trumbore for intersection check. I am not interested in distance, ot graphical or textual representation of any kind. I hope I was able to make this clear.
CPPNick
CPPNick
Okay, we will use a left handed coordinate system:


This is what I understand:

1) We have decided that the position on earth is at the origin(0, 0, 0) of our coordinate system.

2) We have the dimensions of the surrounding objects, and have created triangles/polygons in 3 dimensional space to represent them in the correct scale.

3) We have the position of the sun in (X, Y, Z) coordinates, calculated by your formula with azimuth & altitude, for a given position on the earths surface, at a given time and date. The position of the sun must also be in the same scale(centimeters, feet, miles, ect) as the representations of the obstructions.

4) We have to find out whether or not the line drawn from the origin(0,0,0) to the sun(X, Y, Z) intersects the triangles/polygons that represent the obstruction,

correct?
if so, which steps exactly are you missing?
kaarigar
kaarigar
Quote:
Original post by CPPNick
Okay, we will use a left handed coordinate system:

This is what I understand:

1) We have decided that the position on earth is at the origin(0, 0, 0) of our coordinate system.

Position on the earth is at the origin for the purpose of determining sun's position and sunrise/sunset time - sorry if I was ambiguous about it. The origin of the geographic coordinates is at where Greenwich line intersects the equator line.
Quote:

2) We have the dimensions of the surrounding objects, and have created triangles/polygons in 3 dimensional space to represent them in the correct scale.

True
Quote:
3) We have the position of the sun in (X, Y, Z) coordinates, calculated by your formula with azimuth & altitude, for a given position on the earths surface, at a given time and date. The position of the sun must also be in the same scale(centimeters, feet, miles, ect) as the representations of the obstructions.

This is where the confusion is. The sun position is in azimuth/elevation, whose units is degrees. The position on earth is also in decimal degrees. However, the sun has its azimuth measured clockwise from the northline - while the earth's lat/lon are with reference to the Greenwich line for longitude and Equator for latitude. It seems that one will have to be projected into the another.
Quote:
4) We have to find out whether or not the line drawn from the origin(0,0,0) to the sun(X, Y, Z) intersects the triangles/polygons that represent the obstruction,

Yes. Except that object may not necessarily be at the origin.


kaarigar
kaarigar
Quote:
Original post by CPPNick
Okay, we will use a left handed coordinate system:

This is what I understand:

1) We have decided that the position on earth is at the origin(0, 0, 0) of our coordinate system.

2) We have the dimensions of the surrounding objects, and have created triangles/polygons in 3 dimensional space to represent them in the correct scale.

3) We have the position of the sun in (X, Y, Z) coordinates, calculated by your formula with azimuth & altitude, for a given position on the earths surface, at a given time and date. The position of the sun must also be in the same scale(centimeters, feet, miles, ect) as the representations of the obstructions.

4) We have to find out whether or not the line drawn from the origin(0,0,0) to the sun(X, Y, Z) intersects the triangles/polygons that represent the obstruction,

correct?
if so, which steps exactly are you missing?

I think I got it. I need not worry about the coordinate space of the point on earth - as long as I have the correct vector pointing to the Sun from that point. Thus, using the sun azimuth and elevation, I can calculate the vector in classical way (x = Cos(elev) * Cos(azim), y = Cos(elev) * Sin(azim), z = Sin(elev)). I can use that vector as direction in the ray-triangle intersection routine. Am I right?
CPPNick
CPPNick
ya, sounds right. That took some thinking though =) good luck
kaarigar
kaarigar
Quote:
Original post by CPPNick
ya, sounds right. That took some thinking though =) good luck

Yes, indeed. Your posts made me think :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.