VPython中的显示框,了解横摇和偏航
我正试图想象VPython的一个盒子 问题是:我知道是横摇和横摆,但Vpython的属性是“轴”和“向上”。 我怎样才能把我的角度转换成这两个需要的向量呢 下面是显示3个轴和一个框的简短代码。 功能设置方向应更改提供横滚、俯仰和偏航的框属性“向上”和“轴”VPython中的显示框,了解横摇和偏航,python,math,euler-angles,vpython,Python,Math,Euler Angles,Vpython,我正试图想象VPython的一个盒子 问题是:我知道是横摇和横摆,但Vpython的属性是“轴”和“向上”。 我怎样才能把我的角度转换成这两个需要的向量呢 下面是显示3个轴和一个框的简短代码。 功能设置方向应更改提供横滚、俯仰和偏航的框属性“向上”和“轴” import vis def setOrientation(element, roll, pitch, yaw): element.axis = ??? element.up = ??? vis.display(
import vis
def setOrientation(element, roll, pitch, yaw):
element.axis = ???
element.up = ???
vis.display(
title='Board orientation',
x=0, y=200,
width=600, height=600,
center=(0, 0, 0),
forward=(1, 0.4, 1),
up = (0,0,-1),
lights =[
vis.distant_light(direction=(0.22, 0.44, -0.88), color=vis.color.gray(0.8)),
vis.distant_light(direction=(-0.88, -0.22, 0.44), color=vis.color.gray(0.3))],
range = 5
)
# Draw all axes
startingpoint = vis.sphere(pos=vis.vector(0, 0, 0), radius=0.2, color=vis.color.yellow)
vis.arrow(pos=startingpoint.pos, axis=vis.vector(3, 0, 0), shaftwidth=0.1, color=vis.color.red)
vis.arrow(pos=startingpoint.pos, axis=vis.vector(0, 3, 0), shaftwidth=0.1, color=vis.color.green)
vis.arrow(pos=startingpoint.pos, axis=vis.vector(0, 0, 3), shaftwidth=0.1, color=vis.color.blue)
#Make a box
mybox = vis.box(pos=(0,0,0), length=6, height=2, width=0.1, color=vis.color.red)
#Orient it by proviging roll, pitch and yaw
setOrientation(mybox, 0, 0, 0)
轴和方向应与
X点前进
Y-指向右边
Z点向下
滚动-正方向为顺时针
正俯仰向上
偏航-正向为顺时针方向
我找到的最接近的东西是迈克·斯莫托
axis=(cos(pitch)*cos(yaw),-cos(pitch)*sin(yaw),sin(pitch))
up=(sin(roll)*sin(yaw)+cos(roll)*sin(pitch)*cos(yaw),sin(roll)*cos(yaw)-cos(roll)*sin(pitch)*sin(yaw),-cos(roll)*cos(pitch))
此解决方案的问题是,它的轴与我的问题不匹配,我无法修改它以满足我的需要。您正在执行从身体四等分系统到全局坐标系统的旋转。你可以用一个 您可以使用此选项从侧滚俯仰和偏航创建四元数
def QuaternionFromEuler(Roll, Pitch, Yaw):
cRoll = math.cos(Roll/2)
cPitch = math.cos(Pitch/2)
cYaw = math.cos(Yaw/2)
sRoll = math.sin(Roll/2)
sPitch = math.sin(Pitch/2)
sYaw = math.sin(Yaw/2)
Quaternion = numpy.empty(4)
Quaternion[0] = cRoll*cPitch*cYaw + sYaw*sPitch*sYaw
Quaternion[1] = sRoll*cPitch*cYaw - cRoll*sPitch*sYaw
Quaternion[2] = cRoll*sPitch*cYaw + cYaw*cPitch*sYaw
Quaternion[3] = cRoll*cPitch*sYaw - sRoll*sPitch*cYaw
return Quaternion
好的-但是这如何帮助我计算两个需要的向量“轴”和“向上”?我知道旋转(我有横摇和横摆),但我无法用VPython正确显示它。