Skip to content

Conversation

TrifanBogdan24
Copy link

@TrifanBogdan24 TrifanBogdan24 commented Mar 23, 2025

Solved issue: #1446.

I implemented the algorithm behind calculus of Euler Angles as a nalgebra crate.

I also provided a brief README of how to use these simple, yet powerful functions.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be included?

Comment on lines +151 to +181
pub fn rotation_matrix_to_euler(rotation_matrix: &Vec<Vec<f64>>, order: &[char; 3]) -> Result<Vec<f64>, String> {
// Validate the order
for chr in order {
if !matches!(*chr, 'X' | 'Y' | 'Z') {
let err_msg = format!("Invalid order character '{}'. Expected X/Y/Z", chr);
return Err(err_msg);
}
}

let beta = -rotation_matrix[2][0].asin(); // Y-axis rotation (beta)
let alpha = (rotation_matrix[2][1] / beta.cos()).atan2(rotation_matrix[2][2] / beta.cos()); // X-axis rotation (alpha)
let gamma = (rotation_matrix[1][0] / beta.cos()).atan2(rotation_matrix[0][0] / beta.cos()); // Z-axis rotation (gamma)

// Create a map to associate axes with their corresponding Euler angle functions
let mut euler_map: HashMap<char, f64> = HashMap::new();

euler_map.insert('X', alpha);
euler_map.insert('Y', beta);
euler_map.insert('Z', gamma);

let mut euler_angles = Vec::new();

for &axis in order {
match euler_map.get(&axis) {
Some(&angle) => euler_angles.push(angle),
None => return Err(format!("Unexpected axis '{}'", axis)),
}
}

Ok(euler_angles)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the using the extrinsic or extrinsic definition? And how to discern between those?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants