Skip to content

skrovina/SKLinearAlgebra

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SKLinearAlgebra

Build Status

This library allows common vector operations using SceneKit's native types: SCNVector3, SCNVector4, and SCNMatrix4. It also provides useful linear algebra functions for 3D graphics.

It has been written in the style of Swift, intending to enhance and complete Scenekit's existing functions.

Features

Tests are complete for all implemented features.

Operations

  • equality (==)
  • inequality (!=)
  • equivalence (~=)
    • Returns true if the components are close to equal to each other.
  • inequivalence (!~=)
  • addition (+, +=)
  • subtraction (-, -=)
  • dot product (*)
  • scalar multiplication (*, *=)
  • scalar division (/, /=)
  • cross product (×)
  • subscript access (v[0], m[1, 2])
    • Zero based indexing
    • Access by [row, column]

Functions

  • cross product (cross(a: Vector, b: Vector))
  • magnitude (magnitude(v: Vector))
  • normalize (normalize(v: Vector))
  • angle between (angle(a: Vector, b: Vector))
  • component (component(a: Vector, b: Vector)) - comp_{b} a
    • Read this as "the component of a onto b", it would be written comp_{b} a.
  • projection (projection(a: Vector, b: Vector))
    • Read this as "the projection of a onto b", it would be written proj_{b} a
  • determinate (det(m: Matrix))
  • transpose (transpose(m: Matrix))
  • inverse (inverse(m: Matrix))

Usage

The documentation for using a custom Swift library is lacking at the moment, but my process has been as follows:

  1. Clone [email protected]:apexskier/SKLinearAlgebra.git into your project directory.
  2. Drag SKLinearAlgebra.xcodeproj into your Xcode project.
  3. Select your project, select your target, under General find "Linked Frameworks and Libraries".
  4. Add SKLinearAlgebra.framework, either from the + button or by dragging in SKLinearAlgebra/Products/SKLinearAlgebra.framework from the project navigator.
// Example import statements

import SceneKit
import SKLinearAlgebra

let vector = SCNVector4(x: 1, y: 2, z: 3, w: 4)
vector *= 4
println(vector)

Future Plans

  • Some kind of support for bases (origin + 3 vectors)
    • Conversion between basis
  • Use specific type aliases
    • Vectors for colors, locations, directions, rotations
  • Rotation utilities
  • Torque and Force utilities
  • Utilize Accelerate or Surge

You should follow me on Twitter.

About

Swift extensions for Linear Algebra with SceneKit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%