Python Forum
Object moving in a spiral
Thread Rating:
  • 2 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object moving in a spiral
#1
I'm having a hard time figuring out how to get an object (a ball in this case) to move in a spiral.  I figured the best way to go about this would be to use polar coordinates for x and z, but I can't seem to implement it properly.  Any ideas?

from visual import *

myuniv = display(range = vector(25,25,25))

theta = 1
r = 2
s = vector(r*cos(theta),2,r*sin(theta))  
v = vector(theta,0,theta)
a = vector(0,-9.8,0)

dt = 0.1
t = 0.0

ball = sphere(pos = s, radius = 0.25, color = color.cyan)

while s.y > -100.0:
    rate(25)
    theta = theta + 1
    s = s+ v*dt
    v = v + a*dt
    t = t + dt
    ball.pos = s
    ballghost = sphere(pos = s, radius = 0.2)
Am I on the right track here?  I'm very new to python and coding languages in general.

Thanks! Smile
Reply
#2
(Apr-22-2017, 04:45 AM)JakeWitten Wrote:
from visual import *
What is this?  Is it a public package?  The pip "visual" package is unrelated trash, and vpython is the next closest thing I can find, but that doesn't expose a top level visual module.
Please, help us to help you.  How can I run your code, if I don't know what your code depends on?  :)
Reply
#3
Definitely vpython:
http://vpython.org/contents/docs/
Quote:As a convenience to novice programmers to provide everything that is needed to get started, the statement "from visual import *" imports all of the VPython features and executes "from math import *" and "from numpy import *". It also arranges that for routines common to both math and numpy such as sqrt, the much faster math routine is used when possible (when the argument is a scalar rather than an array).
Hate people writing modules this way...
Reply
#4
Is it just not designed for use with python, then?

> pip install vpython
# requirements already satisfied, many times

> python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from visual import *
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'visual'
>>> import vpython
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "D:\Programs\Python\lib\site-packages\vpython\__init__.py", line 10, in <module>
   from .vpython import *
 File "D:\Programs\Python\lib\site-packages\vpython\vpython.py", line 507, in <module>
   get_ipython().kernel.comm_manager.register_target('glow', GlowWidget)
AttributeError: 'NoneType' object has no attribute 'kernel'
>>>
Reply
#5
I've never used it but I believe it is kinda like its own interpreter. You have to install it from their site and then run their environment, or something.
Reply
#6
I was told by my instructor to put it at the beginning of every code.  It imports the necessary module to get a visual display.  I didn't know there was any other way to do it; this is my first few weeks of python...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Moving object in 3d plot jonathan2582 1 3,148 Dec-04-2019, 12:27 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020