Giter VIP home page Giter VIP logo

swiftysphericaltriangle's Introduction

Swift Implementation for Solving Spherical Triangles

Vertices and angles at the vertices are denoted by the same upper-case letters A, B anc C. The sum of the angles is π < A+B+C < 3π

Length of the sides are denoted by lower-case letters a, b and c and represent their central angle, measured in angular units in radians. For a unit sphere, the angle in radians and length are equal.

The radius of the sphere, R, is assumed to be unitary. Conversion from central angle to length of a side is length = angle * R.

In all function calls, R is optional and will be 1 by default. If a value for R is provided then return values for a, b and c will be the side length instead of the central angle.

Usage Example

Suppose the triangle has known angles at vertices A and B with the subtended for the side c in between them, the triangle can be solved using the ASA function. If a value for the optional sphere radius is provided, the returned values for sides a, b and c will be the length of the sides.

let st = sphericalTriangle_ASA(vertex1: angle_A, side3: side_c, vertex2: angle_B, ASA: .AcB)
let side_a = st.a
let side_b = st.b
let angle_C = st.A

where the return type is struct SphericalTriangle.

public struct SphericalTriangle {
  public var A: Double
  public var B: Double
  public var C: Double
  public var a: Double
  public var a_dist: Double { get { return a * R } }
  public var b: Double
  public var b_dist: Double { get { return b * R } }
  public var c: Double
  public var c_dist: Double { get { return c * R } }
  public var R: Double = 1.0
}

Other functions for solving spherical triangles are provided given that the following are known:

  • three sides (SSS)
  • three angles (AAA)
  • two sides and one included angle (SAS)
  • two sides and one adjacent angle (SSA)
  • two angles and one included side (ASA)
  • two angles and one adjacent side (AAS)
  • two angles and two opposite sides (SSAA)
public func sphericalTriangle_SSS(side1: Double, side2: Double, side3: Double, R: Double = 1.0)
public func sphericalTriangle_AAA(vertex1: Double, vertex2: Double, vertex3: Double, R: Double = 1.0)
public func sphericalTriangle_SAS(side2: Double, vertex1 v1: Double, side3: Double, R: Double = 1.0, SAS: optionSAS)
public func sphericalTriangle_SSA(side1: Double, side2: Double, vertex1 v1: Double, R: Double = 1.0, SSA: optionSSA)
public func sphericalTriangle_ASA(vertex1 v1: Double, side3: Double, vertex2 v2: Double, R: Double = 1.0, ASA: optionASA)
public func sphericalTriangle_AAS(vertex1 v1: Double, vertex2 v2: Double, side side1: Double, R: Double, AAS: optionAAS)
public func sphericalTriangle_SSAA(side1: Double, side2: Double, vertex1 v1: Double, vertex2 v2: Double, R: Double = 1.0, SSAA: optionSSAA)

The sides and angles in the calling function are determined using the option enum, for example calling sphericalTriangle_ASA where angles B and C and side a are given, the enum optionASA would be set to .BaC

Swift Package Management

dependencies: [
    .package(url: "https://github.com/firecrestHorizon/SwiftySphericalTriangle.git", from: "0.1.0"),
],

Limitations

Limited testing to-date, works for triangles where any single angle is 0 < angle < π

swiftysphericaltriangle's People

Contributors

kieranconlon avatar

Stargazers

 avatar

Watchers

 avatar

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.