Last active
November 22, 2022 17:25
-
-
Save ben-xD/6553c95efa09ae4d7c68f56f515d2dff to your computer and use it in GitHub Desktop.
#dart #math Rotating by -90 degrees using quaternions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "dart:math"; | |
import "package:vector_math/vector_math.dart"; | |
class Orientation { | |
// radians | |
final double yaw; | |
final double pitch; | |
final double roll; | |
Orientation({required this.yaw, required this.pitch, required this.roll}); | |
} | |
void main() { | |
final orientation = Orientation(yaw: pi/2, pitch: 0, roll: 0); | |
final orientationQ = Quaternion.euler(orientation.yaw, | |
orientation.pitch, | |
orientation.roll); | |
print(orientationQ); | |
final quaternionCorrection = Quaternion.euler(-pi/2, 0, 0); | |
print(quaternionCorrection); | |
final output = orientationQ * quaternionCorrection; | |
print(output); | |
// TODO Convert back to Euler angles: | |
// to show roll, pitch, yaw | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment