longitude / latitude on sphere

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 27/10/2012 at 16:17, xxxxxxxx wrote:

Below is a piece of that I used to convert longitude / latitude to sphere coordinates.
However, it is not working and I cannot see what I do wrong.

Input e.g. New York lat=40.714, lon=-74.606 and radius=100

longitude = c4d.utils.Rad(lat)
  latitude = c4d.utils.Rad(lon)
 
  x = radius * math.cos(latitude)*math.cos(longitude)
  y = radius * math.cos(latitude)*math.sin(longitude)
  z = radius * math.sin(latitude)
 
  sphereobj = c4d.BaseObject(c4d.Osphere)        # Create new sphere
  sphereobj[c4d.PRIM_SPHERE_RAD] = 20            # set sphere label radius
  sphereobj.SetRelPos(c4d.Vector(x,y,z))         # Set position of sphere
  doc.InsertObject(sphereobj)

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/10/2012 at 13:51, xxxxxxxx wrote:

Can you be more specific about what "not working" means?
I tried it like this and it seems to be working as expected:

import c4d  
import math  
def main() :  
  lat = 40.714  
  lon = -74.606   #New York  
  radius=100   
  
  longitude = c4d.utils.Rad(lat)  
  latitude = c4d.utils.Rad(lon)  
   
  x = radius * math.cos(latitude)*math.cos(longitude)  
  y = radius * math.cos(latitude)*math.sin(longitude)  
  z = radius * math.sin(latitude)  
  
  sphereobj = c4d.BaseObject(c4d.Osphere)        # Create new sphere  
  sphereobj[c4d.PRIM_SPHERE_RAD] = 20            # set sphere label radius  
  sphereobj.SetName("NY")                        #Set the name of the sphere  
  sphereobj.SetRelPos(c4d.Vector(x,y,z))         # Set position of sphere  
  doc.InsertObject(sphereobj)    
  c4d.EventAdd()  
  
if __name__=='__main__':  
  main()

-ScottA

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 28/10/2012 at 15:02, xxxxxxxx wrote:

Hi pgroof,

here's a function I used in a plugin I made for a client.

def llarToWorld(lat, lon, alt, rad) :  
  # see: http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html  
  f  = 0                              # flattening  
  ls = atan((1 - f)**2 * tan(lat))    # lambda  
  
  x = rad * cos(ls) * cos(lon) + alt * cos(lat) * cos(lon)  
  z = rad * cos(ls) * sin(lon) + alt * cos(lat) * sin(lon)  
  y = rad * sin(ls) + alt * sin(lat)  
  
  return c4d.Vector(x, y, z)

-Nik

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/10/2012 at 03:36, xxxxxxxx wrote:

ScottA, thanks, triggered by your remark I tried again.
Changing y = -y + set the globe tp -90,90,-90 helped.
It is ok now.

Hi NiklasR, yes, what you are using is the flattened version of the algorithm.

Thanks for your help.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/10/2012 at 03:37, xxxxxxxx wrote:

Sorry,
Changing y = -y + set the globe tp -90,90,-90 helped.

should be
Changing y = -y + set the globe to -90,90,-90 helped.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 29/10/2012 at 03:39, xxxxxxxx wrote:

Or even better (I'm missing the edit function here) :

Changing y to -y (y=-y) and setting the rotation of the globe to -90,90,-90 solved the issue.