Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

Python
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


What I have tried:

I tried to change the coordinates x,y,z of pos but that didn't work.
Posted
Updated 25-Jun-18 22:05pm
Comments
Richard MacCutchan 25-Jun-18 12:13pm    
You cannot add a vector to a scalar value, the two are totally different types.

1 solution

Python
erdeV = erdeV + Fgrav

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900