I am trying to plot a rotated cylinder whose Z-axis is rotated by pi/4 radians. I am building-up on top of the code given here. The way I try to draw the rotated cylinder is as following, at first I generate mesh grid points on the surface of a non-rotated cylinder. Then I premultiply those set of points with the rotation matrix to get points of the rotated cylinder. But after plotting this I still get the non-rotated cylinder. I am attaching the code that I have tried below. Any help is appreciated.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
def data_for_cylinder_along_z(center_x, center_y, radius, height_z):
z = np.linspace(0, height_z, 20)
theta = np.linspace(0, 2*np.pi, 20)
theta_grid, z_grid = np.meshgrid(theta, z)
x_grid = radius*np.cos(theta_grid) + center_x
y_grid = radius*np.sin(theta_grid) + center_y
return x_grid, y_grid, z_grid
rot_mat = np.array([[np.cos(np.pi/3), 0, -np.sin(np.pi/3)], [0, 1, 0], [np.sin(np.pi/3), 0, np.cos(np.pi/3)]])
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
Xc, Yc, Zc = data_for_cylinder_along_z(0.0, 0.0, 0.05, 0.1)
# Create points for rotated cylinder
new_Xc = Xc.reshape((1, 20*20))
new_Yc = Yc.reshape((1, 20*20))
new_Zc = Zc.reshape((1, 20*20))
all_new = np.vstack((new_Xc, new_Yc, new_Zc))
all_rot = np.dot(rot_mat, all_new)
# print(all_new)
# print(all_rot)
rot_Xc = all_rot[0, :].reshape(20, 20)
rot_Yc = all_rot[1, :].reshape(20, 20)
rot_Zc = all_rot[2, :].reshape(20, 20)
print(Xc)
print(rot_Xc)
ax.plot_surface(rot_Xc, rot_Yc, rot_Zc, alpha=0.5)
plt.show()