- Strongly typed radian, degree and hour angle classes and conversions.
- 3x3 matrix, 4x4 matrix and quaternion support.
- Conversion between matrix, quaternion, Euler angle, and axis and rotation.
- Matrix, quaternion multiplication, inversion and scalar multiplication.
- Overloaded multiplication and division operators in contexts of matrix and quaternion.
- Interpolation support for linear, quadratic and cubic curves with ease-in, ease-out, ease-in-out modes.
- Detect whether two line segments cross each other.
- Operator overloading for
SCNVector3
and more.
# Swift 4.0
github "DJBen/MathUtil" ~> 0.3.0
This version is compatible with Swift 4. To use Swift 3.x compatible version, use 0.1.x
instead.
# Swift 3.x
github "DJBen/MathUtil" ~> 0.1.0
RadianAngle(degreeAngle: DegreeAngle(30)).value // 0.523...
DegreeAngle(radianAngle: RadianAngle(Double.Pi / 2)).value // 90
// Sirius' right ascension is 6h 45m 9s
let deg = DegreeAngle(hour: 6, minute: 45, second: 9)
deg.value // 101.2875
let hourAngle = HourAngle(value: deg)
// Use any custom number formatters for different decimal lengths
hourAngle.compoundDecimalNumberFormatter = NumberFormatter()
print(hourAngle.compoundDescription) // 6h 45m 9s
// Antares' right ascension is −26.432002 degrees
let degreeAngle = DegreeAngle(-26.432002)
print(degreeAngle.compoundDescription) // -26° 25′ 55″
See documentation for VectorMath.
// Starts at 2.1; ends at 7.5; wants to know 85% value.
let interp = Easing(startValue: 2.1, endValue: 7.5)
interp.value(at: 0.85) // 6.69
The following easing functions are available and here is their mathematic definitions.
public enum EasingFunction {
case linear
case quadraticEaseIn
case quadraticEaseOut
case quadraticEaseInOut
case cubicEaseIn
case cubicEaseOut
case cubicEaseInOut
}
Just pass in the function when initializing Easing
and take advantage of it!
Easing(easingMethod: .cubicEaseInOut, startValue: 21, endValue: -9)
- Add operator arithmetics for
CGVector
andSCNVector3
.
MathUtil/VectorMath**
are based on
@nicklockwood's VectorMath. Great thanks!
- Based on 0.3 version. Not bumping up to the latest release because I adopted a different order of deriving Euler angles from Quaternion and vice versa.