Possible to Grab Math from VPython Objects Without Loading Models

77 views
Skip to first unread message

Galen Thomas-Ramos

unread,
Oct 10, 2013, 6:25:06 PM10/10/13
to vpytho...@googlegroups.com
So I am developing a large scale data visualization within this enivornment: http://www.youtube.com/watch?v=d5XDbzy7vuE

The software that we are programming in is based off a CAVE specific implementation of OpenSceneGraph called OmegaLib. This framework ported to Python is pretty fussy about what types of modules it will allow to be imported into apps that we develop, so I am hesitant to spend time in VPython if it turns out that there are issues in importing the library. OmegaLib uses its own class of polygon objects rendered in OpenGL, so I am not sure if using VPython's polygons will work within OmegaLib (pretty sure it won't).

What I would like to do is write code using VPython that will only grab the math from the polygonal objects without having to draw them in the scene... Or if it's possible within VPython, I can pass values into functions within VPython and get some simulated values which I can then pass back to the OmegaLib polygons and have those move around the scene.

Some background: this project revolves around plotting exoplanets in a stereoscopic space while also displaying small multiples of different systems, allowing users to compare systems to one another. I would like to use VPython as I have seen several orbital physical simulations in VPython and thought that this would be a great approach (or at least very funny) to trying to visualize binary, trinary start systems and the interactions of the stars with the planets that orbit either the individual star, or the set of stars as a whole.

If this doesn't make sense to this community, and there exists a better, strictly math based physics library to use to achieve orbital physics, please let me know.  Thanks!

Bruce Sherwood

unread,
Oct 10, 2013, 7:22:43 PM10/10/13
to vpytho...@googlegroups.com
It's only a guess, but it doesn't seem to me that VPython has anything to offer you. You already have extremely high-end, sophisticated 3D graphics, beyond what VPython provides. The "math" part of VPython is simply that it has a 3D vector class that facilitates physics calculations, but there is no physics built-in; it's not a physics engine, nor does it contain a physics engine. 

Just to prove that there's no magic in the demos you may have seen, here's the binary star program orbit.py from the standard VPython example programs that are installed with VPython. The program creates two spheres to represent the two stars and then enters an infinite loop that continually calculates the gravitational force that each star exerts on the other, uses that force to update the momenta of the stars, and uses the new momentum to get an approximation to the average velocity in order to update the positions. The rate(200) statement makes sure that no more than 200 iterations are performed per second, and drives OpenGL rendering about 30 times per second. (I'll mention for completeness that VPython does support various stereo modes, activated by inserting a single statement.)

from visual import *

G = 6.7e-11

giant = sphere(pos=(-1e11,0,0), radius=2e10, color=color.red,
               make_trail=True, interval=10)
giant.mass = 2e30
giant.p = vector(0, 0, -1e4) * giant.mass

dwarf = sphere(pos=(1.5e11,0,0), radius=1e10, color=color.yellow,
               make_trail=True, interval=10)
dwarf.mass = 1e30
dwarf.p = -giant.p

dt = 1e5

while True:
  rate(200)

  dist = dwarf.pos - giant.pos
  force = G * giant.mass * dwarf.mass * dist / mag(dist)**3
  giant.p = giant.p + force*dt
  dwarf.p = dwarf.p - force*dt

  for star in [giant, dwarf]:
    star.pos = star.pos + star.p/star.mass * dt

Reply all
Reply to author
Forward
0 new messages