2017-11-22 5 views
0

私の目的はイメージ1を現在の位置から180度までリングに沿って移動させることです。私は別のことをしようとしていますが、何も動かないようです。私の最後の目的は、両方の画像をリングに沿って異なる方向に移動させ、最後にそれらをマージして消滅させることです。上記のエラーが続きます。お手伝いできますか?また、私はこの問題についてどうすればいいのか教えていただけますか?ValueError:オペランドをシェイプ(3、)(0、)と一緒にブロードキャストできませんでした。

from visual import * 
import numpy as np 
x = 3 
y = 0 
z = 0 
i = pi/3 
c = 0.120239 # A.U/minute 
r = 1 
for theta in arange(0, 2*pi, 0.1):  #range of theta values; 0 to  
    xunit = r * sin(theta)*cos(i) +x 
    yunit = r * sin(theta)*sin(i) +y 
    zunit = r*cos(theta) +z 

ring = curve(color = color.white)  #creates a curve 
for theta in arange(0, 2*pi, 0.01): 

    ring.append(pos=(sin(theta)*cos(i) +x,sin(theta)*sin(i) +y,cos(theta) +z)) 

    image1=sphere(pos=(2.5,-0.866,0),radius=0.02, color=color.yellow)  
    image2=sphere(pos=(2.5,-0.866,0),radius=0.02, color=color.yellow) 
    earth=sphere(pos=(-3,0,-0.4),color=color.yellow, radius =0.3,material=materials.earth) #creates the observer 
    d_c_p = pow((x-xunit)**2 + (y-yunit)**2 + (z-zunit)**2,0.5) #calculates the distance between the center and points on ring 
    d_n_p = abs(yunit + 0.4998112152755791) #calculates the distance to the nearest point 
    t1 = (d_c_p+d_n_p)/c 
    t0=d_c_p/c 
    t=t1-t0         #calculates the time it takes from one point to another 

    theta = [] 
    t = [] 
    dtheta = np.diff(theta)     #calculates the difference in theta 

    dt = np.diff(t)       #calculates the difference in t 
speed = r*dtheta/dt      #hence this calculates the speed 

deltat = 0.005       
t2=0          
while True: 
    rate(5) 

    image2.pos = image2.pos + speed*deltat #increments the position of the image1 
    t2 = t2 + deltat 

答えて

0

あなたの問題は、(それがエラーメッセージに「0」です)image2.posがベクトルである(つまり、エラーメッセージに「3」です)が、速度*デルタTがスカラーであるということです。ベクトルとスカラーを追加することはできません。スカラー "スピード"の代わりにベクトル速度が必要です。投稿したプログラムのインデントにエラーがあるようですので、あなたがしようとしていることを誤解している可能性があります。

https://groups.google.com/forum/?fromgroups&hl=en#!forum/vpython-users

VPythonの質問については、それはあなたがStackOverflowのために投稿した場合よりもあなたの質問を見ることができますより多くのVPythonのユーザーが存在するVPythonフォーラムに投稿する方が良いでしょう

関連する問題