opengl – GLM conversion of euler angles to quaternion and back does not hold

I am trying to convert the orientation of an OpenVR controller that I have stored as glm::vec3 Euler angles in a glm::fquat and back, but I get extremely different results and the behavior in the game is just wrong (difficult to explain, but the orientation of the object behaves normally for a small range of angles, then switches in strange axes).

Here is my conversion code:

// get `orientation` from OpenVR controller sensor data

const glm::vec3 eulerAnglesInDegrees{orientation(PITCH), orientation(YAW), orientation(ROLL)};

const glm::fquat quaternion{glm::radians(eulerAnglesInDegrees)};
const glm::vec3 result{glm::degrees(glm::eulerAngles(quaternion))};

// `result` should represent the same orientation as `eulerAnglesInDegrees`

I would expect eulerAnglesInDegrees and result be either the same representations, or equivalent representations of the same orientation, but this is apparently not the case. Here are some examples of values ​​I get printed:

39.3851 5.17816 3.29104 
39.3851 5.17816 3.29104 

32.7636 144.849 44.3845 
-147.236 35.1512 -135.616 

39.3851 5.17816 3.29104 
39.3851 5.17816 3.29104 

32.0103 137.415 45.1592 
-147.99 42.5846 -134.841 

As you can see above, for some orientation ranges, the conversion is correct, but for others it is completely different.

What am i doing wrong?

I looked at the existing questions and tried a few things, including trying all of the possible rotation orders listed here, conjugating the quaternion and other random things like reversing the pitch / yaw / roll. Nothing has given me the expected result.

How can I convert euler angles to quaternions and back, representing the original orientation, using glm?

Some other examples of discrepancies:

original:      4; 175;   26; 
computed:   -175;   4; -153; 
difference:  179; 171;  179; 

original:     -6; 173;   32; 
computed:    173;   6; -147; 
difference: -179; 167;  179; 

original:      9; 268;  -46; 
computed:   -170; -88;  133; 
difference:  179; 356; -179; 

original:    -27; -73;  266; 
computed:    -27; -73;  -93; 
difference:    0;   0;  359; 

original:    -33; 111;  205; 
computed:    146;  68;   25; 
difference: -179;  43;  180; 

I tried to find a pattern to fix the finale computed results, but there does not seem to be an easy one to identify.

GIF + behavior video:

Video clip

Visual representation of my current intuition / understanding:

Visual diagram

  • The image above shows a sphere, and I'm in the center. When I point the gun towards the green half of the sphere, the orientation is correct. When I aim the gun at the red half of the sphere, it's incorrect – it seems like every axis is reversed, but I'm not 100% sure that it is.

Math – Find a quaternion of rotation from an orthonormal basis?

Given three unitary 3D vectors $ a $, $ b $, $ c $ such as:

$ a times b = c $

$ b times c = a $

$ c times a = b $

(that is to say $ a, b, c $ for men orthonormal basis)

How do you calculate a unit quartile $ q $ so that the product of the sand width (i.e. rotation) of $ q $ the (1,0,0) is $ a $, (0,1,0) is $ b $ and (0,0,1) is $ c $ ?

quaternion – Smoothing from Slerp to Slerp

p0 ------- p1 ------- p2

I am trying to successfully slip between 2 points (p0-p1; p1-p2). But the transition between two slerped angles (p1_in-p1_out) doesn't match, and that sounds shocking

Video of his appearance:

the green squares are points, the position and the angle between each are interpolated.

The problem is most visible at the second 6.00

I have tried hermitite splines, although this reduces the effect, it is still visible.

I tried to convert Catmull-Rom to use it with quaternions by simply adding the 4th index to the vector functions. This works perfectly, except on certain occasions, where some are interpolated from the wrong (long) "path", which switches the view between these points. I tried to line up, didn't help.

The other SO questions related to slerp do not ask this question, and I could not get usable answers from some questions on 4-point slerps.

Is this a common problem, do I supervise something?

Thank you

What is the convex shell of the quaternion symmetries of the three-dimensional cube?

It is well known that there are exactly five regular three-dimensional convex polyhedra, called Platonic solids.
In 1852 the Swiss mathematician Ludwig Schlafli discovered that there were exactly six regular 4 convex polytopes (the generalization of
4-dimensional polyhedra) and that, for dimensions 5 and above, there are only three!

The six 4 regular polytopes are:

NAME                    VERTEXES   EDGES   FACES  CELLS
Hypertetrahedron              5      10      10      5
Hypercube                    16      32      24      8
Hyperoctahedron               8      24      32     16
24-cell                      24      96      96     24
Hyperdodecahedron           600    1200     720    120
Hypericosahedron            120     720    1200    600

The simplest to describe are the first two:
a model for the hypertetrahedron can be obtained as the convex shell of the canonical base in $ mathbb R ^ 5 $ (hence a
4-dimensional object), while a model for the hypercube is the Cartesian product $ (0, 1) times (0, 1) times (0, 1) times (0,
1) $

As in the case of 3 dimensions, the dual of a regular 4-polytope is also a regular 4-polytope and it turns out that the regular six
The 4-polytopes found by Schlafli are linked to each other via duality as follows.

Hypetetrahedron    <->   Itself
24-cell            <->   Itself
Hypercube          <->   Hyperoctahedron
Hyperdodecahedron  <->   Hypericosahedron

This means that it is enough to describe the 24 cells and the hypericosahedron to be all known. In other words:

Hypertetrahedron    =  convex hull of the canonical basis in 5 dimensions
Hypercube           =  (0,1)x(0,1)x(0,1)x(0,1)
Hyperoctahedron     =  dual of the hypercube
Hyperdodecahedron   =  dual of the hypericosahedron
24-cell                ???
Hypericosahedron       ???

The description of the last two 4-polytopes above can be obtained by considering the quaternions $ mathbb Q $.
visualization $ mathbb R ^ 3 $ in $ mathbb Q $ via the card
$$ (x, y, z) mapsto xi + yj + zk, $$
it is well known that each quaternion
$ q $, with $ Green q Green = 1 $, give a rotation $ R_q $ sure $ mathbb R ^ 3 $ via the formula
R_q (v) = qvq ^ {- 1}, quad forall v in mathbb R ^ 3.

In fact the correspondence $ q mapsto R_q $ is a double coating of $ N / A (3) $ by the unitary sphere $ mathbb Q $.

leasing $ P_ {20} $ be the icosahedron $ mathbb R ^ 3 $, Take into account quaternionic symmetries of $ P_ {20} $, which I will write as
$ mathbb {QS} (P_ {20}) $, defined as the
set of all unitary quaternions $ q $ such as $ R_q $ leaves $ P_ {20} $
invariant. In symbols
mathbb {QS} (P_ {20}) = {q in mathbb Q: Vert q Vert = 1, R_q (P_ {20}) = P_ {20} }.

Well, the convex shell of $ mathbb {QS} (P_ {20}) $ in $ mathbb R ^ 4 $ proves to be a model for the hypericosahedron!

Since the symmetries of a regular polyhedron are the same as the symmetries of its dual, it is clear that the symmetries
of $ P_ {12} $, the dodecahedron, is nothing new: the convex shell of $ mathbb {QS} (P_ {12}) $ is just another model for the

Go to the tetrahedron (double auto), call it $ P_4 $, the convex shell of $ mathbb {QS} (P_ {4}) $ give a model for the
4 remaining polytopes, namely the 24 cells, completing the description of the six 4 Schlafli polytopes.

Question: What is the convex shell of the quaternion symmetries of the 3-dimensional cube?

If I am not mistaken, this polytope 4 has 48 vertices and 144 edges, so it is not in Schlafli's list and therefore cannot be regular.

quaternion – Calculate the orientation of GameObject in the custom coordinate system in Unity

I'm trying to build a custom coodinate system. To be more precise, the user chooses three points on the screen to define the coordinate system. The first is the origin, the second is used to build the OX axis, the third OZ and the last OY. The system is properly constructed. The axes are perpendicular to each other.

Once this coordinate system is built, I need to convert the orientation and position of objects placed on the screen from world space to this particular world space. To do this, I tried the solution proposed from here 1. It seems to work, but only for the post. The orientation seems not to change at all.

For example, if I place a cube at (0, 0, 0) without rotating it in world space, in my own coordinate system, it must also be at (0, 0, 0) and it does not should not be rotated relative to my own coordinate system. So the cube in my coordinate system should have a rotation relative to the world space. However, in reality, my code places the cube at my own origin, but does not rotate it accordingly.

In the image below, the first coordinate system (the smallest) is my own system. The other is of world origin. We can see that the WorldObject cube is placed at (0, 0, 0) with rotation (0, 0, 0). The OwnObject should be the representation of WorldObject in my system. We can see that the position has changed, but not the rotation.

My question is how can I rotate the second cube accordingly? I tried to define the rotation of the cube to be the orientation of the structure proposed in this solution 1, but it did not seem to rotate correctly. I also tried to use Quaternion.LookRotation, but it didn't work either.

enter description of image here
1 How to create a custom set of coordinates based on two points in Unity?

Unity – Rotate an object on itself, from one random Quaternion to another

I have a situation:
I have a 3D object in the world. say a sphere.
I have 2 random directional vectors: vector A and vector B:
enter the description of the image here

My question is: how to rotate in time my object, from A to B?
Vector A is important: I do not just want to turn the front of the object forward towards B.

I know I can use the vector3 function C = Vector3.SmoothDamp (…) in the unit for lerp between my 2 vectors A & B.

but then ok, I have vector3 C, how to apply the rotation of my object to C?
if you do not want to do:
gameObject.transform.forward = C;

I want something like:
gameObject.transform.rotation = SomeQuaternion (C, initial rotation A).
or something.

Thanks for the help!

PS: I do not want to be parent / non parent gameObject or something like that, I want the math answer, using Quaternion.

Aggressive Geometry – Reference Request: Shimura Curve and Quaternion Algebra

Let $ F $ to be a totally real field, and $ D $ to be a quaternion algebra on $ F $ which is divided to exactly an infinite prime number of $ F $, then we have the associated quaternionic Shimura curve $ Sh $ more than $ F $ which is of abelian type and not of PEL type in general if $ F not = mathbb Q $. People usually introduce / define the Shimura Curve in this way.

Is it true that $ 1 $Does Shimura variety have the form above? In particular, everything $ 1 $Shimura variety is abelian type? I can not find a good reference for the proof.

quaternion – Generates a random vector relative to the current vector to some extent in the 3D space

I'm creating a simple ray tracer and I think that would be the best place to ask. I created my own engine in Go and I went quite far. I'm setting up diffuse surfaces, so I'll have to generate a random direction to send scattered rays to fake dummies.

I've looked at the other issues here, and found that it was similar to my question, but it was for 2D space, not 3D.

Let's say I have a direction a, and I want to generate a new direction that is random, and within 45 degrees of direction a. As I work in 3D space, I can not just find the perpendicular angle and the lerp between them, so I will have to do something else. For example, here's what I would do in 2D:

dir = Vector2(1, 1).Normal()

perpDir = dir.Perp() // gets the perpendicular direction of `dir`

randDir = dir.Lerp(perpDir, rand() - 0.5) // rand is (0, 1)

I do not know mathematics very well, so it has to be simple enough for me to understand. Is there a simple way to find a random direction based on a current direction with a maximum rotation of a defined maximum rotation such as 90 degrees?

Adding vectors and applying the rotation matrix to quaternion help

I have a problem and I am looking for help, see the attached picture. I have a number of points (x, y, z) that are treated as connected vectors (first point as first vector base, second point as first vector end AND second vector base) etc.) and I need to know the minimum and maximum coordinates. points of the whole connected structure. I only know that the rotation matrix using quaternion should be applied to the process, but I do not have that experience. Any idea or link to a similar example would be appreciated.

   auto rx =; auto ry =; auto rz =;

// set up dimensions of coordinates

auto ncoords = number_of_vectors();

for (int32_t i = 0; i < ncoords; i++)
    float fact = 1.0f / std::sqrt(rx(i) * rx(i) + ry(i) * ry(i) + rz(i) * rz(i));

    rx(i) *= fact; ry(i) *= fact; rz(i) = fact;

    // rotation matrix ??




quaternion – Storing transformations in game objects. (GLM, C ++)

I am writing a game engine from scratch for learning purposes. I have just begun to implement transformations. I know how they work in general but I'm not sure how to implement them effectively in a hierarchical structure.

Should I keep each transformation separately or group them together in a transformation matrix? I have the impression that a single matrix would be much more efficient than calculating the model transformation matrix each image for each object in the component tree. On the other hand, I would like to access position, rotation and scale individually, as I plan to use them later for other optimizations.

I am aware of glm::decompose but I'm not sure it's a good idea to call each picture.

Should I keep the matrix and components, decompose it to each image or calculate it for each image?