Giter Site home page Giter Site logo

djben / spacetime Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 4.0 1.64 MB

Astronomical space coordinate and time conversion. Calculate Julian day, local sidereal time and ecliptic obliquity with great precision.

License: GNU General Public License v3.0

Swift 99.06% Objective-C 0.94%
astronomy conversion julian-date equatorial sidereal-time swift-3 coordinate sidereal carthage swift

spacetime's Introduction

Header

SpaceTime

Language License: GPL v3 Carthage compatible Build Status

Overview

Demo

You can find a demo project under SpaceTimeDemo directory. It showcases several useful scenarios.

Screenshot

Installation

Carthage

github "DJBen/SpaceTime" ~> 0.4.0

Usage

Equatorial to horizontal coordinate:

// Supply observer location and timestamp
let locTime = ObserverLocationTime(location: location, timestamp: JulianDay.now)
let vegaCoord = EquatorialCoordinate(rightAscension: radians(hours: 18, minutes: 36, seconds: 56.33635), declination: radians(degrees: 38, minutes: 47, seconds: 1.2802), distance: 1)
// Azimuth and altitude of Vega
let vegaAziAlt = HorizontalCoordinate.init(equatorialCoordinate: vegaCoord, observerInfo: locTime)

Ecliptic coordinate of Pollux at standard equinox of J2000.0.

let ra = DegreeAngle(116.328942)
let dec = DegreeAngle(28.026183)
let eclipticCoord = EclipticCoordinate(longitude: ra, latitude: dec, distance: 1, julianDay: .J2000)
eclipticCoord.longitude.wrappedValue // 113.21563
eclipticCoord.latitude.wrappedValue // 6.68417

Greenwich Mean Sidereal Time:

SiderealTime.init(julianDay: JulianDay.now)

Local Apparent Sidereal Time:

// Get location from GPS or hard code
let locTime = ObserverLocationTime(location: location, timestamp: JulianDay.now)
let localSidTime = SiderealTime.init(observerLocationTime: locTime)

More use cases can be found in the source and test cases.

spacetime's People

Contributors

djben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

spacetime's Issues

enhancement - scenekit / arkit helpers to display planet locations based off user location / JD

I'm looking to display planets based off user location.

Perhaps we can cherry pick some of the code / logic from @calda .
https://github.com/HTN-2017/AR-Planes

https://www.youtube.com/watch?v=dnYHQ-7wlag
screen shot 2018-03-09 at 11 18 31 am

I'm looking for something as trivial as
here's my date / time / coordinate - where is the corresponding planet pluto / mars / etc.
https://github.com/HTN-2017/AR-Planes/blob/master/AR%20Planes/Model/Flight.swift

struct Flight {

// MARK: - Properties

let icao: String
let callsign: String
let longitude: Double
let latitude: Double
let altitude: Double
let noseHeading: Double
let groundVelocity: Double
let verticalVelocity: Double

var location: CLLocation {
    let coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    
    //note: CLLocation also accepts heading and speed, could be useful?
    return CLLocation(
        coordinate: coordinate,
        altitude: altitude,
        horizontalAccuracy: 1,
        verticalAccuracy: 1,
        timestamp: Date())
}

func sceneKitCoordinate(relativeTo userLocation: CLLocation) -> SCNVector3 {
let distance = location.distance(from: userLocation)
let heading = userLocation.coordinate.getHeading(toPoint: location.coordinate)
let headingRadians = heading * (.pi/180)

    let distanceScale: Double = 1/140
    let eastWestOffset = distance * sin(headingRadians) * distanceScale
    let northSouthOffset = distance * cos(headingRadians)  * distanceScale
    
    let altitudeScale: Double = 1/140 //1/20
    let upDownOffset = altitude * altitudeScale
    
    //in .gravityAndHeading, (1, 1, 1) is (east, up, south)
    return SCNVector3(eastWestOffset, upDownOffset, -northSouthOffset)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.