forked from kscience/kmath
add some quaternion operations
This commit is contained in:
parent
efb853c1bc
commit
7a4e9e70f9
@ -19,13 +19,19 @@ import org.ejml.sparse.csc.factory.DecompositionFactory_DSCC
|
||||
import org.ejml.sparse.csc.factory.DecompositionFactory_FSCC
|
||||
import org.ejml.sparse.csc.factory.LinearSolverFactory_DSCC
|
||||
import org.ejml.sparse.csc.factory.LinearSolverFactory_FSCC
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.linear.*
|
||||
import space.kscience.kmath.linear.Matrix
|
||||
import space.kscience.kmath.UnstableKMathAPI
|
||||
import space.kscience.kmath.nd.StructureFeature
|
||||
import space.kscience.kmath.operations.Float32Field
|
||||
import space.kscience.kmath.structures.Float64
|
||||
import space.kscience.kmath.structures.Float32
|
||||
import space.kscience.kmath.operations.Float64Field
|
||||
import space.kscience.kmath.operations.Float32Field
|
||||
import space.kscience.kmath.operations.DoubleField
|
||||
import space.kscience.kmath.operations.FloatField
|
||||
import space.kscience.kmath.operations.invoke
|
||||
import space.kscience.kmath.structures.Float64Buffer
|
||||
import space.kscience.kmath.structures.Float32Buffer
|
||||
import space.kscience.kmath.structures.DoubleBuffer
|
||||
import space.kscience.kmath.structures.FloatBuffer
|
||||
import kotlin.reflect.KClass
|
||||
|
@ -28,22 +28,27 @@ public fun Quaternion.power(number: Number): Quaternion = QuaternionAlgebra.powe
|
||||
public fun QuaternionAlgebra.slerp(from: Quaternion, to: Quaternion, fraction: Double): Quaternion =
|
||||
(to / from).pow(fraction) * from
|
||||
|
||||
/**
|
||||
* Scalar angle between two quaternions
|
||||
*/
|
||||
public fun QuaternionAlgebra.angleBetween(q1: Quaternion, q2: Quaternion): Angle = (q1.conjugate * q2).theta
|
||||
|
||||
public val Quaternion.inclination: Radians get() = asin(2 * (w * y - x * z)).radians
|
||||
|
||||
public val Quaternion.azimuth: Angle get() = atan2(2 * (w * z + x * y), 1 - 2 * (y.pow(2) + z.pow(2))).radians.normalized()
|
||||
|
||||
/**
|
||||
* Euclidean product of two quaternions
|
||||
*/
|
||||
public infix fun Quaternion.dot(other: Quaternion): Double = w * other.w + x * other.x + y * other.y + z * other.z
|
||||
|
||||
|
||||
private fun Quaternion.normalizedToEuler(): Float32Vector3D {
|
||||
val roll = atan2(2 * y * w + 2 * x * z, 1 - 2 * y * y - 2 * z * z);
|
||||
val pitch = atan2(2 * x * w - 2 * y * z, 1 - 2 * x * x - 2 * z * z);
|
||||
val yaw = asin(2 * x * y + 2 * z * w);
|
||||
|
||||
return Float32Vector3D(roll, pitch, yaw)
|
||||
}
|
||||
//
|
||||
///**
|
||||
// * Convert a quaternion to XYZ Cardan angles assuming it is normalized.
|
||||
// */
|
||||
//private fun Quaternion.normalizedToEuler(): Float32Vector3D {
|
||||
// val roll = atan2(2 * y * w + 2 * x * z, 1 - 2 * y * y - 2 * z * z)
|
||||
// val pitch = atan2(2 * x * w - 2 * y * z, 1 - 2 * x * x - 2 * z * z)
|
||||
// val yaw = asin(2 * x * y + 2 * z * w)
|
||||
//
|
||||
// return Float32Vector3D(roll, pitch, yaw)
|
||||
//}
|
||||
|
||||
/**
|
||||
* Quaternion to XYZ Cardan angles
|
||||
|
Loading…
Reference in New Issue
Block a user