/** * aligns the body x axis with the velocity vector */ void alignVelocityXAxis(double vel_tol = .01) { Eigen::Quaterniond wind_axes_to_body_axes = Eigen::Quaterniond::Identity(); //transforms vectors in wind frame to vectors in body frame if (velocity().norm() > vel_tol) { wind_axes_to_body_axes.setFromTwoVectors(Eigen::Vector3d::UnitX(), velocity()); } Eigen::Matrix3d body_axes_to_wind_axes = wind_axes_to_body_axes.toRotationMatrix().transpose(); angularVelocity() = body_axes_to_wind_axes * angularVelocity(); velocity() = body_axes_to_wind_axes * velocity(); acceleration() = body_axes_to_wind_axes * acceleration(); orientation() = orientation() * wind_axes_to_body_axes; }
/* Complete this function */ void init(const Vector3 & spawnPoint) { // Vectors used to create new particle Vector3 velocity( 0, 5, 0); Vector3 acceleration( 0, 0, 0); Color3d colors( 0, 0, 1); for(int i = 0; i < 1500; ++i) { // Get angle for velocity float theta = randFloat(); // Get random velocity velocity = Vector3( randFloat(-50*cos(theta), 50 * sin(theta)), randFloat(-50*cos(theta), 50 * sin(theta)), randFloat(0,10) ); // Get random colors for each particle colors = Color3d( randFloat(0,1), randFloat(0,.2), randFloat(0,1) ); // Determine acceleration in one direction acceleration.y = -10; // Push back newly created particle in vector particles.push_back( Particle( spawnPoint, velocity, acceleration, colors, 10.0) ); } }
//---------------------------------------------------------------------- // RK4 functions // floating point ops: 6 //---------------------------------------------------------------------- Derivative evaluate(State initial, float t) { Derivative OUT; OUT.dx = initial.v; OUT.dv = acceleration(initial, t); return OUT; }
void BulletEmitter::pattern3() { if (timeRef > 0) { Vector2f position(320.0f, 240.0f); Vector2f acceleration(0.0f, 0.0f); Color color(0.8f, 0.0f, 1.0f, 0.9f); float magnitude = 4.0f; Bullet b; b.set(position, dir, magnitude, acceleration, color); bulletMem.add(b); b.set(position, dir + 3.14f, magnitude, acceleration, color); bulletMem.add(b); b.set(position, dir + 3.14f / 2, magnitude, acceleration, color); bulletMem.add(b); b.set(position, dir + 3 * 3.14f / 2, magnitude, acceleration, color); bulletMem.add(b); b.set(position, -dir, magnitude, acceleration, color); bulletMem.add(b); b.set(position, -dir + 3.14f, magnitude, acceleration, color); bulletMem.add(b); b.set(position, -dir + 3.14f / 2, magnitude, acceleration, color); bulletMem.add(b); b.set(position, -dir + 3 * 3.14f / 2, magnitude, acceleration, color); bulletMem.add(b); dir += 0.03f; } --timeRef; if (timeRef < -10) timeRef = 30; }
void BulletEmitter::pattern2() { if (timeRef == 0) { Vector2f position(320.0f, 240.0f); Vector2f acceleration(0.0f, 0.0f); Color color(0.8f, 0.0f, 1.0f, 0.9f); for (int i = 0; i < 1; ++i) { float initialDir = rng.genRand(0.0, 6.28); float fireDir = rng.genRand(3.14 / 3, 2 * 3.14 / 3); float magnitude = rng.genRand(2.0, 4.0); for (int i = 0; i < 180; ++i) { Bullet b; b.set(position, initialDir, magnitude, acceleration, color); b.queueAction(BulletAction(&bulletMem, VelocityAbs, 20, 2)); b.queueAction(BulletAction(&bulletMem, DirectionAbs, 20, (float)i * 30 / 6.28)); b.queueAction(BulletAction(&bulletMem, VelocityAbs, 40, 0.001)); b.queueAction(BulletAction(&bulletMem, VelocityAbs, 100, 7)); b.queueAction(BulletAction(&bulletMem, DirectionAbs, 100, fireDir)); bulletMem.add(b); } } timeRef = 30; } else timeRef--; }
int main() { //maakt buiten kant weg for( j = 0 ; j < 75 ; ++j ){ for( i = 0; i < 75 ; ++i ){ map[j][linksbuiten] = '|'; map[j][rechtsbuiten] = '|'; } } //maakt de binnen weg for(int i=0; i < 20; ++i) { for(int j=0; j < 20; ++j) { map[i][linksbinnen] = '#'; map[i][rechtsbinnen] = '#'; } } for( ; ; ) { weggetje(); clearscreen(); //getch(); acceleration(); keyhit(); } }
void Physics::updateKinematics(float delta){ Vector displacement=delta*velocity_+0.5f*delta*delta*acceleration_; bv_->translate(displacement.x,displacement.y,displacement.z); velocity_+=(delta*acceleration()); Matrix omega( 0, angVel_.z, -angVel_.y, 0, -angVel_.z, 0, angVel_.x, 0, angVel_.y, -angVel_.x, 0, 0, 0,0,0,0); //set up the matrix for calculating rotation based on //the objects angular velocity Matrix Rcurr= bv_->rotation(); //Get the current rotation of the object Matrix Rdelta=delta*(omega*Rcurr); //Calculate the change in rotation of the object Matrix Rnew=orthoNormalize(Rcurr+Rdelta); //calculate the new rotation matrix Matrix Rnet=orthoNormalize(Rcurr.transpose()*Rnew); //figure out what the net rotation is angVel_=angVel_+delta*angAccel_; //update the angular velocity bv_->rotate(Rnet); }
void MouseWrapper_::move( int8_t x, int8_t y) { if (x != 0 || y != 0) { mouseActiveForCycles++; double accel = (double) acceleration(mouseActiveForCycles); float moveX = 0; float moveY = 0; if (x > 0) { moveX = (x * accel) + carriedOverX; carriedOverX = moveX - floor(moveX); } else if (x < 0) { moveX = (x * accel) - carriedOverX; carriedOverX = ceil(moveX) - moveX; } if (y > 0) { moveY = (y * accel) + carriedOverY; carriedOverY = moveY - floor(moveY); } else if (y < 0) { moveY = (y * accel) - carriedOverY; carriedOverY = ceil(moveY) - moveY; } end_warping(); Mouse.move(moveX, moveY, 0); } else { mouseActiveForCycles = 0; } }
void StabilizeStepper::step() { const std::size_t num_beads(_space->num_beads()); // Calculate Force vector_list acceleration(num_beads, Vector3d(0,0,0)); const vector_list force_list(_model->calculate_force(*(_space.get()))); double max_accel(0); for (std::size_t i(0); i < num_beads; ++i) { acceleration[i] = force_list.at(i) / _mass_list.at(i); if (norm(acceleration[i]) > max_accel) max_accel = norm(acceleration[i]); } // Calculate delta _dt = sqrt(_dx/max_accel)/2; // Update Coordinate std::list<double> displacements; for (std::size_t i(0); i < num_beads; ++i) { const Vector3d direction(acceleration.at(i) * _dt*_dt/2); _space->move(i, direction); displacements.push_back(norm(direction)); } // Update NeighborList for (auto itr(_neighbor_list_managers.begin()); itr != _neighbor_list_managers.end(); ++itr) { (*itr).add_displacements(displacements); if ((*itr).to_update(_space->t())) (*itr).update(*(_space.get())); } _space->set_t(_space->t() + _dt); }
Derivative evaluate(const State &initial, float t) { Derivative output; output.dx = initial.v; output.dv = acceleration(initial, t); return output; }
void Foam::fv::tabulatedAccelerationSource::addSup ( const RhoFieldType& rho, fvMatrix<vector>& eqn, const label fieldi ) { Vector<vector> acceleration(motion_.acceleration()); // If gravitational force is present combine with the linear acceleration if (mesh_.foundObject<uniformDimensionedVectorField>("g")) { uniformDimensionedVectorField& g = mesh_.lookupObjectRef<uniformDimensionedVectorField>("g"); const uniformDimensionedScalarField& hRef = mesh_.lookupObject<uniformDimensionedScalarField>("hRef"); g = g0_ - dimensionedVector("a", dimAcceleration, acceleration.x()); dimensionedScalar ghRef ( mag(g.value()) > SMALL ? g & (cmptMag(g.value())/mag(g.value()))*hRef : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0) ); mesh_.lookupObjectRef<volScalarField>("gh") = (g & mesh_.C()) - ghRef; mesh_.lookupObjectRef<surfaceScalarField>("ghf") = (g & mesh_.Cf()) - ghRef; } // ... otherwise include explicitly in the momentum equation else { eqn -= rho*dimensionedVector("a", dimAcceleration, acceleration.x()); } dimensionedVector Omega ( "Omega", dimensionSet(0, 0, -1, 0, 0), acceleration.y() ); dimensionedVector dOmegaDT ( "dOmegaDT", dimensionSet(0, 0, -2, 0, 0), acceleration.z() ); eqn -= ( rho*(2*Omega ^ eqn.psi()) // Coriolis force + rho*(Omega ^ (Omega ^ mesh_.C())) // Centrifugal force + rho*(dOmegaDT ^ mesh_.C()) // Angular tabulatedAcceleration force ); }
Derivative evaluate(const RigidBody *initial, float t) { Derivative output; output.dx = initial->_velocity; output.dv = acceleration(); output.w = initial->_angularVelocity; output.dw = 0; return output; }
Derivative evaluate(const State &initial, float t, float dt, const Derivative &d) { State state; state.x = initial.x + d.dx*dt; state.v = initial.v + d.dv*dt; Derivative output; output.dx = state.v; output.dv = acceleration(state, t+dt); return output; }
int QDeclarativeParticleMotionGravity::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDeclarativeParticleMotion::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { if (_id < 3) qt_static_metacall(this, _c, _id, _a); _id -= 3; } #ifndef QT_NO_PROPERTIES else if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< qreal*>(_v) = xAttractor(); break; case 1: *reinterpret_cast< qreal*>(_v) = yAttractor(); break; case 2: *reinterpret_cast< qreal*>(_v) = acceleration(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setXAttractor(*reinterpret_cast< qreal*>(_v)); break; case 1: setYAttractor(*reinterpret_cast< qreal*>(_v)); break; case 2: setAcceleration(*reinterpret_cast< qreal*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos, const TileSpec tiles[]) { // Texture u8 texid = myrand_range(0, 5); video::ITexture *texture; struct TileAnimationParams anim; anim.type = TAT_NONE; // Only use first frame of animated texture if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION) texture = tiles[texid].frames[0].texture; else texture = tiles[texid].texture; float size = rand() % 64 / 512.; float visual_size = BS * size; v2f texsize(size * 2, size * 2); v2f texpos; texpos.X = ((rand() % 64) / 64. - texsize.X); texpos.Y = ((rand() % 64) / 64. - texsize.Y); // Physics v3f velocity((rand() % 100 / 50. - 1) / 1.5, rand() % 100 / 35., (rand() % 100 / 50. - 1) / 1.5); v3f acceleration(0,-9,0); v3f particlepos = v3f( (f32) pos.X + rand() %100 /200. - 0.25, (f32) pos.Y + rand() %100 /200. - 0.25, (f32) pos.Z + rand() %100 /200. - 0.25 ); Particle* toadd = new Particle( gamedef, smgr, player, m_env, particlepos, velocity, acceleration, rand() % 100 / 100., // expiration time visual_size, true, false, false, texture, texpos, texsize, anim, 0); addParticle(toadd); }
//gets the closest object on the path of this ray //and sets t to whatever the appropriate t value is //will return a negative t if the object is behind us SceneObject getClosestObject(Ray ray, float * t, SceneProperties scene) { if (useAccelStructure) { return acceleration(ray, t, scene); } else { return noAcceleration(ray, t, scene); } }
void YHEntity::calculateWithRK4(YHVector2 & pos, YHVector2 & vel, YHVector2 & acc, float dt) const { YHVector2 pos2 = YHVector2(pos.getX() + vel.getX() * 0.5f * dt, pos.getY() + vel.getY() * 0.5f * dt); YHVector2 vel2 = YHVector2(vel.getX() + acc.getX() * 0.5f * dt, vel.getY() + acc.getY() * 0.5f * dt); YHVector2 acc2 = acceleration(pos2, vel2, acc, dt); YHVector2 pos3 = YHVector2(pos.getX() + vel2.getX() * 0.5f * dt, pos.getY() + vel2.getY() * 0.5f * dt); YHVector2 vel3 = YHVector2(vel.getX() + acc2.getX() * 0.5f * dt, vel.getY() + acc2.getY() * 0.5f * dt); YHVector2 acc3 = acceleration(pos3, vel3, acc, dt); YHVector2 pos4 = YHVector2(pos.getX() + vel3.getX() * dt, pos.getY() + vel3.getY() * dt); YHVector2 vel4 = YHVector2(vel.getX() + acc3.getX() * dt, vel.getY() + acc3.getY() * dt); YHVector2 acc4 = acceleration(pos4, vel4, acc, dt); pos.setX(pos.getX() + (vel.getX() + 2.0f * vel2.getX() + 2.0f * vel3.getX() + vel4.getX()) / 6.0f * dt); pos.setY(pos.getY() + (vel.getY() + 2.0f * vel2.getY() + 2.0f * vel3.getY() + vel4.getY()) / 6.0f * dt); vel.setX(vel.getX() + (acc.getX() + 2.0f * acc2.getX() + 2.0f * acc3.getX() + acc4.getX()) / 6.0f * dt); vel.setY(vel.getY() + (acc.getY() + 2.0f * acc2.getY() + 2.0f * acc3.getY() + acc4.getY()) / 6.0f * dt); }
task main() { acceleration(5); wait1Msec(1000); acceleration(15); wait1Msec(1000); turnaround(20, 'p'); wait1Msec(1000); turnaround(10, 'u'); wait1Msec(1000); turnaround(30, 't'); wait1Msec(1000); square(10); wait1Msec(1000); square(25); wait1Msec(1000); circle(10); wait1Msec(1000); circle(20); }
Configurations step(Parameters ps, Configurations cs, Length dx, Time dt) { assert(ps.m.size() == cs.position.size()); assert(cs.position.size() == cs.velocity.size()); Configurations csp = cs; for (unsigned i = 0; i < cs.position.size(); i++) { csp.position[i] = cs.position[i] + cs.velocity[i] * dt; csp.velocity[i] = cs.velocity[i] + acceleration(i, ps, cs, dx) * dt; } return csp; }
// floating point ops: 11 Derivative evaluate(State initial, float t, float dt, Derivative d) { State state; state.x = initial.x + d.dx * dt; state.v = initial.v + d.dv * dt; Derivative OUT; OUT.dx = state.v; OUT.dv = acceleration(state, t+dt); return OUT; }
bool Entity::update(float deltaTime) { b2Vec2 velocity = _body->GetLinearVelocity(); b2Vec2 force(0.0f, 0.0f), acceleration(0.0f, 0.0f); acceleration.x = _velocity.x - velocity.x; acceleration.y = _velocity.y - velocity.y; force = _body->GetMass() * acceleration; //_body->ApplyLinearImpulse(force, _body->GetWorldCenter(), true); _body->SetLinearVelocity(Utils::toB2Vec2(_velocity)); return true; }
void GameObject::updatePosition(sf::Time elapsedTime) { sf::Vector2f acceleration(resultantForce.x / mass, resultantForce.y / mass); //calculate velocity sf::Vector2f newVelocity = velocity + acceleration*elapsedTime.asSeconds(); float newVelocityLen = ezo::vecLength(newVelocity.x, newVelocity.y); if(newVelocityLen > maxVelocity) velocity = {newVelocity.x/newVelocityLen*maxVelocity, newVelocity.y/newVelocityLen*maxVelocity}; else velocity = newVelocity; oldPosition = representation.getPosition(); representation.setPosition(representation.getPosition() + velocity*elapsedTime.asSeconds()); }
KOKKOS_INLINE_FUNCTION void operator()(int inode) const { // Getting count as per 'CSR-like' data structure const int element_offset = node_elem_offset(inode); const int element_count = node_elem_offset(inode + 1) - element_offset ; double local_force[] = {0.0, 0.0, 0.0}; // for each element that a node belongs to for(int i = 0; i < element_count ; i++){ // node_elem_offset is a cumulative structure, so // node_elem_offset(inode) should be the index where // a particular row's elem_IDs begin const int nelem = node_elem_ids( element_offset + i, 0); // find the row in an element's stiffness matrix // that corresponds to inode const int elem_node_index = node_elem_ids( element_offset + i, 1); local_force[0] += element_force(nelem, 0, elem_node_index); local_force[1] += element_force(nelem, 1, elem_node_index); local_force[2] += element_force(nelem, 2, elem_node_index); } internal_force(inode, 0) = local_force[0]; internal_force(inode, 1) = local_force[1]; internal_force(inode, 2) = local_force[2]; Scalar v_new[3]; Scalar a_current[3]; const Scalar tol = 1.0e-7; if ( fabs(model_coords(inode,0)-x_bc) > tol ) { //not on x boundary acceleration(inode,0) = a_current[0] = -local_force[0] / nodal_mass(inode); acceleration(inode,1) = a_current[1] = -local_force[1] / nodal_mass(inode); acceleration(inode,2) = a_current[2] = -local_force[2] / nodal_mass(inode); } else { //enforce fixed BC acceleration(inode,0) = a_current[0] = 0; acceleration(inode,1) = a_current[1] = 0; acceleration(inode,2) = a_current[2] = 0; } velocity(inode,0,next_state) = v_new[0] = velocity(inode,0,current_state) + (*prev_dt+*dt)/2.0*a_current[0]; velocity(inode,1,next_state) = v_new[1] = velocity(inode,1,current_state) + (*prev_dt+*dt)/2.0*a_current[1]; velocity(inode,2,next_state) = v_new[2] = velocity(inode,2,current_state) + (*prev_dt+*dt)/2.0*a_current[2]; displacement(inode,0,next_state) = displacement(inode,0,current_state) + *dt*v_new[0]; displacement(inode,1,next_state) = displacement(inode,1,current_state) + *dt*v_new[1]; displacement(inode,2,next_state) = displacement(inode,2,current_state) + *dt*v_new[2]; }
Derivative evaluate(const RigidBody *initial, float t, float dt, const Derivative &d) { State state; state.x = initial->_position + d.dx * dt; state.v = initial->_velocity + d.dv * dt; state.ori = initial->_orientation + d.w * dt; state.dori = initial->_angularVelocity + d.dw * dt; Derivative output; output.dx = state.v; output.dv = acceleration(); output.w = state.dori; output.dw = 0; return output; }
void tick(double dt) { for (Body ¤t : bodies) { glm::vec2 acceleration(0.0); for (const Body &other : bodies) { glm::vec2 to_other = other.position - current.position; double distance2 = glm::length2(to_other); if(distance2 < 0.0001) { continue; } acceleration += glm::vec2(G * other.mass / distance2) * glm::normalize(to_other); } current.velocity += acceleration * glm::vec2(dt); } for (Body ¤t : bodies) { current.position += current.velocity * glm::vec2(dt); } }
void Emitter::prepareParticles(){ // Shotgun stuff if(hasFired && isShotgun){ return; } hasFired = true; for(int i(0); i < density; ++i){ // Shitty random generation for now float rand1 = ((rand()%100)/100.0f)-0.5f; float rand2 = ((rand()%100)/100.0f)-0.5f; float rand3 = ((rand()%100)/100.0f)-0.5f; glm::vec3 position(-1.3f+rand1, 0.0f, rand2); // Emitter parented to camera // position+=camera->getPosition(); glm::vec3 velocity(0.0f, 0.01f+(0.01f*rand3), 0.0f); glm::vec3 acceleration(0.0f, 0.0f, 0.0f); // Random wind interaction for snow particles. // if (rand() % 1000){ // velocity += glm::vec3(0.001 * (rand() % 5), - abs(0.0005 * (rand() % 5)), 0.001 * (rand() % 5)); // } float rotation = 0.0f; // Particle recycling! // Weird that the pointer must be explicitly set to 0, but crashes without this Particle* ptr = 0; if(particles.size() < maxParticles){ ptr = new Particle(*billboard, shader); ptr->setEmissive(particle_texture); } if(particles.size() > 0 && particles[0]->isDead()){ ptr = particles[0]; particles.pop_front(); } if(ptr){ ptr->setInitialValues(position, velocity, acceleration, rotation, lifespan, Particle::ScalingOption::SCALE_DOWN_WITH_AGE, Particle::FadingOption::FADE_NONE); particles.push_back(ptr); } } }
int QPanGesture::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QGesture::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QPointF*>(_v) = lastOffset(); break; case 1: *reinterpret_cast< QPointF*>(_v) = offset(); break; case 2: *reinterpret_cast< QPointF*>(_v) = delta(); break; case 3: *reinterpret_cast< qreal*>(_v) = acceleration(); break; case 4: *reinterpret_cast< qreal*>(_v) = QPanGesture::d_func()->horizontalVelocity(); break; case 5: *reinterpret_cast< qreal*>(_v) = QPanGesture::d_func()->verticalVelocity(); break; } _id -= 6; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setLastOffset(*reinterpret_cast< QPointF*>(_v)); break; case 1: setOffset(*reinterpret_cast< QPointF*>(_v)); break; case 3: setAcceleration(*reinterpret_cast< qreal*>(_v)); break; case 4: QPanGesture::d_func()->setHorizontalVelocity(*reinterpret_cast< qreal*>(_v)); break; case 5: QPanGesture::d_func()->setVerticalVelocity(*reinterpret_cast< qreal*>(_v)); break; } _id -= 6; } else if (_c == QMetaObject::ResetProperty) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 6; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 6; } #endif // QT_NO_PROPERTIES return _id; }
bool SGMFastScanParameters::operator ==(const SGMFastScanParameters &other){ if( element() == other.element() && runSeconds() == other.runSeconds() && energyStart() == other.energyStart() && energyMidpoint() == other.energyMidpoint() && energyEnd() == other.energyEnd() && velocity() == other.velocity() && velocityBase() == other.velocityBase() && acceleration() == other.acceleration() && scalerTime() == other.scalerTime() && baseLine() == other.baseLine() && undulatorStartStep() == other.undulatorStartStep() && undulatorVelocity() == other.undulatorVelocity() && undulatorRelativeStep() == other.undulatorRelativeStep() && exitSlitDistance() == other.exitSlitDistance() && sgmGrating() == other.sgmGrating()){ return true; } return false; }
Derivative Physics::take_derivative(const State &init_state, const Derivative &init_derivative, Body *body_ptr, real_t dt) const { // Make a dt step. State update_state; update_state.position = init_state.position + init_derivative.d_position * dt; update_state.velocity = init_state.velocity + init_derivative.d_velocity * dt; update_state.angular_position = init_state.angular_position + init_derivative.d_angular_position * dt; update_state.angular_velocity = init_state.angular_velocity + init_derivative.d_angular_velocity * dt; Derivative result; result.d_position = update_state.velocity; result.d_angular_position = update_state.angular_velocity; // Compute the new linear and angular acceleration from the new force and torque. acceleration(update_state, body_ptr, dt, result); return result; }
void System::acceleration(Object &mainObject, int i, double time, std::string dimension) { arma::Col<double> tempAcceleration(3); arma::Col<double> acceleration(3); acceleration.zeros(); for (int j = 0; j < numberOfObject; ++j) { if (j!=i) { const Object tempObject = objectlist[j]; Distance d; arma::Col<double> position1, position2; position1 = mainObject.getPosition(); position2 = tempObject.getPosition()+ time*tempObject.getVelocity(); double R = d.twoObjects(position1, position2); if (dimension == "ly") { tempAcceleration = -(tempObject.getMass()* (mainObject.getPosition()-tempObject.getPosition())/ (R*(R*R+epsilon_*epsilon_)));// ly/yr] } else if(dimension == "AU") { tempAcceleration = -4*PI*PI*tempObject.getMass()* (mainObject.getPosition()-tempObject.getPosition())/ (R*(R*R+epsilon_*epsilon_));// ly/yr] } else { std::cout << "dimension must be AU or ly"<< std::endl; } acceleration += tempAcceleration; } //end if } //end for mainObject.setAcceleration(acceleration); }