Skip to content

Instantly share code, notes, and snippets.

@ben-xD
Last active November 22, 2022 17:25
Show Gist options
  • Save ben-xD/6553c95efa09ae4d7c68f56f515d2dff to your computer and use it in GitHub Desktop.
Save ben-xD/6553c95efa09ae4d7c68f56f515d2dff to your computer and use it in GitHub Desktop.
#dart #math Rotating by -90 degrees using quaternions
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