Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91511694
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
Mon, Nov 11, 19:19
Size
933 B
Mime Type
text/x-c
Expires
Wed, Nov 13, 19:19 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22276021
Attached To
R9490 Homework_sp4e_Peruzzo_SáezUribe
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