@@ -38,14 +38,15 @@ public static Vector2 GenerateForce_Friction_Static(Vector2 _forceNormal, Vector
38
38
float max = _frictionCoefficient_Static * _forceNormal . magnitude ;
39
39
40
40
Vector2 force = _frictionCoefficient_Static * _forceNormal ;
41
+ float mag = _forceOpposing . magnitude ;
41
42
42
- if ( _forceOpposing . magnitude > max )
43
+ if ( mag > max )
43
44
{
44
- force -= _forceOpposing ;
45
+ force = - _forceOpposing ;
45
46
}
46
47
else
47
48
{
48
- force = - _frictionCoefficient_Static * _forceNormal ;
49
+ force = - _forceOpposing * max / mag ;
49
50
}
50
51
51
52
return force ;
@@ -55,7 +56,7 @@ public static Vector2 GenerateForce_Friction_Kinetic(Vector2 f_normal, Vector2 p
55
56
{
56
57
// f_friction_k = -coeff*|f_normal| * unit(vel)
57
58
58
- Vector2 force = - frictionCoefficient_kinetic * f_normal . magnitude * particleVelocity ;
59
+ Vector2 force = - frictionCoefficient_kinetic * f_normal . magnitude * particleVelocity . normalized ;
59
60
60
61
return force ;
61
62
}
@@ -64,7 +65,9 @@ public static Vector2 GenerateForce_Drag(Vector2 particleVelocity, Vector2 fluid
64
65
{
65
66
// f_drag = (p * u^2 * area * coeff)/2
66
67
67
- Vector2 force = ( particleVelocity - fluidVelocity ) * ( fluidDensity * particleVelocity . magnitude * particleVelocity . magnitude * objectArea_crossSection * objectDragCoefficient * 0.5f ) ;
68
+ Vector2 diff = particleVelocity - fluidVelocity ;
69
+
70
+ Vector2 force = diff * diff . magnitude * ( fluidDensity * objectArea_crossSection * objectDragCoefficient * 0.5f ) ;
68
71
69
72
return force ;
70
73
}
@@ -77,11 +80,13 @@ public static Vector2 GenerateForce_Spring(Vector2 particlePosition, Vector2 anc
77
80
// Calculate relative position of the particle to the anchor.
78
81
Vector2 position = particlePosition - anchorPosition ;
79
82
83
+ float springLength = position . magnitude ;
84
+
80
85
// Generate the force.
81
- float force = - springStiffnessCoefficient * ( position . magnitude - springRestingLength ) ;
86
+ float force = - springStiffnessCoefficient * ( springLength - springRestingLength ) ;
82
87
83
88
// Return the force at the current position.
84
- return position * force ;
89
+ return position * force / springLength ;
85
90
}
86
91
public static Vector2 GenerateForce_Spring_Damping ( Vector2 particlePosition , Vector2 anchorPosition , float springRestingLength , float springStiffnessCoefficient , float springDamping , float springConstant , Vector2 particleVelocity )
87
92
{
0 commit comments