# Nalgebra rotation3 don't behave as I expected

I don't know if this is the right place to ask this question as nalgebra is rust lib but anyway.
I define vector3 [0f32, 1f32, 0f32] and apply rotation3 on it constructed by the following waht
let rotation = Rotation3::from_euler_angles(std::f32::consts::PI/2f32, 0f32, 0f32) where parameters represent roll, pitch and yaw in this order. Where roll should rotate over Z pitch over X and Yaw over Y In other words my code should rotate the vector over Z with 90 degrees and I should get [1f32, 0f32, 0f32] or [-1f32, 0f32, 0f32] but instead I get [0f32, 0.f32, 1f32] which is the least expected result.
Probably nalgebra use different convention. Probably someone with experience with this lib can cast a little bit of light

I think you want `Rotation3::from_euler_angles`, not `Rotation3::new`.

Sorry for mislead you. I actually use it like that
let rotation = Rotation3::from_euler_angles(roll, pitch, yaw);

It would help to post the code you are using in markdown format, like this:

``````use std::f32::consts::PI;
use nalgebra::base::Vector3;
use nalgebra::geometry::Rotation3;

fn main () {
let mut vec = Vector3::new(0f32, 1f32, 0f32);
// warning: unused variable: 'vec'
// warning: variable does not need to be mutable

let roll = PI/2.0;
let pitch = 0.0;
let yaw = PI/4.0;

let rot = Rotation3::from_euler_angles(roll, pitch, yaw);
let euler = rot.euler_angles();
println!("{:?}", euler);
// (1.5707964, 0.0, 0.7853982)
}
``````

Or post a link to an example on the playground. From this toy example, it looks like from_euler_angles makes a new rotation using the input values, and does not modify your original vector as intended.

with a `yay` value of `PI/2` the result is what you are expect. Is that `PI/4` what you are looking for???

Sorry I didn't put enough effort in that question.
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=79c13e8cf2725d2398dcf1fac61c047c
This is the link to the playground with correct example
You can see that vector that look towards Y direction turn to vector that look at Z direction after apply rotation over Z axis (roll) which should be impossible unless nalgebra use different convection then well established

From this wikipedia image you can see the definition of the rotation in 3d space

and here is nalgebra implementation

``````    /// Creates a new rotation from Euler angles.
///
/// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.
pub fn new_with_euler_angles(roll: N, pitch: N, yaw: N) -> Rotation3<N> {
let (sr, cr) = roll.sin_cos();
let (sp, cp) = pitch.sin_cos();
let (sy, cy) = yaw.sin_cos();

unsafe {
Rotation3::new_with_matrix(
Matrix3::new(
cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr,
sy * cp, sy * sp * sr + cy * cr, sy * sp * cr - cy * sr,
-sp,     cp * sr,                cp * cr
)
)
}
}
}
``````

Which is obviously different from what wikipedia says it should look like

My mistake. I copied wrong numbers from my project. I edited it again. Now It should be correct

Comparing code and formula, looks like `yaw` is α, `pitch` is β, and `roll` is γ, then everything matches AFAICT. This would also match perfectly with the labeling of the three matrix factors.

Yes but why, roll should be the rotation over Z which mean roll should be the alfa

There are different conventions and Wikipedia is no authority.

Yes they are different conventions but when you speak about computer graphics there is one established and it is the one mentioned in wikipedia. Also wikipedia is not authority but when you talk about engineering or math there is very little discrepancy from what you can find in the books.

As addition to that I want to mention that I was unable to find any clue about the convention that nalgebra use and that is the purpose of that question here to find out

1 Like

1 Like

Ok but most of them agree that roll should be rotation over Z also such things should be mentioned in the documentation. Anyway I have plans to ask that question on the forum of nalgebra

This is my project :). Try to learn rust by write some code. My plans to learn multithreding with rust is to write raytracer

1 Like

For another random data point that isn’t helpful but might be interesting to someone, for aircraft, roll is about the x axis (which is the direction from tail to nose), pitch is about the y axis (which is the direction to the side) and yaw is about the z (which is the vertical) This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.