11#include "sfh/math/math.h"
15typedef Eigen::Matrix<double,6,6> mat6;
16typedef Eigen::Matrix<double,6,1> vec6;
17typedef Eigen::Matrix<double,3,3> mat3;
18typedef Eigen::Matrix<double,2,1> vec2;
19typedef Eigen::Matrix<int,2,1> vec2i;
20typedef Eigen::Matrix<double,3,1> vec3;
21typedef Eigen::Matrix<int,3,1> vec3i;
22typedef Eigen::Matrix<double,13,1> vec13;
23typedef Eigen::Quaternion<double> quat;
26typedef double iCoordinate;
27typedef double oCoordinate;
31int rayTri(
const vec3 &V1,
const vec3 &V2,
const vec3 &V3,
const vec3 &O,
const vec3 &D,
double &out);
35int SegmentPlane(
const vec3 &S0,
const vec3 &S1,
const vec3 &P0,
const vec3 &PN, vec3 &SPI);
41 bool operator <(
const Point &p)
const {
42 return x < p.x || (x == p.x && y < p.y);
47inline oCoordinate Cross2D(
const Point &O,
const Point &A,
const Point &B)
49 return (A.x - O.x) * (B.y - O.y) - (A.y - O.y) * (B.x - O.x);
53std::vector<Point> ConvexHull(std::vector<Point> P);
57inline double TriangleArea2D(
const vec2 &V0,
const vec2 &V1,
const vec2 &V2)
62 return 0.5*std::abs(V01(0)*V02(1)-V02(0)*V01(1));
67inline double TriangleArea3D(
const vec3 &V0,
const vec3 &V1,
const vec3 &V2)
72 vec3 V012 = V01.cross(V02);
74 return 0.5*sqrt(V012(0)*V012(0)+V012(1)*V012(1)+V012(2)*V012(2));
79inline double PointDistance3D(
const vec3 &PA,
const vec3 &PB)
81 return sqrt((PA(0)-PB(0))*(PA(0)-PB(0))+(PA(1)-PB(1))*(PA(1)-PB(1))+(PA(2)-PB(2))*(PA(2)-PB(2)));
86inline double PointPlaneDis(
const vec3 &V0,
const vec3 &P0,
const vec3 &PN)
89 return VP.dot(PN.normalized());
97 PolyplateSpec(
int &nPolyPoints, std::vector<double> &xPoints, std::vector<double> &yPoints,
double &mThickness,
double &mDensity);
100 void setPolyplate(
int &nPolyPoints, std::vector<double> &xPoints, std::vector<double> &yPoints,
double &mThickness,
double &mDensity);
104 std::vector<double> xCoords;
105 std::vector<double> yCoords;
112 double projectedArea;
123mat3 GetRotation(
const vec3& angle);
124mat6 ReorientInertiaTranslateRotate(
const mat6& Inertia,
const vec6& orientation);
125mat3 MakeDyadic(
const vec3& vector);
134 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
135 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
139 minloc = aabb.minloc;
140 maxloc = aabb.maxloc;
145 void add(
const vec3 &v) {
146 if (v(0) < minloc(0)) minloc(0) = v(0);
147 if (v(1) < minloc(1)) minloc(1) = v(1);
148 if (v(2) < minloc(2)) minloc(2) = v(2);
149 if (v(0) > maxloc(0)) maxloc(0) = v(0);
150 if (v(1) > maxloc(1)) maxloc(1) = v(1);
151 if (v(2) > maxloc(2)) maxloc(2) = v(2);
155 minloc(0) = minloc(1) = minloc(2) = std::numeric_limits<double>::max();
156 maxloc(0) = maxloc(1) = maxloc(2) = -std::numeric_limits<double>::max();
159 int overlap(
const AABB &aabb)
161 if(maxloc(0) < aabb.minloc(0) || minloc(0) > aabb.maxloc(0))
return 0;
162 if(maxloc(1) < aabb.minloc(1) || minloc(1) > aabb.maxloc(1))
return 0;
163 if(maxloc(2) < aabb.minloc(2) || minloc(2) > aabb.maxloc(2))
return 0;
168 double overlapvolume(
const AABB &aabb, vec3 &minol, vec3 &maxol)
170 minol(0) = std::max(minloc(0),aabb.minloc(0));
171 maxol(0) = std::min(maxloc(0),aabb.maxloc(0));
172 minol(1) = std::max(minloc(1),aabb.minloc(1));
173 maxol(1) = std::min(maxloc(1),aabb.maxloc(1));
174 minol(2) = std::max(minloc(2),aabb.minloc(2));
175 maxol(2) = std::min(maxloc(2),aabb.maxloc(2));
177 double volume = std::abs((maxol(0)-minol(0))*(maxol(1)-minol(1))*(maxol(2)-minol(2)));
200 minloc(0) = minloc(1) = std::numeric_limits<double>::max();
201 maxloc(0) = maxloc(1) = -std::numeric_limits<double>::max();
205 minloc = aabb.minloc;
206 maxloc = aabb.maxloc;
211 void add(
const vec2 &v) {
212 if (v(0) < minloc(0)) minloc(0) = v(0);
213 if (v(1) < minloc(1)) minloc(1) = v(1);
214 if (v(0) > maxloc(0)) maxloc(0) = v(0);
215 if (v(1) > maxloc(1)) maxloc(1) = v(1);
219 minloc(0) = minloc(1) = std::numeric_limits<double>::max();
220 maxloc(0) = maxloc(1) = -std::numeric_limits<double>::max();
223 int overlap(
const AABB2D &aabb)
225 if(maxloc(0) < aabb.minloc(0) || minloc(0) > aabb.maxloc(0))
return 0;
226 if(maxloc(1) < aabb.minloc(1) || minloc(1) > aabb.maxloc(1))
return 0;
231 double overlaparea(
const AABB2D &aabb, vec2 &minol, vec2 &maxol)
233 minol(0) = std::max(minloc(0),aabb.minloc(0));
234 maxol(0) = std::min(maxloc(0),aabb.maxloc(0));
235 minol(1) = std::max(minloc(1),aabb.minloc(1));
236 maxol(1) = std::min(maxloc(1),aabb.maxloc(1));
238 double area = std::abs((maxol(0)-minol(0))*(maxol(1)-minol(1)));
281 void newPolyplate(
int &nPolyPoints);
282 void setPolyplate(
int &nPolyPoints,
const PolyplateSpec &iPolyplate, vec3 &iCT, quat &iQuatL2G);
283 vec2i ClosestV(
const Particle &PB,
double &dAB);
284 double DistancePL(
const vec3 &P0,
const vec3 &PN,
int &numCV, std::vector<int> &indexCV);
285 double DistancePL1V(
const vec3 &P0,
const vec3 &PN);
286 int IntersectionPL(
const vec3 &P0,
const vec3 &PN,
int &numInt, std::vector<vec3> &xyzInt,
double &IND);
299 int CalCommonPlane(
Particle &PA,
Particle &PB,
const double &TOL,
const double &TRAN,
const vec3 &P0,
const vec3 &PN, vec3 &CP0, vec3 &CPN);
304double ContactArea(
Particle &PA,
Particle &PB,
const vec3 &P0,
const vec3 &PN,
double &IND, vec3 &CONP);
306double ContactAreaPolyplate(
Particle &PA,
Particle &PB,
const vec3 &P0,
const vec3 &PN,
double &IND, vec3 &CONP);
310inline vec3 QuaternionToAngle(
const quat &QuatL2G)
312 vec3 RollPitchYaw = QuatL2G.toRotationMatrix().eulerAngles(0,1,2);
Definition: Subroutines.h:195
Definition: Subroutines.h:129
Definition: Subroutines.h:291
Definition: Subroutines.h:265
Definition: Subroutines.h:257
Definition: Subroutines.h:185
Definition: Subroutines.h:246
Definition: Subroutines.h:39
Definition: Subroutines.h:94