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.
Tests are complete for all implemented features.
- 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]
- 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)
)
The documentation for using a custom Swift library is lacking at the moment, but my process has been as follows:
- Clone
[email protected]:apexskier/SKLinearAlgebra.git
into your project directory. - Drag
SKLinearAlgebra.xcodeproj
into your Xcode project. - Select your project, select your target, under General find "Linked Frameworks and Libraries".
- Add
SKLinearAlgebra.framework
, either from the + button or by dragging inSKLinearAlgebra/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)
- 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.