Python Forum
rotating and resizing objects - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: rotating and resizing objects (/thread-20064.html)



rotating and resizing objects - jenya56 - Jul-25-2019

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.


RE: rotating and resizing objects - Yoriz - Jul-25-2019

Your post lacks information of how you are representing these objects


RE: rotating and resizing objects - jenya56 - Jul-25-2019

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


RE: rotating and resizing objects - scidam - Jul-26-2019

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()