コード例 #1
0
ldouble yAcceleration(Particle p, vector<Particle> particles) {
	ldouble acceleration = 0;
	for(auto i = particles.begin(); i != particles.end(); ++i) {
		ldouble dy = p.py - i->py;
		if(fabs(dy) > numeric_limits<ldouble>::epsilon())
			acceleration += i->mass / dy*dy * -signum(dy);
	}
	return acceleration * GRAVITY;
}
コード例 #2
0
ldouble xAcceleration(Particle p, vector<Particle> particles) {
	ldouble acceleration = 0;
	for(auto i = particles.begin(); i != particles.end(); ++i) {
		ldouble dx = p.px - i->px;
		if(fabs(dx) > numeric_limits<ldouble>::epsilon())
			acceleration += i->mass / dx*dx * -signum(dx);
	}
	return acceleration * GRAVITY;
}