无法在vpyhton(glowscript)中添加标量和向量错误 [英] Cannot add scalar and a vector error in vpyhton (glowscript)

查看:131
本文介绍了无法在vpyhton(glowscript)中添加标量和向量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GlowScript中的VPython实现太阳能系统。现在我在运行时收到此错误:错误无法添加标量和向量。我想我做得很好。我是否必须用pos改变一些东西。这是代码:



I'm implementing a solar system with VPython in GlowScript. Now I have received this error when running: Error cannot add scalar and a vector. I think I've done all correctly. Do I have to change something with the pos. ?

Here is the code:

GlowScript 2.7 VPython
from visual import *

scene = display(width = 800, height = 800, center = vec(0,0.5,0))

#sun
sonne = sphere(pos = vec (0,0,0), radius=8, color = color.orange, shininess=1)

#earth
erde = sphere(pos = vec (50,0,0), radius=1.5, color = color.blue, make_trail=True)

erdeV = vector(0,0,5)

#masses
erdeM = 5.97*10**24
sonneM = 1.989*10**30

#Grav-constant
G = 6.67259*10**-11

for i in range (1000):
    rate(1000)
    erde.pos = erde.pos + erdeV
    
    #distance
    entfernung = sqrt(erde.pos.y**2 + erde.pos.z**2)
    
  
    #Gravitational law F = G * m * M / r*r --> G*s*e/AE*AE ae=Astr. Einheit
    Fgrav = G *( erdeM * sonneM) / (entfernung*entfernung)
    erdeV = erdeV + Fgrav
    erde.pos += erdeV
    
    if entfernung <= sonne.radius: break





我尝试过:



我试图改变坐标x,y, pos的z但是没有用。



What I have tried:

I tried to change the coordinates x,y,z of pos but that didn't work.

推荐答案

erdeV = erdeV + Fgrav



Fgrav是一个标量值,而不是矢量...你可以添加两个向量,但只能通过标量划分或乘以向量...


Fgrav is a scalar value and not vector... You can add two vectors but only divide or multiply vector by scalar...


这篇关于无法在vpyhton(glowscript)中添加标量和向量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆