help with implementing orbitting

14 views
Skip to first unread message

slim

unread,
Feb 1, 2011, 3:21:58 PM2/1/11
to General discussion of the Lepton particle engine for Python
Hi all,

First of all, thanks for this library! It is extremely useful! :)

I'm trying to implement an orbitting particle. I will have an initial
particle that becomes the center, and would like all subsequent
particles to orbit around it forming a concentric circle.

I tried to do this using the Magnet controller by updating it's center
each iteration of the update. This works great, but the movement is
simply a linear up and down the y axis. I'm wondering what is the
simplest way to get them to move in a circular motion around the x and
y would be. Or maybe there is no simple way, and I need to whip out my
physics book?

Thanks for all your help!

slim

Casey Duncan

unread,
Feb 1, 2011, 8:03:39 PM2/1/11
to py-lept...@googlegroups.com
Hi Slim,

It sounds like you want exacting control over the position/motion of
the particles. The magnet controller and the like are really best for
more organic type effects that are not entirely deterministic. You
could get the magnet controller to do something like what you want,
but it will require a lot of tweaking. Regardless, I'll describe how
you might do it with a magnet.

If you want one particle to orbit another, then you will want the
magnet to be at the same position as the particle at the center
(assuming they are not mutually orbiting each other). The magnet will
not move unless you want the center particle to move, but in that case
you will not have a circular orbit, more like a helical one.

The orbiting particles will need to start at the desired distance from
the center. They will need to have a velocity perpendicular to the
line between that particle and the center. This is where the tweaking
comes in. In order to get a perfect orbit, the velocity must match the
magnet's charge, or else the particle will either spiral in or out
from the center. You can cheat a bit here by playing with the
exponent, epsilon, and outer_cutoff magnet values.

This may be fun to play with, but is unlikely to be your best use of
time 8^) Even with exactly balanced math, rounding errors will
accumulate over time causing the particle to deviate from a perfect
orbit, and spiral in or away from the center. This is fixable in other
ways, but it involves several magnets in opposition, and is even more
tweaky in practice (things tend to explode ;^)

I think in this case I would suggest implementing a custom controller.
This controller would just alter the direction of the velocity vector
over time such that it goes around like the hand on a clock. You might
do this by storing the magnitude of the velocity in the "up" vector's
y component or something. The velocity could then be calculated by
your controller based on some simple trig based on particle.age and
the length of particle.up.y. Making a controller like this would
involve very little code. There is an example very close to what you
would want here:

http://code.google.com/p/py-lepton/wiki/ParticleController

The custom controller would only be applied to orbiting particles, not
their centers. Determining where the center would be for each orbit
might take a little figuring, or you could figure it out by trial and
error.

The biggest downside to doing it this way is that it would not scale
up as well as the built-in controllers written in C. But I would
suggest getting a good solution first, then worrying about how it
performs later.

-Casey

slim

unread,
Feb 7, 2011, 1:23:59 AM2/7/11
to General discussion of the Lepton particle engine for Python
Thanks Casey

I was able to do something close enough to what I need using the
Magnet.

Is py-lepton being worked on still?

I saw the roadmap, and was quite intrigued by the potential features
to be added on.

For one I would love to be able to write code that goes from scattered
particles that
assembles into a tri-mesh... Or be able to use a voxel instead of a
pixel as a particle.
Or maybe these are already possible?

thanks again

slim

Casey Duncan

unread,
Feb 9, 2011, 1:13:22 PM2/9/11
to py-lept...@googlegroups.com
Hi Slim,

Glad to hear that you got it to work. If you are willing to share your
program, I'd be interested to see it 8^)

I am not actively working on Lepton anymore, but it is very
extensible, and I would be willing to help you if you wanted to add
new features. All of the core C parts have a full Python API, so it is
possible, and beneficial to prototype new features purely in Python.
Then they can be ported to C for maximum performance. I can help
answer questions about the core API, and help port things to C as
well.

If you could describe what you are looking for in some more detail, I
could figure out how complicated it would be to implement, and lend
some general ideas.

-Casey

> --
> You received this message because you are subscribed to the Google Groups "General discussion of the Lepton particle engine for Python" group.
> To post to this group, send email to py-lept...@googlegroups.com.
> To unsubscribe from this group, send email to py-lepton-use...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/py-lepton-users?hl=en.
>
>

slim

unread,
Feb 15, 2011, 4:36:45 PM2/15/11
to General discussion of the Lepton particle engine for Python
It's really nothing special. I use the size attribute to keep the
order, then use the magnet to suck
them in. Code will follow

As for what I'm looking for. I want to be able to have a particles
populate a domain that
is defined by either a 2d shape (i.e a black region of a black and
white bitmap) or a 3d polygon.

For example, if I could have a big letter "A" slowly becomed formed
using particles that'd be my goal.

Oh, and is lepton no longer being worked on because you've found a
better way of dealing with
particles? I'm curious.

thanks!



###############################################################################
#
###############################################################################
class
EnergyController(object):

"""
Pipes energy through the byte
stream.
It sucks all the particles into the
domain

"""
def __init__(self,
domain):
self.domain =
domain
self.magnet = Magnet(Point((0,0,0)), epsilon=5,
charge=50000)

def __call__(self, td,
group):
n_in_domain =
0
head_in_domain =
False
sequence =
[]

for c in
group:
sequence.append((c.size[0],
c))


sequence.sort()

if sequence and sequence[0][0] ==
1:
for i, p in
sequence:
if p.position in
self.domain:
n_in_domain +=
1
p.velocity =
(0,0,0)

if i ==
1:
head_in_domain =
True

elif p.velocity.x == 0 and
p.velocity.y == 0 and p.velocity.z == 0:
if i ==
1:
v =
calculateVelocity(p.color)
p.velocity =
(random.choice((-1,1)) * random.randint(1,15),v,0)

if n_in_domain >
0:
# suck everyone
in
self.magnet.domain =
self.domain
self.magnet(td,
group)

for p in
group:
p.age =
0
p.color[-1] =
1.0

Casey Duncan

unread,
Feb 22, 2011, 3:42:23 PM2/22/11
to py-lept...@googlegroups.com
Thanks for sharing the code. I had a couple of ideas around particle
targeting a while back that might be useful on my blog:

http://eatthedots.blogspot.com/2009/03/lepton-particle-targetting.html

The ides was to allow particles to organize themselves over time into
whatever pattern you like. The idea would be to create two sets of
particles. One set would contain the "target" attributes. These
particles may be static, and may not be drawn, but that need not be
the case. You could create and configure them whatever way you want,
including using domains to determine the attributes. The second set of
particles would have some initial state different from the targets.
They could be random or arranged in a different pattern (maybe
changing from forming one letter or image into another). This second
set of particles would be dynamic and drawn.

A "Target" controller would be used to bind the "dynamic" particles to
the target ones. Over time the target controller would alter the
desired attributes of the dynamic particles until they coincide with
the targets. The number of particles in each group need not be the
same. A bunch of dynamic particles could be targeted to a single
target particle, for example.

Which attributes you target would be up to you. By default, it might
match up all attributes, but you could limit it just to position,
velocity, color, etc. as desired. You could also target different
attributes separately using separate controllers. Also, the target
particles could be changed or rearranged however you want, causing the
dynamic particles to follow them.

As for the state of Lepton, I moved on to some other projects, which
aren't directly about particles per se, but definitely use some of the
ideas from Lepton in terms of simple, pluggable components working
together. You can learn more about them here:

http://pygamesf.org/~casey/grease/doc/
http://pygamesf.org/~casey/planar/doc/

Actually a new release of planar is just about ready and should be out
this week. Might be useful for creating 2D shape domains in Lepton, as
the new version supports arbitrary polygons.

-Casey

Reply all
Reply to author
Forward
0 new messages