-1

I currently am able to calculate the Altitude and Azimuth of the Sun on a given Datetime, now I would like to be able to point an arrow from any current position on Google Map towards the direction of the Sun (based on Altitude coordinates and Azimuth).

I am working on a app which is suppose to show a user the direction to the sun from users current location.

Any ideas very welcome.

Toothfairy
  • 383
  • 1
  • 6
  • 24
  • Since it is a 2D map, the altitude does not play a role. Depending on the coordinate system that you use, you would use sine and cosine to get the arrow components (e.g. `(-sin(azimuth), cos(asimuth))`, this assumes that y is the north-south axis and x is the west-east axis and both axes are proportional to each other). – Nico Schertler Oct 24 '16 at 16:17
  • Thank you for your comment... What does this mean in practical terms if using Google Maps which uses Altitude and Longitude? Lets assume Azimuth has the value of 0.13224351331114464. How do you think I could get a location on google maps from: Sin(0.13224351331114464) and Cos(0.13224351331114464) ? – Toothfairy Oct 24 '16 at 17:57
  • What do you need? Coordinates on the screen or latitude/longitude coordinates on the globe? – Nico Schertler Oct 24 '16 at 19:13
  • Coordinates on the screen, on a simple Google map similar to suncalc.net/#/51.508,-0.125,2/2016.10.24/17:26 – Toothfairy Oct 24 '16 at 19:16
  • Then the calculation above gives you the direction in pixel coordinates. Just add a reasonable multiple (the radius) of it to the current location and you get your point. – Nico Schertler Oct 24 '16 at 20:01
  • is pixel coordinates compatible with Google Map format? "reasonable multiple" Do you mean a reasonable radius of the Sun? Sorry for my confusion and thank you for your time... Just to confirm: Sin(0.13224351331114464) = Altitude Cos(0.13224351331114464) = Longitude, correct? – Toothfairy Oct 24 '16 at 20:06
  • I think, you might need to refresh your understanding of the involved coordinate-systems. The globe uses latitude/longitude (not altitude!), the direction of an object in the sky is expressed in the tangent plane by altitude and azimuth, screen coordinates are just coordinates on your screen (usually the upper left corner is the origin) and are usually expressed as x/y. – Nico Schertler Oct 24 '16 at 20:13
  • Sorry it was a mistype, what I need is Latitude and Longitude which is the coordinate system used by Google Maps. My problem is I cannot figure out how to, on a map using the coordinate system of Longitude/Latitude , x / y figure out the direction of the Sun based on the values of Altitude and Azimuth. Thank you for the advice, I will refresh them however this came a little bit urgent. – Toothfairy Oct 24 '16 at 20:27

1 Answers1

1

Given geo-coordinates lat (positive for north) and long (positive for east), the 3D-coordinates on the globe are (one possibility):

    / x \   / cos(lat) * sin(long) \
p = | y | = | cos(lat) * cos(long) |
    \ z /   \ sin(lat)             /

The north direction is then:

        / -sin(lat) * sin(long) \
north = | -sin(lat) * cos(long) |
        \  cos(lat)             /

And the east direction is:

       /  cos(lat) * cos(long) \
east = | -cos(lat) * sin(long) |
       \  0                    /

Given azimuth and altitude, you can get the 3D direction as:

dir = (-cos(azimuth) * north -sin(azimuth) * east) * cos(altitude) + sin(altitude) * p

Hence, for any positive scalar t, you can calculate a point between your position on the globe and the object:

pos(t) = p + t * dir

You can project the position back onto the globe by normalization:

pos_normalized(t) = pos(t) / ||pos(t)||

, where ||pos(t)|| is the length of pos(t).

And given this, you can calculate latitude and longitude:

lat2 = asin(pos_normalized(t).z)
long2 = atan2(pos_normalized(t).x, pos_normalized(t).y)

This is one point that lies in the direction of the sun. Choose some sufficiently small t to calculate it (it should be much smaller than 1; the unit is basically multiples of earth radius). For certain maps, all these positions may lie on a line. However, this is not guaranteed for arbitrary maps. So you might want to sample a few points and generate a polyline instead.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70