Results 1 to 6 of 6
Thread: Calculating points in a circle
 02142011, 05:18 PM #1
[FIXED] Calculating points in a circle
Hey guys.
I'm trying to emit particles in a nice circle with around 60  100 particles.
My problem is to get these points in a circle.
I'm using Slick, which particle framework allows me to just select a direction of the particle using floats.
The methods looks like this:
setVelocity(float x, float y, int speed)
Here's an example of that:
Java Code:float vx = (float) (0.02f + (Math.random() * 0.04f)); float vy = (float) ((Math.random() * 0.15f)); particle.setVelocity(vx,vy,0.3f);
Java Code:int range = 10; boolean xGrow = true; boolean xStop = false; int parX = xrange; boolean yGrow = false; boolean yReachedButtom = false; boolean yStop = false; int parY = y; while (!xStop) { while (!yStop) { Particle p = system.getNewParticle(this, 1000); p.setColor(1, 1, 1, 0.5f); p.setPosition(x, y); p.setSize(size); p.setVelocity(parX,parY,0.3f); if (!yGrow) { parY; } else { parY++; } if (parY == yrange && !yGrow) { yGrow = true; } if (parY == y+range) { yGrow = false; yReachedButtom = false; } if (parY == y && yReachedButtom) { yStop = true; } } if (xGrow) { parX++; } else { x; } if (parX == x+range && xGrow) { xGrow = false; } if (parX == xrange && !xGrow) { xStop = true; } }
I know I'm using wrong types and all that, and my attempt was pretty bad..
Does anyone know how to do this, so I'll get some particles in a nice round formation? Thanks in advance :)Last edited by Masochist; 02142011 at 07:36 PM.
 Masochist.
 02142011, 05:32 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,879
 Blog Entries
 7
 Rep Power
 21
cenosillicaphobia: the fear for an empty beer glass
 02142011, 05:42 PM #3
Thanks though this part I didn't quite get:
select a random number a in the range [0,2*pi).
How du you suggest I do this? I don't know what you mean by this.:confused: Masochist.
 02142011, 06:00 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,879
 Blog Entries
 7
 Rep Power
 21
 02142011, 07:25 PM #5
Okay, I tried this and got an interresting result:
The particles move in each their direction, and thats great. Sadly, they also travel a lot southeast :L
I can't see why though..
this is my code:
Java Code:public void update(ParticleSystem system, int delta) { timer = delta; if (timer <= 0) { timer = interval; int r = 10; for (int i = 0; i < 20; i++) { double a = Math.PI * 2 * Math.random(); float parX = (float) (x + r * Math.cos(a)); float parY = (float) (y + r * Math.sin(a)); Particle p = system.getNewParticle(this, 1000); p.setColor(1, 1, 1, 0.5f); p.setPosition(x, y); p.setSize(size); p.setVelocity(parX, parY, 0.005f); } } }
 Masochist.
 02142011, 07:36 PM #6
Similar Threads

calculating the angle between 3 points
By imorio in forum New To JavaReplies: 2Last Post: 12242010, 09:49 AM 
Josephu's Circle
By Pyrexkidd in forum New To JavaReplies: 8Last Post: 08012010, 08:44 AM 
Circle arrays
By n00b in forum New To JavaReplies: 15Last Post: 05052010, 05:04 PM 
Circle and line
By c_walker in forum New To JavaReplies: 1Last Post: 01272010, 04:56 AM 
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08242008, 12:30 AM
Bookmarks