Sunday, October 15, 2023
HomeiOS Developmentios - How can I convert a geographic coordinate (lat/lengthy) to an...

ios – How can I convert a geographic coordinate (lat/lengthy) to an SCNVector3 on a sphere representing the Earth


I’ve an SCNScene with the earth represented by an SCNSphere of radius 1.

I wish to characterize a geographic coordinate for some extent on the earth’s floor by a dot on sphere.

How can I convert a geographic coordinate to an SCNVector3 to place the dot on my sphere.

To date I’ve the next however I am undecided if it is appropriate:

func convertCoordinatesToVector(latitude: Double, longitude: Double, elevation: Double, radius: Double) -> SCNVector3 {
    
    let latRad = latitude * .pi / 180.0
    let longRad = longitude * .pi / 180.0
    
    let x = cos(latRad) * cos(longRad) * Double(radius + elevation)
    let y = sin(latRad) * Double(radius + elevation)
    let z = cos(latRad) * sin(longRad) * Double(radius + elevation)
    
    return SCNVector3(x, y, z)
    
}



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments