Working on a simple 3d physics engine. I connected 8 point particles with springs so that it forms a cuboid.
Moving the particles via linear forces is easy but integrating angular forces is something I have no clue on how to do since point particles don't have an orientation. However if particles are connected via springs the particles should have an orientation from the center of mass to itself right? What I'm wondering is how do I integrate the angular velocity to the orientation of the particle and the center of mass. I looked online and I assume you can do something like this.
Get the center of mass of all the particles.
Calculate the moment of inertia for point particles which would be I = mr^2
Sum up torque from all the forces
Add angular velocity to itself via angularVelocity += invertedInertia * torque * dt;
Apply angular velocity damping
Now what I'm wondering is how do you integrate the angular velocity to the particle position? For a rigid body you could for example do it by using a quaternion but point particles don't have an orientation. Any ideas?
AFAIK you would either need to add orientation and inertia tensors to the particles or ignore any rotation effects. There are other approaches used for soft body simulation that may work the way you want but require some global operations to estimate current orientation based on all particles in the shape.
You can integrate angular velocity to orientation (as a 3x3 matrix) using this:
The skew symmetric function returns a 3x3 matrix according to this definition. Angular velocity is a vector in world space representing the rotation axis. The orthonormalization is used to prevent skewing that can accumulate over time. Despite conventional wisdom, 3x3 matrices are faster than quaternions because the operations are more easily vectorized.
dragonm246 said: Now what I'm wondering is how do you integrate the angular velocity to the particle position? For a rigid body you could for example do it by using a quaternion but point particles don't have an orientation. Any ideas?
Following your idea, the particles don't need an orientation. You would just rotate them around the com of all particles.
But i don't think this will be robust. Say you have 8 particles for a cube forming a virtual rigid body, it's easy to find the com of this body, but maintaining some orientation for it requires some state, and there is no guarantee such state will always change continuously from one simulation step to the next. A typical problem is flipping. If we push one prticle inside the cube, it may snap to the opposite corner because the springs don't care about orientation but just about distance. Such flipping also flips the handness of a virtual cube orientation, breaking any representation of said orientation.
What does work is adding orientation to each particle, and extending the springs to have a given direction in that space. The springs would then try to resolve flipping cases, and there is no need for a virtual cube at all. It's more costly ofc., but still cheaper than rigid bodies, because you do not need to handle non uniform inertia. Just treat each particle as a point mass. You still get realistic inertia behavior from connected particles indirectly out of the angular constraints, without any need to work on that specifically.
JoeJ said: But i don't think this will be robust. Say you have 8 particles for a cube forming a virtual rigid body, it's easy to find the com of this body, but maintaining some orientation for it requires some state, and there is no guarantee such state will always change continuously from one simulation step to the next.
I take that back. There is no need to maintein orientation from frame to frame. All that's needed to integrate angular velocity is angular momentum and inertia of the virtual body.
Thanks for the replies both @Aressera and @JoeJ its a huge help! I think if I were to add orientation to the particles I could basically simulate particles as if they were spheres then? I could then try to solve the springs since if one particle is spinning it would rotate the spring around effectively rotating the cube if I were to change the angular velocity of all the particles. However I don't know how complicate it would be to implement all of that since I only know high school math and a little bit of physics.
Aressera said:
AFAIK you would either need to add orientation and inertia tensors to the particles or ignore any rotation effects. There are other approaches used for soft body simulation that may work the way you want but require some global operations to estimate current orientation based on all particles in the shape.
You can integrate angular velocity to orientation (as a 3x3 matrix) using this:
The skew symmetric function returns a 3x3 matrix according to this definition. Angular velocity is a vector in world space representing the rotation axis. The orthonormalization is used to prevent skewing that can accumulate over time. Despite conventional wisdom, 3x3 matrices are faster than quaternions because the operations are more easily vectorized.
For this to work would I need to store the orientation of every particle or should the cuboid have its own orientation stored? Once I got the orientation I'd assume it wouldn't be that difficult to rotate the particles around the center of mass since you would be essentially rotating points around an origin.
I'm fine if the solution isn't physically accurate just looking for a way to solve this problem while still looking fairly ok.
dragonm246 said: I think if I were to add orientation to the particles I could basically simulate particles as if they were spheres then?
Yes, you can give them a radius. But you don't have to, it also works with points. It's a bit liek the real world or fluid sim: Angular effects show up as a result of particle interactions with each other, but they are not modelled explecitly per particle. (To some degree at least - sadly i don't remember if i did integrate abgular velocity per particle when i worked on this. Probably i did.)
dragonm246 said: However I don't know how complicate it would be to implement all of that since I only know high school math and a little bit of physics.
I'm also capped at high school level, but i got it to work mostly following intuition and common sense. The angular part of physics is more complicated, but it follows the same rules as the linear part. I would be optimistic if you want to give it a try.
I'll give a example on what to expect: I had constraints involving multiple particles, e.g. 3 particles should form a triangle with given edge lengths, in a 2D world. If we do this with distance constraints only, we get a potential flipping problem:
If one particle is pushed through it's opposite edge, the shape gets inverted and the distance constraints do not resolve the illegal state. There are many variations of this problem, and because i could not solve it, i have introduced oriented particles for a working fix.
Another application is this:
We can from a complex shape like a tree, and it keeps its shape. Using only distance constraints, it would all fall down to the ground. So you might start to add more (invisible) distance constraints to make it more stable:
Now it's better, but also much more costly. And it's still not robust. We can still flip some branches and they will form inverted shapes. It does not work. And that's the point where oriented particles become not only the robust alternative, but also the faster method since there are less constraints.
So it depends on the kind of complexity you want to achieve. For simple structures or cloth oriented particles might be overkill, for complex structures it might be worth it.
Aressera said: AFAIK you would either need to add orientation and inertia tensors to the particles or ignore any rotation effects.
Sounds you did the same assumption i did intially. But no, we don't need to track a state of orientation or inertia. We can calculate those properties on demand instead.
Say we have those 8 particles connected by springs, and we want to calculate angular velocity treating the whole system as a single rigid body (which i call the ‘virtual cube body’). Then we can calculate angular velocity from the linear velocities of the particles like so:
// 1. calc com and linear velocity of our virtual body:
float mass = 0;
vec3 com(0);
vec3 linVel(0);
for each particle
{
mass += particle.mass;
com += particle.pos * particle.mass;
linVel += particle.linvel * particle.mass;
}
com /= mass;
linVel /= mass;
// 2. calc angular momentum of the vitual body:
vec3 angMom(0);
for each particle
{
vec3 pLinMom = particle.linvel * particle.mass;
vec3 pAngMom = vec3(particle.pos - com).Cross(pLinMom);
// + particle.uniformInertia * particle.angVel; // if we have spherical particles with inertia and angular velocity
angMom += pAngMom;
}
// 3. calc angular velocity from momentum, but we need inertia around that axis to do so:
vec3 axis = normalize(angMom);
float inertia = 0;
for each particle
{
vec3 d = particle.com - com;
vec3 temp = (axis * axis.Dot(d) - d);
inertia += particle.mass * temp.Dot(temp);
//inertia += info->uniformInertia; // if we have spherical particles
}
vec3 virtualAngularVelocity = angMom / inertia;
After that we could rotate the particles around the com using virtualAngularVelocity to integrate angular velocity, and momentum of the whole system is preserved correctly. (Assuming i did no mistake in the pseude code)
So if i got the question right, this should be the answer.