2

VPython でボックスを視覚化しようとしています 問題は、ロール ピッチとヨーであることはわかっていますが、Vpython のボックス には「軸」と「上」の属性があります。角度をこれら 2 つの必要なベクトルに変換するにはどうすればよいですか?

以下は、3 つの軸と 1 つのボックスを示す短いコードです。関数 setOrientation は、ロール、ピッチ、およびヨーを提供するボックス属性「up」および「axis」を変更する必要があります。

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 - 下向き

ロール - 正の方向は時計回り

ピッチ - ポジティブが上

ヨー - 正は時計回り

私が見つけた最も近いものは、Mike Smorto のコードです

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

このソリューションの問題は、軸が私の問題と一致せず、ニーズに合わせて変更できないことです。

4

1 に答える 1

0

あなたは体の四分位システムからグローバルな座標系への回転を行っています. クォータニオンを使用できます。

これで、ロール ピッチとヨーからクォータニオンを作成できます。

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
于 2014-08-03T19:38:44.603 に答える