Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    longitude / latitude on sphere

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 508 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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)

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post