0

I have a 2d group of particles that I'd like to set its angular velocity, for the particles to spin around their group center.

I found this method to get the angular velocity of the group, and I have tried inverting the logic to actually set the angular group velocity.

In my attempts I leave most of the logic intact, by getting the group mass, group center and group linear velocity in the same way. But seems most of my trial and errors are not building up to the expected results.

If you have any knowledge on how I should tackle this logic inversion from getting the angular velocity to setting it, I'd love to hear what you have to say.

getParticleGroupAngularVelocity()
{
particleCount = 30;
particleMass = 1.5;
particleGroupMass = 0;
particleGroupInertia = 0;
particleGroupAngularVelocity = 0;

particleGroupCenter = vector(0, 0);
particleGroupLinearVelocity = vector(0, 0);

for (i = 0; i < particleCount; i++)
{
    particleGroupMass += particleMass;
    particleGroupCenter += particleMass * particles[i].position;
    particleGroupLinearVelocity += particleMass * particles[i].velocity;
}

if (particleGroupMass > 0)
{
    particleGroupCenter *= 1 / particleGroupMass;
    particleGroupLinearVelocity *= 1 / particleGroupMass;
}

for (i = 0; i < particleCount; i++)
{
    pos = particles[i].position - particleGroupCenter;
    vel = particles[i].velocity - particleGroupLinearVelocity;
    particleGroupInertia += particleMass * (pos.x * pos.x + pos.y * pos.y);
    particleGroupAngularVelocity += particleMass * (pos.x * vel.y - pos.y * vel.x);
}

if (particleGroupInertia > 0)
{
    particleGroupAngularVelocity *= 1 / particleGroupInertia;
}

return particleGroupAngularVelocity;
}
Claudia
  • 726
  • 1
  • 6
  • 20
  • You have a group of particles, and you want to change the velocities of some or all of the particles in order to give the group a desired "group angular velocity" (I use the term loosely, in the same sense as this code) while keeping the "group linear velocity" the same, is that right? Do you have any other conditions? I ask because there are *many* ways to do that. – Beta May 12 '14 at 16:42
  • I want to be able to change the velocity of all the particles while keeping the groups linear velocity. So, if the group of particles is moving at a constant velocity on the x and/or y axis, I'd like to be able to make the group of particles rotate around their center, without affecting their other movements. – Claudia May 12 '14 at 17:56
  • As for other conditions, I can't really think of other conditions. But then I might also be lacking some insight on the subject. – Claudia May 12 '14 at 18:00

1 Answers1

1

All right, this should do it.

for (i = 0; i < particleCount; i++)
{
    pos = particles[i].position - particleGroupCenter;
    vel.x = - particleGroupAngularVelocity * pos.y;
    vel.y =   particleGroupAngularVelocity * pos.x;
    particles[i].velocity = vel + particleGroupLinearVelocity;
}

This will preserve the linear velocity of the group. The individual particles will be given velocities as if they were all embedded in the same sheet of glass, rotating about the group center. (Keeping them in those orbits is someone else's problem.)

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Great, that works! Thank you very much Beta. Only one question to remove any kind of doubt. In the original code, there's an adjustment of the velocity based on the inertia. In the solution you provide, the inertia is not used to affect the particle velocities. What would be the reasoning for that? Thanks again, Beta! – Claudia May 12 '14 at 19:52
  • @Claudia: this solution will conserve linear momentum, but not angular momentum. ("Conserve" in the physics sense, "not change".) The original code *measured* the angular momentum, then divided by the moment of inertia to get `particleGroupAngularVelocity`; this code freezes the particles relative to each other, then "spins up" the whole group. – Beta May 12 '14 at 20:11
  • I see. Thanks for your thorough answer and explanation. – Claudia May 12 '14 at 20:17