New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Matrix translation / rotation? #1160
Comments
Right now there is only A translate/rotate function sounds interesting, we don't have that in mathjs. I guess we can get inspiration from similar functions in python/matlab/etc. Do you have some concrete use cases for rotating a matrix? |
Typically rotation matrices are used to manipulate points or objects in space or on the plane, for example when doing 3D graphics. The matrix is constructed using trig functions, then multiplied to each vector in the object to be rotated. This allows for rotation of many points at a time. It would be very handy to have a set of functions to create rotation matrices. Or possibly @aneilbaboo means to rotate the elements themselves within a square matrix or something. I'm not familiar with the applications of doing that. |
Thanks, @ericman314 - yes, that is what I meant. |
Ah, of course. Sounds cool! |
I think I could work on this. const vec = [1, 2];
const rotatedVec = math.rotate(vec, math.pi / 4); // [-0.707..., 2.12...] I could also do this for 3D vectors (perhaps even n-dimensional?) |
Could there also be a function that returns a rotation matrix? Then you could do the trig just once and rotate lots of vectors quickly: const vec = [1, 2];
const rotationMat = math.rotationMatrix(math.pi / 4); // [[0.707, -0.707], [0.707, 0.707]]
const rotatedVec = math.multiply(rotationMat, vec); // [-0.707, 2.12] I think 3D rotations are also a must-have, but I don't know about n-dimensional. I can't wrap my head around that! |
Thanks for your offer @YuvalGat, that's great! I like the idea of @ericman314 , so that means we will create two new functions, where I also guess we need support for both 2D and 3D matrices? The function Are there any lessons we can learn for the API from other languages/libraries? |
I think that both
And:
If it became useful, the above syntax could be extended to dimensions greater than 3. But in dimensions greater than 3 I do not believe there is the idea of a rotation axis, instead one speaks of "rotation plane". (Only in 3d is there a natural correspondence between rotation plane and rotation axis.) So in higher dimensions, |
This sounds like a good idea! I'll get working ASAP. |
@josdejong How dead is this issue? Looks like @YuvalGat gave up (?) and the basic |
I think Yuval didn't manage to find time for it. Would be great if you can pick it up @rnd-debug, thanks! |
@josdejong ok, work started. Short question: in case of
What would be preferable? I am tending towards coefficient-wise as more standalone solution. |
Are there any downsides of using coefficient-wise? |
Overhead with typing the coefficients. :D so let's go for coefficient-wise. |
👍 |
Function |
The new function |
What is the right way to translate or rotate a sparse or dense matrix?
The text was updated successfully, but these errors were encountered: