Skip to content

Commit 2c77b44

Browse files
Improve ContactResult comments and test
- Improve comments in elasticCollisionResponse.jl. - Improve plot definitions in BouncingSphereContactResults.jl.
1 parent 536fd75 commit 2c77b44

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

src/Composition/responseCalculation/elasticCollisionResponse.jl

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -138,50 +138,37 @@ function responseCalculation(material::ElasticContactPairResponseMaterial, obj1:
138138
vsmall = F(material.vsmall)
139139
wsmall = F(material.wsmall)
140140

141-
### signed velocity and relative velocity ####
142141
# Contact points and distances to local part frame (in world frame)
143-
# r_rel1 ... position vector from obj1 to average contact point, resolved in world
144-
# r_rel2 ... position vector from obj2 to average contact point, resolved in world
145-
r_rel1 = rContact - obj1.r_abs
146-
r_rel2 = rContact - obj2.r_abs
142+
r_rel1 = rContact - obj1.r_abs # position vector from obj1 to average contact point, resolved in world
143+
r_rel2 = rContact - obj2.r_abs # position vector from obj2 to average contact point, resolved in world
147144

148145
# Velocities and angular velocities of contact frames in world frame
149-
150-
w1 = obj1.R_abs'*obj1.w
151-
w2 = obj2.R_abs'*obj2.w
152-
v1 = obj1.v0 + cross(w1,r_rel1)
153-
v2 = obj2.v0 + cross(w2,r_rel2)
146+
w1 = obj1.R_abs'*obj1.w # absolute angular velocity vector of obj1, resolved in world
147+
w2 = obj2.R_abs'*obj2.w # absolute angular velocity vector of obj2, resolved in world
148+
v1 = obj1.v0 + cross(w1, r_rel1) # absolute velocity vector of obj1 at average contact point, resolved in world
149+
v2 = obj2.v0 + cross(w2, r_rel2) # absolute velocity vector of obj2 at average contact point, resolved in world
154150

155151
# Velocities and angular velocities in normal and tangential direction
156-
# w_rel ... angular velocity vector of obj2 relative to obj1, resolved in world
157-
# e_w_reg ... regularised direction vector of w_rel, resolved in world
158-
# v_rel ... velocity vector at average contact point on obj2 relative to obj1, resolved in world
159-
w_rel = w2 - w1
160-
e_w_reg = w_rel/Modia3D.regularize(norm(w_rel),wsmall)
161-
v_rel = v2 - v1
162-
163-
# e_n ... points from contact point on obj2 to contact point on obj1, i.e. normal direction into obj2
164-
# s ... signed distance of the contact points, negative during contact
165-
# delta_dot ... signed relative velocity in normal direction, positive for expansion (sign inconsistent with delta!)
166-
# v_t ... tangential velocity vector at average contact point on obj2 relative to obj1, resolved in world
167-
# e_t_reg ... regularised direction vector of v_t, resolved in world
168-
# delta ... penetration, positive during contact
169-
delta_dot = dot(v_rel,e_n)
170-
v_t = v_rel - delta_dot*e_n
171-
e_t_reg = v_t/Modia3D.regularize(norm(v_t),vsmall)
172-
delta = -s
173-
152+
w_rel = w2 - w1 # angular velocity vector of obj2 relative to obj1, resolved in world
153+
e_w_reg = w_rel/Modia3D.regularize(norm(w_rel), wsmall) # regularized direction vector of w_rel, resolved in world
154+
v_rel = v2 - v1 # velocity vector of obj2 relative to obj1 at average contact point, resolved in world
155+
156+
# e_n points from contact point on obj2 to contact point on obj1, i.e. normal direction into obj2
157+
# s = signed distance of the contact points, negative during contact
158+
delta_dot = dot(v_rel, e_n) # signed relative velocity in normal direction, positive for expansion (sign inconsistent with delta!)
159+
v_t = v_rel - delta_dot*e_n # tangential velocity vector of obj2 relative to obj1 at average contact point, resolved in world
160+
e_t_reg = v_t/Modia3D.regularize(norm(v_t), vsmall) # regularized direction vector of v_t, resolved in world
161+
delta = -s # penetration, positive during contact
174162
delta_comp = delta * sqrt(abs(delta))
175163

176-
#fn = -max(F(0.0), c_res * c_geo * delta_comp * (1 - d_res*delta_dot) )
177164
fn = -c_res * c_geo * delta_comp * (1 - d_res*delta_dot) # normal force, negative for pressure!
178165
ft = -mu_k*fn*e_t_reg # tangential force vector acting on obj1, resolved in world
179-
f1 = fn * e_n + ft # total force vector acting on obj1, resolved in world
180-
f2 = -f1 # total force vector acting on obj2, resolved in world
166+
f1 = fn * e_n + ft # total force vector acting at average contact point on obj1, resolved in world
167+
f2 = -f1 # total force vector acting at average contact point on obj2, resolved in world
181168

182169
tau = -mu_r * mu_r_geo * fn * e_w_reg # torque vector acting at average contact point on obj1, resolved in world
183-
t1 = cross(r_rel1,f1) + tau # torque vector acting at obj1, resolved in world
184-
t2 = cross(r_rel2,f2) - tau # torque vector acting at obj2, resolved in world
170+
t1 = cross(r_rel1, f1) + tau # total torque vector acting at obj1, resolved in world
171+
t2 = cross(r_rel2, f2) - tau # total torque vector acting at obj2, resolved in world
185172

186173
return (f1, f2, t1, t2,
187174
ContactResults(delta, # normal contact penetration (positive during contact)

test/Collision/BouncingSphereContactResults.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ simulate!(bouncingSphere, stopTime=stopTime, tolerance=tolerance, dtmax=dtmax, l
3939
requiredFinalStates_atol=1e-6, requiredFinalStates=requiredFinalStates)
4040

4141
@usingModiaPlot
42-
plot(bouncingSphere, ["result.penetration", "result.penetrationVelocity", "result.tangentialVelocity", "result.angularVelocity", "result.normalForce", "result.tangentialForce", "result.torque"], figure=1)
43-
plot(bouncingSphere, ["result.positionVector", "result.normalVector", "result.forceVector", "result.torqueVector"], figure=2)
42+
plot(bouncingSphere, ["result.penetration", "result.penetrationVelocity", "result.tangentialVelocity", "result.angularVelocity"], figure=1)
43+
plot(bouncingSphere, ["result.normalForce", "result.tangentialForce", "result.torque"], figure=2)
44+
plot(bouncingSphere, ["result.positionVector", "result.normalVector", "result.forceVector", "result.torqueVector"], figure=3)
4445

4546
end

0 commit comments

Comments
 (0)