/Graviton

Real-time night sky rendering and planetarium in Swift 4 with native SceneKit and Metal.

Primary LanguageSwiftGNU General Public License v3.0GPL-3.0

Header image

Graviton 🌌

Language Build Status codebeat badge License: GPL v3

  • Real-time night sky and solar system rendering.
  • Astronomy and celestial mechanics toolkit.
  • Native Apple technologies with Swift 4 and SceneKit.

App

  • Real-time night sky rendering. Fully customizable. Totally hackable.
    • Reading from GPS or inputing custom position to see a night sky in your location.
    • Time warp - see what night sky is like at any time.
  • Real-time high accuracy solar system illustration. In scale.
  • Detailed celestial body information. Rise, transit and set information panel for ☀️, 🌛 and naked-eye planets.

Screenshots

Stellarium Planets Metadata Celestial body
main planets rts celestial-body

Getting Started

Xcode 14, iOS 16 is required. This app is built with Swift Package Manager, open Graviton.xcodeproj.

Features

The work is primarily done in the year of 2017 and 2018. It is frozen as of Jul 2023.

Stellarium

  1. View the simulated night sky at your local position and local time. Find the constellations and solar system plants.
  2. Time warp to any time in the past and future to view the predicted night sky.
  3. Browse the celestial object catalog, search the desired celestial objects and inspect their physical properties.

Planets

  1. View the real-time solar system.
  2. Goes forward in time to see the motion of heaven.

Information

  1. Astronomic properties including Julian date, LST offset and more.
  2. Rise, transit and set time of the sun, the moon and all planets.

Two websites are planned to be built. One includes all documentation, the other is a shiny front page for maximum appeal.

This project is a monorepo that also contains multiple useful frameworks. See below section.

Goals

Outdated

This is an amateurish project by an amateur astronomer. As a lover of science and space exploration, there are a few long-term goals:

  • A full-fledged open source stellarium software
  • An educational astronomy app with science in mind
  • (?) A space flight simulator that utilizes patched conics approximation.

Copyright

This project is licensed under GPLv3. If you have issues with any assets or resources in Graviton, please don't hesitate to reach out DJBen.

Frameworks

Orbits

High accuracy ephemeris query and orbital mechanics calculation framework.

  • Calculate Keplarian orbital mechanics with support of all conics.
  • Query and process high accuracy ephemeris from NASA JPL's Horizon interface and automatically cache results using Realm and SQLite.
  • Excellent offline mode. Stock ephemeris from 1500 AD to 3000 AD of major celestial bodies.
  • Support querying rise, transit and set timestamps for major celestial bodies.

Conics model predicts the orbits of the major planets in our solar system pretty accurately. To account for apsidal precession and other orbital perturbations of celestial bodies like Mercury and Earth's moon, Orbits fetches many data points from JPL and cherry-pick the orbital configuration closest to the reference time.

Header image

StarryNight

Language License: GPL v3

Overview

StarryNight is all you need for curiosity towards stars and constellations.

  • Database of 15000+ stars within 7th magnitude.
    • Star Catalogs including HR, HD, HIP, Gould and Bayer-Flamsteed designations.
    • Celestial coordinate and proper motion.
    • Visual and absolute magnitude, luminance, spectral type, binary star info, and other physical properties.
  • Extended Constellation support.
    • Position query and inverse position query.
    • Constellation line and constellation border.
    • Abbreviation, genitive and etymology.

Usage

Stars

  1. All stars brighter than...
Star.magitudeLessThan(7)
  1. Star with specific designation.
Star.hr(9077)
Star.hd(224750)
Star.hip(25)
  1. Star closest to specific celestial coordinate.

This is very useful to locate the closest star to user input.

let coord = Vector3.init(equatorialCoordinate: EquatorialCoordinate.init(rightAscension: radians(hours: 5, minutes: 20), declination: radians(degrees: 10), distance: 1)).normalized()
Star.closest(to: coord, maximumMagnitude: 2.5)
// Bellatrix

Constellations

  1. Constellation with name or IAU symbol.
Constellation.iau("Tau")
Constellation.named("Orion")
  1. Constellation that contains specific celestial coordinate.

This is very useful to locate the constellation that contains the region of user input.

It is implemented as a category on EquatorialCoordinate. See SpaceTime repo for implementation and usage of coordinate classes.

let coord = EquatorialCoordinate.init(rightAscension: 1.547, declination: 0.129, distance: 1)
coord.constellation
// Orion
  1. Neighboring constellations and centers.
// Get a set of neighboring constellations
Constellation.iau("Ori").neighbors
// Get the coordinate of center(s) of current constellation
Constellation.iau("Ori").displayCenters

Note: displayCenters returns an array of one element for all constellations except Serpens, which will include two elements - one center for Serpens Caput and the other for Serpens Cauda.

Remarks

Data extracted from HYG database and processed into SQLite. The star catalog has been trimmed to 7th magnitude to reduce file size. Feel free to download the full catalog and import into SQLite whenever you see fit.

Header

SpaceTime

Language License: GPL v3

Overview

Demo

Screenshot

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.

Startracker

A startracker is included to obtain precise alignment to the stars when viewing at night. To compile the app/run tests, you will first need to download the image files from: https://drive.google.com/drive/folders/1aB7_yC7U4iHJOtRk4fT2sOnFLDsacUH5?usp=sharing. The directories in the drive correspond to directories in this repo. Place the files into the corresponding repo directory.

To further develop/test the startracker, there are two methods:

  1. Simulation code from Python (see py/README.md)
  2. Real images where stars have been externally identified. These images should ideally come from the long-exposure photo capture functionality in Graviton's startracker, as those images would represent what the app could realistically capture. The app saves all photos to the photo library to facilitate this type of debugging.

Both types of images can be converted into unit tests on the Swift side.

Coordinare Systems

The following are differrent coordinate systems used throughout the codebase. A transformation between two coordinate systems is denoted T_{space_to}_{space_from}.

Ceq (Catalog Equatorial)

  • The catalog is full of vectors in the Equatorial coordinate system

Cc (Catalog Camera)

  • Cameras should have +x being horizontal to the right, +y being vertical and downwards, and +z point out of the camera to the scene. The Cc system refers to a hypothetical camera placed at the same origin/orientation as the Ceq system, but using camera conventions.

Meq (Mobile Equatorial)

  • The mobile view in Equatorial coordinate system

Mc (Mobile Camera)

  • The mobile camera system