Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
testEllipsoidalPlacement.cpp
Go to the documentation of this file.
2#include <Eigen/Geometry>
3#include <iostream>
4#include <stdexcept>
5using V = Eigen::Vector3d;
6using M = Eigen::Matrix3d;
7void check(bool ok, const char *message)
8{
9 if(!ok)
10 {
11 throw std::runtime_error(message);
12 }
13}
14int main()
15{
16 using namespace model::ellipsoidalPlacement;
17 try
18 {
19 const M sphere = M::Identity();
20 check(overlap(V(1.9, 0, 0), sphere, sphere), "Overlapping spheres missed");
21 check(overlap(V(2, 0, 0), sphere, sphere), "Touching spheres missed");
22 check(!overlap(V(2.01, 0, 0), sphere, sphere), "Separated spheres rejected");
23 check(overlap(V::Zero(), sphere, 100 * sphere), "Contained spheres missed");
24 const M shape = V(9, 4, 1).asDiagonal();
25 check(!overlap(V(6.1, 0, 0), shape, shape), "Separated ellipsoids rejected");
26 check(overlap(V(5.9, 0, 0), shape, shape), "Overlapping ellipsoids missed");
27 check(!overlap(V(0, 0, 2.1), shape, shape), "Thin-direction gap rejected");
28 check(!overlap(V(4.01, 0, 0), shape, sphere), "Separated sphere/ellipsoid rejected");
29 check(overlap(V(3.99, 0, 0), shape, sphere), "Sphere/ellipsoid overlap missed");
30 const M rotation = Eigen::AngleAxisd(.7, V(1, 2, 3).normalized()).toRotationMatrix();
31 check(!overlap(rotation * V(6.1, 0, 0), rotation * shape * rotation.transpose(),
32 rotation * shape * rotation.transpose()),
33 "Rotation changed separation");
34 check(!overlap(V(6.1e-8, 0, 0), shape * 1e-16, shape * 1e-16), "Scaling changed separation");
35 // All vertices outside the unit ball, but the face crosses it.
36 check(triangleDistanceSquared(V(-3, -3, .5), V(3, -3, .5), V(0, 3, .5)) < 1,
37 "Triangle interior intersection missed");
38 check(triangleDistanceSquared(V(-3, -3, 2), V(3, -3, 2), V(0, 3, 2)) > 1, "Separated face rejected");
39 check(triangleDistanceSquared(V(-2, 0, 0), V(2, 0, 0), V(2, 0, 0)) == 0, "Degenerate edge intersection missed");
40 check(triangleDistanceSquared(V(2, 0, 0), V(2, 0, 0), V(2, 0, 0)) == 4, "Degenerate point distance failed");
41 check(triangleDistanceSquared(V(2, 0, 0), V(0, 2, 0), V(0, 0, 2)) > 1, "Outside triangle distance failed");
42 std::cout << "PASS ellipsoid contact, rotations, scales, boundary triangles and degeneracies\n";
43 return 0;
44 }
45 catch(const std::exception &error)
46 {
47 std::cerr << error.what() << '\n';
48 return 1;
49 }
50}
Eigen::Matrix3d M
Eigen::Vector3d V
double triangleDistanceSquared(const Eigen::Vector3d &a, const Eigen::Vector3d &b, const Eigen::Vector3d &c)
bool overlap(const Eigen::Vector3d &displacement, const Eigen::Matrix3d &first, const Eigen::Matrix3d &second)
M sphere(const V &r, double a, const M &e, double n=nu, double m=mu)
void check(bool ok, const char *message)
int e