Accessing position list

27 views
Skip to first unread message

Josh Gates

unread,
Aug 4, 2016, 10:08:21 AM8/4/16
to Glowscript Users
Is there a method to access the stored set of positions in a curve (trail)?

I'm trying to plot via matplotlib, and instead of creating my own variable to accumulate the points, I'd like to access the stored set of points in the trail, if possible. Is there anything else odd about that workflow that I'm not considering? I know that, when there's a long trail, it seems like it doesn't display all of the points in the curve - I assume that's just a display change (modifying the interval), but I'm not positive.

Thanks,
jg

Bruce Sherwood

unread,
Aug 4, 2016, 3:37:39 PM8/4/16
to Glowscript Users
No, there's isn't currently a way to access the points in a trail. I'm not aware of a long trail not showing all points; do you have an example? There was something like this in Classic VPython, but not in GlowScript or Jupyter VPython.

For your purposes it makes sense not to use the trail machinery but to append points to your own curve object (and to a list), so that you have complete control. Be aware that typically you shouldn't add a point every time you update the position of an object, because that could mean you would be adding several hundred points per second, and a curve with a very large number of points displays slowly.

Josh Gates

unread,
Aug 4, 2016, 3:45:06 PM8/4/16
to glowscri...@googlegroups.com
I was assuming that GS had the same behavior as classic VP - thanks for clarifying that. 

What's the method for accessing the points list of a curve object?

Thanks,
jg


On Thu, Aug 4, 2016 at 3:37 PM, Bruce Sherwood <bruce.s...@gmail.com> wrote:
No, there's isn't currently a way to access the points in a trail. I'm not aware of a long trail not showing all points; do you have an example? There was something like this in Classic VPython, but not in GlowScript or Jupyter VPython.

For your purposes it makes sense not to use the trail machinery but to append points to your own curve object (and to a list), so that you have complete control. Be aware that typically you shouldn't add a point every time you update the position of an object, because that could mean you would be adding several hundred points per second, and a curve with a very large number of points displays slowly.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Glowscript Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/glowscript-users/EaVqXolEaxU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to glowscript-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Joshua Gates

Bruce Sherwood

unread,
Aug 4, 2016, 3:54:26 PM8/4/16
to Glowscript Users
See the GlowScript help article on the curve object.

But in your case, if you append your own points to a curve object you could easily append the same point to your own list. There's no need to read from the curve later.

Bruce Sherwood

unread,
Aug 10, 2016, 12:50:59 AM8/10/16
to Glowscript Users
Another scheme is to use make_trail and periodically, when you update pos, append pos to a list of positions. Something like this:

count = 10
while True:
    newpos = .....
    ball.pos = newpos
    if count == 0:
        poslist.append(newpos)
        count = 0
    else:
        count -= 1

Josh Gates

unread,
Aug 11, 2016, 12:31:06 AM8/11/16
to Glowscript Users


That's pretty similar to what I was doing (except that I was keeping the count going and using modular arithmetic to get every 200th point) - works fine!

Thanks,
jg
Reply all
Reply to author
Forward
0 new messages