1

I have some numpy/scipy issue. I have a 3D array that represent an ellipsoid in a binary way [ 0 out of the ellipsoid]. The thing is I would like to rotate my shape of a certain degree. Do you think it's possible ? Or is there an efficient way to write directly the ellipsoid equation with the rotation ?

2
  • Have a look at Homegeneous coordinates, it allows you all transformations with one matrix multiplication. en.wikipedia.org/wiki/… Commented Aug 4, 2011 at 10:36
  • Do you know how you will rotate it ... whether in a 2D fashion or 3D ... whether pitch (nose up or down), yaw (nose left or right), roll (sides up or down) or a combination? Commented Aug 4, 2011 at 12:30

3 Answers 3

2

Just a short answer. If you need more informations or you don't know how to do it, then I will edit this post and add a small example.

The right way to rotate your matrix of data points is to do a matrix multiplication. Your rotation matrix would be probably an n*n-matrix and you have to multiply it with every point. If you have your 3d-matrix you have some thing like i*j*k-points for plotting. This means for your case you have to do it i*j*k-times to find the new points. Maybe you should consider an other matrix for plotting which is just a 2D matrix and just store the plotting points and no zero values.

There are some algorithm to calculate faster the results for low valued matrix, but just google for this.

Did you understood me or do you still have some questions? Sorry for this rough overview.

Best regards

Sign up to request clarification or add additional context in comments.

Comments

1

Take a look at the command numpy.shape I used it once to transpose an array, but I don't know if it might fit your needs. Cheers!

4 Comments

I think the OP wants to geometrically rotate the ellipsoid through a certain angle, not transpose the array.
That's it ! I want to rotate geometrically the ellipsoid within the array !
Ah, ok, I see. Misunderstood the question... Sorry!
Maybe some matrix operations could be helpful? en.wikipedia.org/wiki/Rotation_matrix
0

rotating by a non rectangular degree is tricky, because the rotated square does no longer fit in the matrix.

The simplest way would be to transpose a 2D array/matrix by:

import numpy as np
... x = np.array([[1,2,3],[4,5,6],[7,8,9]])
x
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])

x.T      # transpose the array

array([[1, 4, 7],
       [2, 5, 8],
       [3, 6, 9]])

if you require an explicit array rotation check the ndimage package from scipy library:

from scipy import ndimage, datasets
img = datasets.ascent()
img_45 = ndimage.rotate(img, 45, reshape=False)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.