Quaternion
Simple Quaternion test.
- Boards:
- AVR, AVR USB, Nano Every, Nano 33 IoT, Nano 33 BLE, UNO R4, Pi Pico, Due, Teensy 3.x, ESP8266, ESP32
Written by PieterP, 2020-03-24
https://github.com/tttapa/Arduino-Helpers
bool close(float actual, float expected, float atol) {
return std::abs(actual - expected) <= atol;
}
void setup() {
Serial.begin(115200);
Vec3f vector {-0.414578098794425, 0.829156197588850, 0.375000000000000};
Quaternion expected {0.829156197588850, -0.5, -0.25, 0.0};
float atol = 1e-7;
Serial << close(result.
w, expected.w, atol) <<
endl;
Serial << close(result.
x, expected.x, atol) <<
endl;
Serial << close(result.
y, expected.y, atol) <<
endl;
Serial << close(result.
z, expected.z, atol) <<
endl;
Serial << close(diff.
norm(), 0, atol) <<
endl;
}
void loop() {}
Dummy header file for Arduino builder.
Definition of Quaternion and EulerAngles.
Print & endl(Print &printer)
Print & boolalpha(Print &printer)
Setprecision setprecision(int n)
Type for quaternions of floating point numbers.
static Quaternion fromDirection(Vec3f v)
Calculate the quaternion that satisfies the following: result.rotate(Vec3f{0, 0, 1}) == v....
float w
Scalar (real) component.
float y
Second vector (imaginary) component .
Vec3f rotate(Vec3f v) const
Rotate vector by this quaternion.
float x
First vector (imaginary) component .
float z
Third vector (imaginary) component .
Type for 3D vectors of floating point numbers.
Vec3f normalized() const
Normalize a copy of this vector (doesn't change the original vector).