3

Basically, I've created the masses, gave them some velocity and momentum, and I'm trying to make them orbit each other (around their center of mass) using the force from gravity.

from visual import *

earth = sphere(radius = 100000000)
newPlanet = sphere(pos = (3.84403*10**8, 0, 0), radius = 10000000)

earth.velocity = vector(0, 100, 0)
newPlanet.velocity = vector(0, 100, 0)

earth.mass = 2*10**30
newPlanet.mass = 1*10**30

earth.p = vector(0, earth.mass*earth.velocity, 0)
newPlanet.p = vector(0, newPlanet.mass*newPlanet.velocity, 0)

dt = 1000
r = newPlanet.pos.x
T = 1.296*10**6
G = 6.673*10**-11

while 1:
    Fnet = G*((earth.mass*newPlanet.mass)/r**2)

    earth.p += Fnet*dt
    newPlanet.p += Fnet*dt

    earth.velocity += (earth.p/earth.mass)*dt
    newPlanet.velocity += (newPlanet.p/newPlanet.mass)*dt

    earth.pos += earth.velocity*dt
    newPlanet.pos += newPlanet.velocity*dt

    t += 1

    rate(100)

This is the error I'm getting:

Traceback (most recent call last):
  File "Untitled", line 12
    earth.p = vector(0, earth.mass*earth.velocity, 0)
Boost.Python.ArgumentError: Python argument types in
    vector.__init__(vector, int, vector, int)
did not match C++ signature:
    __init__(struct _object *, class cvisual::vector)
    __init__(struct _object *)
    __init__(struct _object *, double)
    __init__(struct _object *, double, double)
    __init__(struct _object *, double, double, double)
Cairnarvon
  • 25,981
  • 9
  • 51
  • 65
Bob John
  • 3,688
  • 14
  • 43
  • 57
  • 3
    It might help if you tagged this and/or provided comments in the code telling us where this "visual" module is coming from. Based on the traceback I'd surmise that it's a binary extension/module that's been written in C++. From that I'd just guess that one of it's initializers is being called, perhaps with a large integer from Python and that, possibly. it doesn't have suitable support for arbitrary precision integers? – Jim Dennis Feb 19 '12 at 03:15
  • 1
    @BobJohn: He means, what is `visual`??? It's not a python builtin. Also, it's possible you've got the argument order mixed up in `vector`. – Joel Cornett Feb 19 '12 at 03:30
  • @JimDennis @JoelCornett `visual` is presumably referring to the library Vpython http://vpython.org/, popular for teaching computational physics. – Hooked Feb 19 '12 at 04:45

1 Answers1

5

vector takes three numbers as arguments as shown by vpython documentation here

In your assignment earth.p = vector(0, earth.mass*earth.velocity, 0), earth.mass*earth.velocity is a vector as typeof(earth.mass*earth.velocity) will indicate and not a number as expected.

Hence the error message, are you sure you didn't mean

earth.p = vector(0, earth.mass*mag(earth.velocity), 0)

or earth.p = vector(0, earth.mass*earth.velocity.y, 0) instead.

Appleman1234
  • 15,946
  • 45
  • 67