Implemented Euler angles a separate crate#1500
Open
TrifanBogdan24 wants to merge 2 commits intodimforge:mainfrom
Open
Implemented Euler angles a separate crate#1500TrifanBogdan24 wants to merge 2 commits intodimforge:mainfrom
TrifanBogdan24 wants to merge 2 commits intodimforge:mainfrom
Conversation
tdamsma
reviewed
Mar 30, 2025
tdamsma
reviewed
Mar 30, 2025
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) | ||
| } |
There was a problem hiding this comment.
Is the using the extrinsic or extrinsic definition? And how to discern between those?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.