我正在使用jupyter笔记本中的sympy模块对参考框架进行一些计算。我仅绕z轴旋转一个角度av。这个想法如下:
我正在使用以下代码:
from sympy import *
init_printing()
av = symbols('\\alpha_v')
# Reference frames
from sympy.physics.vector import *
# World frame
W = ReferenceFrame('W')
# Vehicle frame
v = ReferenceFrame('v')
v.orient(W,'Axis',[pi-av,W.z])
display('Rotation matrix from W to v:')
display(W.dcm(v)) <-- Check if frames are still coupled
# u frame
u = v
display(W.dcm(v)) <-- Check if frames are still coupled
u.orient(u,'Axis',[pi/2,u.z])
display(W.dcm(v)) <-- Check if frames are still coupled, from here on error!
display('Rotation matrix from w to u:')
display(u.dcm(w))
旋转u之后,v和W框架之间的链接断开。我得到以下输出:
最后的错误是:
ValueError Traceback (most recent call last)
<ipython-input-20-72d62c7921df> in <module>()
17 display(W.dcm(v))
18 u.orient(u,'Axis',[pi/2,u.z])
---> 19 display(W.dcm(v))
20 display('Rotation matrix from w to u:')
21 display(u.dcm(w))
c:\python\python35\lib\site-packages\sympy\physics\vector\frame.py in dcm(self, otherframe)
409 if otherframe in self._dcm_cache:
410 return self._dcm_cache[otherframe]
--> 411 flist = self._dict_list(otherframe, 0)
412 outdcm = eye(3)
413 for i in range(len(flist) - 1):
c:\python\python35\lib\site-packages\sympy\physics\vector\frame.py in _dict_list(self, other, num)
254 return outlist[0]
255 raise ValueError('No Connecting Path found between ' + self.name +
--> 256 ' and ' + other.name)
257
258 def _w_diff_dcm(self, otherframe):
ValueError: No Connecting Path found between W and v
因此,通过旋转u可以断开W和v之间的连接吗?我不明白我在做什么错。
服务器信息: 您正在使用Jupyter笔记本。
笔记本服务器的版本为:5.6.0 服务器正在此版本的Python上运行: Python 3.5.4(v3.5.4:3f56838,2017年8月8日,02:17:05)[MSC v.1900 64位(AMD64)]
编辑:该问题可以通过以下方法解决:
from sympy import *
init_printing()
av = symbols('\\alpha_v')
# Reference frames
from sympy.physics.vector import *
# World frame
W = ReferenceFrame('W')
display(W)
# Vehicle frame
v = ReferenceFrame('v')
v.orient(W,'Axis',[pi-av,W.z])
display('Rotation matrix from W to v:')
display(W.dcm(v))
display(W.dcm(v))
# u frame
u = ReferenceFrame('u')
u.orient(v,'axis',[pi/2,v.z])
display(u.dcm(v))
display(W.dcm(v))
我认为u = v正在变量u中复制v。这不起作用并导致问题。将u定义为参考框架,然后将其相对于v进行定向是正确的方法。
唯一剩下的问题是,如果要两个相同的参考系,如何制作副本?唯一的办法就是这样吗?
u = ReferenceFrame('u')
u.orient(v,'axis',[0,v.z])