Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91105115
compute_contact.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Nov 7, 23:08
Size
933 B
Mime Type
text/x-c
Expires
Sat, Nov 9, 23:08 (2 d)
Engine
blob
Format
Raw Data
Handle
22174927
Attached To
R7571 SP4E-TB-TL-FR
compute_contact.cc
View Options
#include "compute_contact.hh"
#include "ping_pong_ball.hh"
#include <cmath>
/* -------------------------------------------------------------------------- */
void ComputeContact::setPenalty(Real penalty) {
this->penalty = penalty;
}
/* -------------------------------------------------------------------------- */
void ComputeContact::compute(System& system) {
auto penalty_contact = [this](Particle& par1, Particle& par2) {
auto& ppb1 = static_cast<PingPongBall&>(par1);
auto& ppb2 = static_cast<PingPongBall&>(par2);
auto v_r = ppb2.getPosition() - ppb1.getPosition();
auto r = std::sqrt(v_r.squaredNorm());
v_r /= r;
auto penetration = ppb1.getRadius() + ppb2.getRadius() - r;
Vector force;
if (penetration > 0) {
force = v_r;
force *= penalty * penetration;
ppb1.getForce() -= force;
ppb2.getForce() += force;
}
};
applyOnPairs(penalty_contact, system);
}
Event Timeline
Log In to Comment