1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* // Copyright (c) 2021 Feng Yang
* //
* // I am making my contributions/submissions to this project solely in my
* // personal capacity and am not conveying any rights to any intellectual
* // property of any third parties.
*/
use crate::vector2::Vector2D;
use crate::vector3::Vector3D;
use num::traits::Pow;
//MARK:- computeDragForce
pub fn compute_drag_force2(drag_coefficient: f64,
radius: f64,
velocity: &Vector2D) -> Vector2D {
// Stoke's drag force assuming our Reynolds number is very low.
// http://en.wikipedia.org/wiki/Drag_(physics)#Very_low_Reynolds_numbers:_Stokes.27_drag
return *velocity * -6.0 * crate::constants::K_PI_D * drag_coefficient * radius;
}
pub fn compute_drag_force3(drag_coefficient: f64,
radius: f64,
velocity: &Vector3D) -> Vector3D {
// Stoke's drag force assuming our Reynolds number is very low.
// http://en.wikipedia.org/wiki/Drag_(physics)#Very_low_Reynolds_numbers:_Stokes.27_drag
return *velocity * -6.0 * crate::constants::K_PI_D * drag_coefficient * radius;
}
//MARK:- projectAndApplyFriction
pub fn project_and_apply_friction2(vel: &Vector2D,
normal: &Vector2D,
friction_coefficient: f64) -> Vector2D {
let mut velt = vel.projected(normal);
if velt.length_squared() > 0.0 {
let veln = f64::max(-vel.dot(&normal), 0.0);
velt *= f64::max(1.0 - friction_coefficient * veln / velt.length(), 0.0)
}
return velt;
}
pub fn project_and_apply_friction3(vel: &Vector3D,
normal: &Vector3D,
friction_coefficient: f64) -> Vector3D {
let mut velt = vel.projected(normal);
if velt.length_squared() > 0.0 {
let veln = f64::max(-vel.dot(normal), 0.0);
velt *= f64::max(1.0 - friction_coefficient * veln / velt.length(), 0.0)
}
return velt;
}
//MARK:- compute_pressure_from_eos
pub fn compute_pressure_from_eos(density: f64,
target_density: f64,
eos_scale: f64,
eos_exponent: f64,
negative_pressure_scale: f64) -> f64 {
// See Murnaghan-Tait equation of state from
// https://en.wikipedia.org/wiki/Tait_equation
let mut p = eos_scale / eos_exponent * (f64::pow(density / target_density, eos_exponent) - 1.0);
// Negative pressure scaling
if p < 0.0 {
p *= negative_pressure_scale
}
return p;
}