Python Forum

Full Version: rotating and resizing objects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear all,
I really need help. I have 3d array. Inside that array I have a few objects (ellipsoids) that are represented by the digit 1 (the rest are 0s). I want to rotate these objects by n degrees. And the re-size them. is it possible?
Any suggestions would be appreciated.
Your post lacks information of how you are representing these objects
Hi, my array is 0/1 array. Ellipses are represented by 1s. So it is a bunch of 1s to shape up an ellipse.
Thanks
In 3d-case you'll need to define an axis around which rotation is performed. I think, you need to look
at the rotate helper function from SciPy package . Below, I wrote a minimal example of 2d-ellipse rotation around third (z) axis. Hope that helps.


from scipy.ndimage.interpolation import rotate
import numpy as np

x, y = np.linspace(-5, 5, 100), np.linspace(-5, 5, 100)
X, Y = np.meshgrid(x, y)

# lets make an ellipse (Z); the array will consist of bool values, you can easily convert them to 0/1
Z = np.bitwise_and(((X/2)**2 + (Y/3)**2 - 1) < 0.2, ((X/2)**2 + (Y/3)**2 - 1) > 0.0)

import matplotlib.pyplot as plt

plt.imshow(Z)
rotated_Z =rotate(Z, 45)

plt.imshow(rotated_Z)

plt.show()