本文主要是介绍qutip+mayavi可视化SO(3)旋转操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
上一篇文章说到python的qutip包可以实现布洛赫球的可视化,并附上了产生动画的代码。
这一篇文章可以对SO(3)旋转操作进行可视化:(需要用到上一篇的new_bloch3d)
import numpy as np
import qutip# SO(3)旋转矩阵总共包含三个参数theta, phi, deltadef rn(state, theta, phi, delta):rn_mat = qutip.Qobj([[np.cos(delta/2) - (0+1j)*np.cos(theta)*np.sin(delta/2),-(0+1j)*np.exp(-(0+1j)*phi)*np.sin(delta/2)*np.sin(theta)],[-(0+1j)*np.exp((0+1j)*phi)*np.sin(delta/2)*np.sin(theta),np.cos(delta/2) + (0+1j)*np.cos(theta)*np.sin(delta/2)]])r_state = (rn_mat*state)*(rn_mat*state).dag()return(r_state)# 设置两个想要绕这个轴旋转的向量
state1 = qutip.Qobj([[-0.6747969 -0.54760216j],[ 0.35928193-0.34014339j]])
state2 = qutip.Qobj([[0.17668045-0.55481338j], [0.59620446-0.5527263j ]])
print(state1, state2)
# state = qutip.Qobj([])
# 设置旋转轴的其中两个参数
theta0 = 0.9
phi0 = np.pi/2+0.5############################################产生每一帧对应的坐标
sx1 = []
sy1 = []
sz1 = []
for delta in range(100):r_rho = rn(state1, theta0, phi0, (delta/100)*2*np.pi)sx1.append((qutip.sigmax()*r_rho).tr())sy1.append((qutip.sigmay()*r_rho).tr())sz1.append((qutip.sigmaz()*r_rho).tr())sx2 = []
sy2 = []
sz2 = []
for delta in range(100):r_rho = rn(state2, theta0, phi0, (delta/100)*2*np.pi)sx2.append((qutip.sigmax()*r_rho).tr())sy2.append((qutip.sigmay()*r_rho).tr())sz2.append((qutip.sigmaz()*r_rho).tr())#下面是画图的函数
#################################################################
import mayavi.mlab as mlab
import matplotlib.colors as colors
import moviepy.editor as mpy
from new_bloch3d import new_Bloch3dduration= 4
fps = 25fig_myv = mlab.figure(1, size=[800, 800],bgcolor=colors.colorConverter.to_rgb('white'),fgcolor=colors.colorConverter.to_rgb('black'))b3d = new_Bloch3d(fig=fig_myv)def make_frame(t):mlab.clf() # clear the figure (to reset the colors)b3d.clear()p1_color = (135.0/255, 206.0/255, 235.0/255)s1_color = p1_colorp2_color = (254.0/255, 129.0/255, 125.0/255)s2_color = p2_colorv_color = (255/255, 130.0/255, 71.0/255)index = round(t*fps)# print(index)b3d.add_points([sx1[:index+1], sy1[:index+1], sz1[:index+1]],p1_color)b3d.add_vectors([sx1[index], sy1[index], sz1[index]], s1_color)b3d.add_vectors([np.sin(theta0)*np.cos(phi0), np.sin(theta0)*np.sin(phi0), np.cos(theta0)],v_color)b3d.add_points([sx2[:index+1], sy2[:index+1], sz2[:index+1]],p2_color)b3d.add_vectors([sx2[index], sy2[index], sz2[index]], s2_color)b3d.add_vectors([np.sin(theta0)*np.cos(phi0), np.sin(theta0)*np.sin(phi0), np.cos(theta0)],v_color)b3d.make_sphere()mlab.title('delta='+format((index/100)*360, '.2f')+'°', figure = fig_myv)#清除画纸上的上一帧,然后产生新的一帧f = mlab.gcf()f.scene._lift()return mlab.screenshot() #antialiased=True# 使用MoviePy把这个图片创建为一个动画,并保存
animation = mpy.VideoClip(make_frame, duration=duration)
animation.write_videofile("bloch_rotation_2.mp4", fps=fps)
可视化效果如下:
一键三连一下呗
可视化波片对光子偏振态的影响_哔哩哔哩_bilibili
这篇关于qutip+mayavi可视化SO(3)旋转操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!