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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use crate::math::{Isometry, Real, Vector};
#[cfg(feature = "dim3")]
use crate::query::sat;
use crate::shape::{Cuboid, Triangle};
#[cfg(feature = "dim2")]
use crate::{query::sat::support_map_support_map_compute_separation, shape::SupportMap};
#[cfg(feature = "dim3")]
pub fn cuboid_triangle_find_local_separating_edge_twoway(
cube1: &Cuboid,
triangle2: &Triangle,
pos12: &Isometry<Real>,
) -> (Real, Vector<Real>) {
let x2 = pos12 * (triangle2.b - triangle2.a);
let y2 = pos12 * (triangle2.c - triangle2.b);
let z2 = pos12 * (triangle2.a - triangle2.c);
let axes = [
Vector::new(0.0, -x2.z, x2.y),
Vector::new(x2.z, 0.0, -x2.x),
Vector::new(-x2.y, x2.x, 0.0),
Vector::new(0.0, -y2.z, y2.y),
Vector::new(y2.z, 0.0, -y2.x),
Vector::new(-y2.y, y2.x, 0.0),
Vector::new(0.0, -z2.z, z2.y),
Vector::new(z2.z, 0.0, -z2.x),
Vector::new(-z2.y, z2.x, 0.0),
];
sat::cuboid_support_map_find_local_separating_edge_twoway(cube1, triangle2, &axes, pos12)
}
#[cfg(feature = "dim2")]
pub fn triangle_support_map_find_local_separating_normal_oneway(
triangle1: &Triangle,
shape2: &impl SupportMap,
pos12: &Isometry<Real>,
) -> (Real, Vector<Real>) {
let mut best_sep = -Real::MAX;
let mut best_normal = Vector::zeros();
for edge in &triangle1.edges() {
if let Some(normal) = edge.normal() {
let sep = support_map_support_map_compute_separation(triangle1, shape2, pos12, &normal);
if sep > best_sep {
best_sep = sep;
best_normal = *normal;
}
}
}
(best_sep, best_normal)
}
#[cfg(feature = "dim2")]
pub fn triangle_cuboid_find_local_separating_normal_oneway(
triangle1: &Triangle,
shape2: &Cuboid,
pos12: &Isometry<Real>,
) -> (Real, Vector<Real>) {
triangle_support_map_find_local_separating_normal_oneway(triangle1, shape2, pos12)
}
#[cfg(feature = "dim3")]
pub fn triangle_cuboid_find_local_separating_normal_oneway(
triangle1: &Triangle,
shape2: &Cuboid,
pos12: &Isometry<Real>,
) -> (Real, Vector<Real>) {
sat::point_cuboid_find_local_separating_normal_oneway(
triangle1.a,
triangle1.normal(),
shape2,
pos12,
)
}