问题的根本在于球形坐标系与笛卡尔坐标系之间的转换方式。为了正确地将球形坐标转换为笛卡尔坐标并在ARKit中添加点,您可以使用以下代码示例:
let radius: Float = 0.1 // Radius of sphere
let theta: Float = Float(arc4random_uniform(360)) // Theta is between 0 to 360
let phi: Float = Float(arc4random_uniform(360)) // Phi is between 0 to 360
let x = radius * sin(theta) * cos(phi)
let y = radius * sin(theta) * sin(phi)
let z = radius * cos(theta)
let position = SCNVector3(x: x, y: y, z: z)
let node = SCNNode(geometry: SCNSphere(radius: 0.01))
node.position = position
sceneView.scene.rootNode.addChildNode(node)
这段代码将随机生成一个球形坐标,并将其转换为笛卡尔坐标。然后,您可以将添加具有适当位置的SCNNode以创建点。