phyz_contact/material.rs
1//! Contact material properties.
2
3/// Material properties for contact interactions.
4#[derive(Debug, Clone)]
5pub struct ContactMaterial {
6 /// Contact stiffness (N/m).
7 pub stiffness: f64,
8 /// Contact damping (N·s/m).
9 pub damping: f64,
10 /// Coefficient of friction (dimensionless).
11 pub friction: f64,
12 /// Coefficient of restitution (0 = inelastic, 1 = elastic).
13 pub bounce: f64,
14 /// Constraint force mixing (for numerical stability).
15 pub soft_cfm: f64,
16 /// Error reduction parameter (for constraint drift correction).
17 pub soft_erp: f64,
18}
19
20impl Default for ContactMaterial {
21 fn default() -> Self {
22 Self {
23 stiffness: 10000.0,
24 damping: 100.0,
25 friction: 0.5,
26 bounce: 0.0,
27 soft_cfm: 0.0001,
28 soft_erp: 0.2,
29 }
30 }
31}
32
33impl ContactMaterial {
34 /// Create a new contact material with custom parameters.
35 pub fn new(stiffness: f64, damping: f64, friction: f64, bounce: f64) -> Self {
36 Self {
37 stiffness,
38 damping,
39 friction,
40 bounce,
41 soft_cfm: 0.0001,
42 soft_erp: 0.2,
43 }
44 }
45
46 /// Create a bouncy material (high restitution).
47 pub fn bouncy() -> Self {
48 Self {
49 stiffness: 10000.0,
50 damping: 50.0,
51 friction: 0.3,
52 bounce: 0.8,
53 soft_cfm: 0.0001,
54 soft_erp: 0.2,
55 }
56 }
57
58 /// Create a soft material (low stiffness).
59 pub fn soft() -> Self {
60 Self {
61 stiffness: 1000.0,
62 damping: 200.0,
63 friction: 0.7,
64 bounce: 0.1,
65 soft_cfm: 0.001,
66 soft_erp: 0.2,
67 }
68 }
69
70 /// Create a rigid material (high stiffness).
71 pub fn rigid() -> Self {
72 Self {
73 stiffness: 50000.0,
74 damping: 100.0,
75 friction: 0.5,
76 bounce: 0.0,
77 soft_cfm: 0.00001,
78 soft_erp: 0.2,
79 }
80 }
81}