Exemplo n.º 1
0
		b2Vec2 composite_body::get_com_linear_velocity() const
		{
			b2Vec2 com_vel(0.0f, 0.0f);
			float sum_mass = 0.0f;
			for(b2Body const* b : m_bodies)
			{
				float mass = b->GetMass();
				com_vel += mass * b->GetLinearVelocity();
				sum_mass += mass;
			}
			return (1.0f / sum_mass) * com_vel;
		}
Exemplo n.º 2
0
std::vector<double> centerofmass_vel(int type)
{
    /*center of mass velocity scaled with time_step*/
    std::vector<double> com_vel (3);
    int i, j;
    int count = 0;

    updatePartCfg(WITHOUT_BONDS);
    for (j=0; j<n_part; j++) {
        if (type == partCfg[j].p.type) {
            for (i=0; i<3; i++) {
            	com_vel[i] += partCfg[j].m.v[i];
            }
            count++;
        }
    }

    for (i=0; i<3; i++) {
        com_vel[i] /= count;
    }
    return com_vel;
}