Hello there,
I started learning Rust and felt comfortable enough to build something. Being a Robotics Engineer naturally I wanted to build a kinematics/dynamics library. I know that there is already stuff out there, but this serves more as a learning-the-language for me. I want to implement something I am familiar with in a new language.
Now after a few hours I am quite frustrated. I have to say that I am coming from numpy where I can slice and stack matrices like a crazy person and feel quite comfortable. I knew I had to give this up but man I hit so many road blocks, I did not expect this.
Anyways here is my problem:
Disclaimer: I have seen that nalgebra seems to have Transformations already build in. But as I said I want to try to build a lil library myself also to understand how to deal with matrices.
So lets say I want to store a 4x4 transformation matrix with nalgebra.
So I have a struct that is holding a Matrix like this:
pub struct TF {
T: Matrix4<f32>,
}
Now, this thing falls out of a forward kinematics function, and I want to retrieve quaternion and position from it. And I am already struggling with the most easy case (getting the position vector out).
So in my impl
block I have a function that shall just return a 3 dimensional vector. In Numpy
I would just
return self.T[0:3, 3]
However I know this is not Pyton and so I expected to somehow be able to get a Vector3<f32>
out of my Matrix.
My first attempt was this. I also tried fixed_rows
which did not work:
pub fn get_p(&self) -> Vector3<f32> {
self.T.fixed_slice::<U3, U1>(0, 3) as Vector3<f32>
}
Okay this does not work. With or without the explicit type cast, the types donât match. And here I thought a Vector3
is just a VectorN
is just a MatrixNM
, âŚ
Maybe there is a ::from
method I could use on Vector? I am so confused about how to use this library. The Docs looked so fancy but I seem to be too stupid to understand it very well. So, why can I not do something like:
let my_cool_vector = Vector3::from_fixed_slice(my_cool_matrix, slice_stuff)
Anyway any help on how to do slices right, would be very much appreciated. I am using version 0.20.0.
As a bonus: In my frustration, I looked more into the docs and found a transformation struct. Cool! As I said, I wanna build this myself to understand, but maybe I could use this for now to make some progress. But I could not find a function that just returns the position vector. I mean any transformation matrix consists of two things really: a rotation matrix and a position vector. If I write an abstraction, I should be able to get either out of that abstraction somehow. I could not figure out how.
Anyways, sorry for long post. I will be lying down in a fetal position now and contemplate on life until someone responded. Please do not take my frustrations as criticism. As I said, I am new to the language and have mostly worked with C++ and Python recetly.