【问题标题】:Swift- change star map view according to coordinate and timeSwift-根据坐标和时间改变星图视图
【发布时间】:2017-03-10 22:00:34
【问题描述】:

我正在尝试根据用户的时间和坐标找出纠正我的星图视图的方法,但它并不准确,所以我想知道哪一部分是错误的。

我有两个节点,星图节点和相机节点,相机节点在星图节点内部,使其像 360 度视图。 这是我的方法:

1.获取加速度数据

motionManager.startAccelerometerUpdatesToQueue(NSOperationQueue.currentQueue()!, withHandler: {(accelerometerData, error) -> Void in

    self.outputAccelerationData(accelerometerData!.acceleration)

    if(error != nil) {
        print("\(error)")
    }
})

func outputAccelerationData(acceleration: CMAcceleration) {

    let accZ: Double = fabs(acceleration.z)
    rotateDegreeCameraX = acos(accZ) * 180 / M_PI

}
  1. 将相机节点更正到它正在查看的位置

//让相机节点从看春分开始 //

  private func orientationFromCMQuaternion(attitudeQuaternion: CMQuaternion, trueHeading: Float) -> SCNVector4 { 
    let gq1 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(Float(rotateDegreeCameraX) - 90), 1, 0, 0)
    let gq2 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(180), 0, 0, 1)
    let gq3 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(trueHeading), 0, 0, 1)       
    let gq4 = GLKQuaternionMake(Float(attitudeQuaternion.x), Float(attitudeQuaternion.y), Float(attitudeQuaternion.z), Float(attitudeQuaternion.w))

    let qp = GLKQuaternionMultiply(gq1, gq2)
    let qp2 = GLKQuaternionMultiply(qp, gq3)
    let qp3 = GLKQuaternionMultiply(qp2, gq4)
    let rq = CMQuaternion(x: Double(qp3.x), y: Double(qp3.y), z: Double(qp3.z), w: Double(qp3.w))
    return SCNVector4Make(Float(rq.x), Float(rq.y), Float(rq.z), Float(rq.w))
}
  1. 根据用户的时间和坐标修正星图(SCNshpere)

    func correctOfSkyMap(revolution: Float, rotation: Float, latitude: Float) -> SCNVector4 {

     // rotate the sphere, making Equatorial plane is now same position with Ecliptic plane. (degrees: 23.4397) //
     let gq = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(-23.4397), 0, 0, 1)
    
     // rotate the sphere according to the gap between current date and the date vernal equinox pass 0 longitude //
     let gq2 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(-revolution), 0, 1, 0)
     let qp = GLKQuaternionMultiply(gq, gq2)
    
     // rotate sphere back to where Equatorial plane is //
     let gq3 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(-23.4397), 0, 0, 1)
     let qp2 = GLKQuaternionMultiply(qp, gq3)
    
     // rotate the sphere according to current time //
     let gq4 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(-rotation), 0, 1, 0)
     let qp3 = GLKQuaternionMultiply(qp2, gq4)
    
     // rotate sphere according to user's latitude (adjust the degree of polaris) //
     let gq5 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(latitude - 90), 1, 0, 0)
     let qp4 = GLKQuaternionMultiply(qp3, gq5)
    
     // after comparing with other star gazing app, finding the map needs to rotate 90 degrees to make it more accurate. //
     let gq6 = GLKQuaternionMakeWithAngleAndAxis(GLKMathDegreesToRadians(90), 0, 0, 1)
     let qp5 = GLKQuaternionMultiply(qp4, gq6)
    
     return SCNVector4Make(qp5.x, qp5.y, qp5.z, qp5.w)   }
    
  2. 以下是计算公转和自转的方法:

    func calculateRevolution() -> 浮点数 {

    let degreePerDay: Double = 0.9656112744
    let originalDate = NSDate()
    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
    dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
    let currentDateStr = dateFormatter.stringFromDate(originalDate)
    if let currentDate = dateFormatter.dateFromString(currentDateStr),
        let vernalEquinox = dateFormatter.dateFromString("2016-03-20 04:30") {
    
        let currentDateInSecs = currentDate.timeIntervalSinceDate(vernalEquinox)
        let currentDateInDays = currentDateInSecs / (60 * 60 * 24)
        let rotateDegreesDouble = currentDateInDays * degreePerDay
        let rotateDegrees = Float(rotateDegreesDouble)
    
        return rotateDegrees
    
    } else { return 0.0 }}
    

    func calculateEarthRotation() -> 浮点数 {

    let degreePerMinute: Double = 0.25
    let originalDate = NSDate()
    let dateFormatter = NSDateFormatter()
    dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
    dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
    let originalDateStr = dateFormatter.stringFromDate(originalDate)
    if let currentDate = dateFormatter.dateFromString(originalDateStr) {
        let calendar = NSCalendar.currentCalendar()
        let hours = Double(calendar.component(.Hour, fromDate: currentDate))
        let minutes = Double(calendar.component(.Minute, fromDate: currentDate))
    
        print("pass time: \(hours * 60 + minutes)")
        print("Local date: \(originalDate)")
        print("Date in UTC: \(currentDate)")
    
        return Float((hours * 60 + minutes) * degreePerMinute)
    
    } else {return 0.0}}
    

谁能给我一些建议来准确吗?提前致谢。

【问题讨论】:

  • Idk 如果您正在寻找用户的 精确 位置,但如果用户使用 wifi,您将无法达到该级别的精确度 - 这将近似于您的位置相对于路由器的位置。如果精确位置不是问题,请忽略这一点。
  • @Danoram 我不介意纬度不准确,因为我认为这可能不会对星图产生太大影响。我不知道。我只是想有人帮我检查一下这个纠正我的地图的过程和方法是否正确?因为有时它可能不准确,甚至有180度的差异。我想知道是不是因为我使用真正的航向来旋转我的相机节点?
  • 首先验证你的地图旋转让它旋转,看看它是否围绕北极星旋转(中心应该非常接近它......希望你知道在小熊座哪里可以找到它)如果不是那么你的日和经度旋转是围绕错误的轴....
  • @Spektre 是的,原点星图(我根本不旋转它)北极星在球体的顶部。
  • 然后旋转相机/视图没关系,但您需要确保您的坐标系是正确的,然后才能跳转到项目的下一阶段

标签: swift scenekit astronomy


【解决方案1】:

缩小错误范围。有太多事情可能是错误的,任何人都无法检查。

RA/偏角是否正确?你怎么知道?

对于给定的 RA/decl,您的星星是否出现在外球体的正确位置?你怎么知道?

查看https://stackoverflow.com/help/mcve 并发布与 Playground 兼容的代码 sn-p,我们可以运行并重现您的错误。

带注释的屏幕截图也会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-01
    • 2016-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多