Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
FloatMath.h
Go to the documentation of this file.
1#pragma once
2
3#include <float.h>
4#include <stdint.h>
5
7{
8namespace FLOAT_MATH
9{
11{
12 FMCS_XMIN = (1 << 0),
13 FMCS_XMAX = (1 << 1),
14 FMCS_YMIN = (1 << 2),
15 FMCS_YMAX = (1 << 3),
16 FMCS_ZMIN = (1 << 4),
17 FMCS_ZMAX = (1 << 5),
18};
19
21{
22 FM_XAXIS = (1 << 0),
23 FM_YAXIS = (1 << 1),
24 FM_ZAXIS = (1 << 2)
25};
26
28{
31 LS_END
32};
33
34const float FM_PI = 3.1415926535897932384626433832795028841971693993751f;
35const float FM_DEG_TO_RAD = ((2.0f * FM_PI) / 360.0f);
36const float FM_RAD_TO_DEG = (360.0f / (2.0f * FM_PI));
37
38//***************** Float versions
39//***
40//*** vectors are assumed to be 3 floats or 3 doubles representing X, Y, Z
41//*** quaternions are assumed to be 4 floats or 4 doubles representing X,Y,Z,W
42//*** matrices are assumed to be 16 floats or 16 doubles representing a standard D3D or OpenGL style 4x4 matrix
43//*** bounding volumes are expressed as two sets of 3 floats/double representing bmin(x,y,z) and bmax(x,y,z)
44//*** Plane equations are assumed to be 4 floats or 4 doubles representing Ax,By,Cz,D
45
48
49void fm_decomposeTransform(const float local_transform[16], float trans[3], float rot[4], float scale[3]);
50void fm_decomposeTransform(const double local_transform[16], double trans[3], double rot[4], double scale[3]);
51
52void fm_multiplyTransform(const float* pA, const float* pB, float* pM);
53void fm_multiplyTransform(const double* pA, const double* pB, double* pM);
54
55void fm_inverseTransform(const float matrix[16], float inverse_matrix[16]);
56void fm_inverseTransform(const double matrix[16], double inverse_matrix[16]);
57
58void fm_identity(float matrix[16]); // set 4x4 matrix to identity.
59void fm_identity(double matrix[16]); // set 4x4 matrix to identity.
60
61void fm_inverseRT(const float matrix[16], const float pos[3], float t[3]); // inverse rotate translate the point.
62void fm_inverseRT(const double matrix[16], const double pos[3], double t[3]); // inverse rotate translate the point.
63
64void fm_transform(const float matrix[16], const float pos[3], float t[3]); // rotate and translate this point.
65void fm_transform(const double matrix[16], const double pos[3], double t[3]); // rotate and translate this point.
66
67float fm_getDeterminant(const float matrix[16]);
68double fm_getDeterminant(const double matrix[16]);
69
70void fm_getSubMatrix(int32_t ki, int32_t kj, float pDst[16], const float matrix[16]);
71void fm_getSubMatrix(int32_t ki, int32_t kj, double pDst[16], const float matrix[16]);
72
73void fm_rotate(const float matrix[16], const float pos[3], float t[3]); // only rotate the point by a 4x4 matrix, don't
74 // translate.
75void fm_rotate(const double matri[16], const double pos[3], double t[3]); // only rotate the point by a 4x4 matrix,
76 // don't translate.
77
78void fm_eulerToMatrix(float ax, float ay, float az, float matrix[16]); // convert euler (in radians) to a dest 4x4
79 // matrix (translation set to zero)
80void fm_eulerToMatrix(double ax, double ay, double az, double matrix[16]); // convert euler (in radians) to a dest 4x4
81 // matrix (translation set to zero)
82
83void fm_getAABB(uint32_t vcount, const float* points, uint32_t pstride, float bmin[3], float bmax[3]);
84void fm_getAABB(uint32_t vcount, const double* points, uint32_t pstride, double bmin[3], double bmax[3]);
85
86void fm_getAABBCenter(const float bmin[3], const float bmax[3], float center[3]);
87void fm_getAABBCenter(const double bmin[3], const double bmax[3], double center[3]);
88
89void fm_transformAABB(const float bmin[3], const float bmax[3], const float matrix[16], float tbmin[3], float tbmax[3]);
90void fm_transformAABB(const double bmin[3],
91 const double bmax[3],
92 const double matrix[16],
93 double tbmin[3],
94 double tbmax[3]);
95
96void fm_eulerToQuat(float x, float y, float z, float quat[4]); // convert euler angles to quaternion.
97void fm_eulerToQuat(double x, double y, double z, double quat[4]); // convert euler angles to quaternion.
98
99void fm_quatToEuler(const float quat[4], float& ax, float& ay, float& az);
100void fm_quatToEuler(const double quat[4], double& ax, double& ay, double& az);
101
102void fm_eulerToQuat(const float euler[3],
103 float quat[4]); // convert euler angles to quaternion. Angles must be radians not degrees!
104void fm_eulerToQuat(const double euler[3], double quat[4]); // convert euler angles to quaternion.
105
106void fm_scale(float x, float y, float z, float matrix[16]); // apply scale to the matrix.
107void fm_scale(double x, double y, double z, double matrix[16]); // apply scale to the matrix.
108
109void fm_eulerToQuatDX(float x, float y, float z, float quat[4]); // convert euler angles to quaternion using the fucked
110 // up DirectX method
111void fm_eulerToQuatDX(double x, double y, double z, double quat[4]); // convert euler angles to quaternion using the
112 // fucked up DirectX method
113
114void fm_eulerToMatrixDX(float x, float y, float z, float matrix[16]); // convert euler angles to quaternion using the
115 // fucked up DirectX method.
116void fm_eulerToMatrixDX(double x, double y, double z, double matrix[16]); // convert euler angles to quaternion using
117 // the fucked up DirectX method.
118
119void fm_quatToMatrix(const float quat[4],
120 float matrix[16]); // convert quaterinion rotation to matrix, translation set to zero.
121void fm_quatToMatrix(const double quat[4],
122 double matrix[16]); // convert quaterinion rotation to matrix, translation set to zero.
123
124void fm_quatRotate(const float quat[4], const float v[3], float r[3]); // rotate a vector directly by a quaternion.
125void fm_quatRotate(const double quat[4], const double v[3], double r[3]); // rotate a vector directly by a quaternion.
126
127void fm_getTranslation(const float matrix[16], float t[3]);
128void fm_getTranslation(const double matrix[16], double t[3]);
129
130void fm_setTranslation(const float* translation, float matrix[16]);
131void fm_setTranslation(const double* translation, double matrix[16]);
132
133void fm_multiplyQuat(const float* qa, const float* qb, float* quat);
134void fm_multiplyQuat(const double* qa, const double* qb, double* quat);
135
136void fm_matrixToQuat(const float matrix[16],
137 float quat[4]); // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w
138void fm_matrixToQuat(const double matrix[16],
139 double quat[4]); // convert the 3x3 portion of a 4x4 matrix into a quaterion as x,y,z,w
140
141float fm_sphereVolume(float radius); // return's the volume of a sphere of this radius (4/3 PI * R cubed )
142double fm_sphereVolume(double radius); // return's the volume of a sphere of this radius (4/3 PI * R cubed )
143
144float fm_cylinderVolume(float radius, float h);
145double fm_cylinderVolume(double radius, double h);
146
147float fm_capsuleVolume(float radius, float h);
148double fm_capsuleVolume(double radius, double h);
149
150float fm_distance(const float p1[3], const float p2[3]);
151double fm_distance(const double p1[3], const double p2[3]);
152
153float fm_distanceSquared(const float p1[3], const float p2[3]);
154double fm_distanceSquared(const double p1[3], const double p2[3]);
155
156float fm_distanceSquaredXZ(const float p1[3], const float p2[3]);
157double fm_distanceSquaredXZ(const double p1[3], const double p2[3]);
158
159float fm_computePlane(const float p1[3], const float p2[3], const float p3[3], float* n); // return D
160double fm_computePlane(const double p1[3], const double p2[3], const double p3[3], double* n); // return D
161
162float fm_distToPlane(const float plane[4], const float pos[3]); // computes the distance of this point from the plane.
163double fm_distToPlane(const double plane[4],
164 const double pos[3]); // computes the distance of this point from the plane.
165
166float fm_dot(const float p1[3], const float p2[3]);
167double fm_dot(const double p1[3], const double p2[3]);
168
169void fm_cross(float cross[3], const float a[3], const float b[3]);
170void fm_cross(double cross[3], const double a[3], const double b[3]);
171
172float fm_computeNormalVector(float n[3], const float p1[3], const float p2[3]); // as P2-P1 normalized.
173double fm_computeNormalVector(double n[3], const double p1[3], const double p2[3]); // as P2-P1 normalized.
174
175bool fm_computeWindingOrder(const float p1[3], const float p2[3], const float p3[3]); // returns true if the triangle
176 // is clockwise.
177bool fm_computeWindingOrder(const double p1[3], const double p2[3], const double p3[3]); // returns true if the
178 // triangle is clockwise.
179
180float fm_normalize(float n[3]); // normalize this vector and return the distance
181double fm_normalize(double n[3]); // normalize this vector and return the distance
182
183float fm_normalizeQuat(float n[4]); // normalize this quat
184double fm_normalizeQuat(double n[4]); // normalize this quat
185
186void fm_matrixMultiply(const float A[16], const float B[16], float dest[16]);
187void fm_matrixMultiply(const double A[16], const double B[16], double dest[16]);
188
189void fm_composeTransform(const float position[3], const float quat[4], const float scale[3], float matrix[16]);
190void fm_composeTransform(const double position[3], const double quat[4], const double scale[3], double matrix[16]);
191
192float fm_computeArea(const float p1[3], const float p2[3], const float p3[3]);
193double fm_computeArea(const double p1[3], const double p2[3], const double p3[3]);
194
195void fm_lerp(const float p1[3], const float p2[3], float dest[3], float lerpValue);
196void fm_lerp(const double p1[3], const double p2[3], double dest[3], double lerpValue);
197
198bool fm_insideTriangleXZ(const float test[3], const float p1[3], const float p2[3], const float p3[3]);
199bool fm_insideTriangleXZ(const double test[3], const double p1[3], const double p2[3], const double p3[3]);
200
201bool fm_insideAABB(const float pos[3], const float bmin[3], const float bmax[3]);
202bool fm_insideAABB(const double pos[3], const double bmin[3], const double bmax[3]);
203
204bool fm_insideAABB(const float obmin[3],
205 const float obmax[3],
206 const float tbmin[3],
207 const float tbmax[3]); // test if bounding box tbmin/tmbax is fully inside obmin/obmax
208bool fm_insideAABB(const double obmin[3],
209 const double obmax[3],
210 const double tbmin[3],
211 const double tbmax[3]); // test if bounding box tbmin/tmbax is fully inside obmin/obmax
212
213uint32_t fm_clipTestPoint(const float bmin[3], const float bmax[3], const float pos[3]);
214uint32_t fm_clipTestPoint(const double bmin[3], const double bmax[3], const double pos[3]);
215
216uint32_t fm_clipTestPointXZ(const float bmin[3], const float bmax[3], const float pos[3]); // only tests X and Z, not Y
217uint32_t fm_clipTestPointXZ(const double bmin[3], const double bmax[3], const double pos[3]); // only tests X and Z,
218 // not Y
219
220uint32_t fm_clipTestAABB(const float bmin[3],
221 const float bmax[3],
222 const float p1[3],
223 const float p2[3],
224 const float p3[3],
225 uint32_t& andCode);
226uint32_t fm_clipTestAABB(const double bmin[3],
227 const double bmax[3],
228 const double p1[3],
229 const double p2[3],
230 const double p3[3],
231 uint32_t& andCode);
232
233bool fm_lineTestAABBXZ(const float p1[3], const float p2[3], const float bmin[3], const float bmax[3], float& time);
234bool fm_lineTestAABBXZ(const double p1[3],
235 const double p2[3],
236 const double bmin[3],
237 const double bmax[3],
238 double& time);
239
240bool fm_lineTestAABB(const float p1[3], const float p2[3], const float bmin[3], const float bmax[3], float& time);
241bool fm_lineTestAABB(const double p1[3], const double p2[3], const double bmin[3], const double bmax[3], double& time);
242
243void fm_initMinMax(const float p[3], float bmin[3], float bmax[3]);
244void fm_initMinMax(const double p[3], double bmin[3], double bmax[3]);
245
246void fm_initMinMax(float bmin[3], float bmax[3]);
247void fm_initMinMax(double bmin[3], double bmax[3]);
248
249void fm_minmax(const float p[3], float bmin[3], float bmax[3]); // accumulate to a min-max value
250void fm_minmax(const double p[3], double bmin[3], double bmax[3]); // accumulate to a min-max value
251
252// Computes the diagonal length of the bounding box and then inflates the bounding box on all sides
253// by the ratio provided.
254void fm_inflateMinMax(float bmin[3], float bmax[3], float ratio);
255void fm_inflateMinMax(double bmin[3], double bmax[3], double ratio);
256
257float fm_solveX(const float plane[4], float y, float z); // solve for X given this plane equation and the other two
258 // components.
259double fm_solveX(const double plane[4], double y, double z); // solve for X given this plane equation and the other two
260 // components.
261
262float fm_solveY(const float plane[4], float x, float z); // solve for Y given this plane equation and the other two
263 // components.
264double fm_solveY(const double plane[4], double x, double z); // solve for Y given this plane equation and the other two
265 // components.
266
267float fm_solveZ(const float plane[4], float x, float y); // solve for Z given this plane equation and the other two
268 // components.
269double fm_solveZ(const double plane[4], double x, double y); // solve for Z given this plane equation and the other two
270 // components.
271
272bool fm_computeBestFitPlane(uint32_t vcount, // number of input data points
273 const float* points, // starting address of points array.
274 uint32_t vstride, // stride between input points.
275 const float* weights, // *optional point weighting values.
276 uint32_t wstride, // weight stride for each vertex.
277 float plane[4], // Best fit plane equation
278 float center[3]); // Best fit weighted center of input points
279
280bool fm_computeBestFitPlane(uint32_t vcount, // number of input data points
281 const double* points, // starting address of points array.
282 uint32_t vstride, // stride between input points.
283 const double* weights, // *optional point weighting values.
284 uint32_t wstride, // weight stride for each vertex.
285 double plane[4],
286 double center[3]);
287
288// Computes the average center of a set of data points
289bool fm_computeCentroid(uint32_t vcount, // number of input data points
290 const float* points, // starting address of points array.
291 float* center);
292
293bool fm_computeCentroid(uint32_t vcount, // number of input data points
294 const double* points, // starting address of points array.
295 double* center);
296
297// Compute centroid of a triangle mesh; takes area of each triangle into account
298// weighted average
299bool fm_computeCentroid(uint32_t vcount, // number of input data points
300 const float* points, // starting address of points array.
301 uint32_t triangleCount,
302 const uint32_t* indices,
303 float* center);
304
305// Compute centroid of a triangle mesh; takes area of each triangle into account
306// weighted average
307bool fm_computeCentroid(uint32_t vcount, // number of input data points
308 const double* points, // starting address of points array.
309 uint32_t triangleCount,
310 const uint32_t* indices,
311 double* center);
312
313float fm_computeBestFitAABB(uint32_t vcount,
314 const float* points,
315 uint32_t pstride,
316 float bmin[3],
317 float bmax[3]); // returns the diagonal distance
318double fm_computeBestFitAABB(uint32_t vcount,
319 const double* points,
320 uint32_t pstride,
321 double bmin[3],
322 double bmax[3]); // returns the diagonal distance
323
324float fm_computeBestFitSphere(uint32_t vcount, const float* points, uint32_t pstride, float center[3]);
325double fm_computeBestFitSphere(uint32_t vcount, const double* points, uint32_t pstride, double center[3]);
326
327bool fm_lineSphereIntersect(const float center[3],
328 float radius,
329 const float p1[3],
330 const float p2[3],
331 float intersect[3]);
332bool fm_lineSphereIntersect(const double center[3],
333 double radius,
334 const double p1[3],
335 const double p2[3],
336 double intersect[3]);
337
338bool fm_intersectRayAABB(const float bmin[3],
339 const float bmax[3],
340 const float pos[3],
341 const float dir[3],
342 float intersect[3]);
343bool fm_intersectLineSegmentAABB(const float bmin[3],
344 const float bmax[3],
345 const float p1[3],
346 const float p2[3],
347 float intersect[3]);
348
349bool fm_lineIntersectsTriangle(const float rayStart[3],
350 const float rayEnd[3],
351 const float p1[3],
352 const float p2[3],
353 const float p3[3],
354 float sect[3]);
355bool fm_lineIntersectsTriangle(const double rayStart[3],
356 const double rayEnd[3],
357 const double p1[3],
358 const double p2[3],
359 const double p3[3],
360 double sect[3]);
361
362bool fm_rayIntersectsTriangle(const float origin[3],
363 const float dir[3],
364 const float v0[3],
365 const float v1[3],
366 const float v2[3],
367 float& t);
368bool fm_rayIntersectsTriangle(const double origin[3],
369 const double dir[3],
370 const double v0[3],
371 const double v1[3],
372 const double v2[3],
373 double& t);
374
375bool fm_raySphereIntersect(const float center[3],
376 float radius,
377 const float pos[3],
378 const float dir[3],
379 float distance,
380 float intersect[3]);
381bool fm_raySphereIntersect(const double center[3],
382 double radius,
383 const double pos[3],
384 const double dir[3],
385 double distance,
386 double intersect[3]);
387
388void fm_catmullRom(float out_vector[3],
389 const float p1[3],
390 const float p2[3],
391 const float p3[3],
392 const float* p4,
393 const float s);
394void fm_catmullRom(double out_vector[3],
395 const double p1[3],
396 const double p2[3],
397 const double p3[3],
398 const double* p4,
399 const double s);
400
401bool fm_intersectAABB(const float bmin1[3], const float bmax1[3], const float bmin2[3], const float bmax2[3]);
402bool fm_intersectAABB(const double bmin1[3], const double bmax1[3], const double bmin2[3], const double bmax2[3]);
403
404// computes the rotation quaternion to go from unit-vector v0 to unit-vector v1
405void fm_rotationArc(const float v0[3], const float v1[3], float quat[4]);
406void fm_rotationArc(const double v0[3], const double v1[3], double quat[4]);
407
408float fm_distancePointLineSegment(const float Point[3],
409 const float LineStart[3],
410 const float LineEnd[3],
411 float intersection[3],
413 float epsilon);
414double fm_distancePointLineSegment(const double Point[3],
415 const double LineStart[3],
416 const double LineEnd[3],
417 double intersection[3],
419 double epsilon);
420
421bool fm_colinear(const double p1[3], const double p2[3], const double p3[3], double epsilon = 0.999); // true if these
422 // three points
423 // in a row are
424 // co-linear
425bool fm_colinear(const float p1[3], const float p2[3], const float p3[3], float epsilon = 0.999f);
426
427bool fm_colinear(const float a1[3],
428 const float a2[3],
429 const float b1[3],
430 const float b2[3],
431 float epsilon = 0.999f); // true if these two line segments are co-linear.
432bool fm_colinear(const double a1[3],
433 const double a2[3],
434 const double b1[3],
435 const double b2[3],
436 double epsilon = 0.999); // true if these two line segments are co-linear.
437
439{
444};
445
447 const float a2[3],
448 const float b1[3],
449 const float b2[3],
450 float intersectionPoint[3]);
452 const double a2[3],
453 const double b1[3],
454 const double b2[3],
455 double intersectionPoint[3]);
456
458 const float a2[3],
459 const float b1[3],
460 const float b2[3],
461 float& t1,
462 float& t2);
464 const double a2[3],
465 const double b1[3],
466 const double b2[3],
467 double& t1,
468 double& t2);
469
470// Plane-Triangle splitting
471
473{
478};
479
480PlaneTriResult fm_planeTriIntersection(const float plane[4], // the plane equation in Ax+By+Cz+D format
481 const float* triangle, // the source triangle.
482 uint32_t tstride, // stride in bytes of the input and output *vertices*
483 float epsilon, // the co-planer epsilon value.
484 float* front, // the triangle in front of the
485 uint32_t& fcount, // number of vertices in the 'front' triangle
486 float* back, // the triangle in back of the plane
487 uint32_t& bcount); // the number of vertices in the 'back' triangle.
488
489PlaneTriResult fm_planeTriIntersection(const double plane[4], // the plane equation in Ax+By+Cz+D format
490 const double* triangle, // the source triangle.
491 uint32_t tstride, // stride in bytes of the input and output *vertices*
492 double epsilon, // the co-planer epsilon value.
493 double* front, // the triangle in front of the
494 uint32_t& fcount, // number of vertices in the 'front' triangle
495 double* back, // the triangle in back of the plane
496 uint32_t& bcount); // the number of vertices in the 'back' triangle.
497
498bool fm_intersectPointPlane(const float p1[3], const float p2[3], float* split, const float plane[4]);
499bool fm_intersectPointPlane(const double p1[3], const double p2[3], double* split, const double plane[4]);
500
501PlaneTriResult fm_getSidePlane(const float p[3], const float plane[4], float epsilon);
502PlaneTriResult fm_getSidePlane(const double p[3], const double plane[4], double epsilon);
503
504void fm_computeBestFitOBB(uint32_t vcount,
505 const float* points,
506 uint32_t pstride,
507 float* sides,
508 float matrix[16],
509 bool bruteForce = true);
510void fm_computeBestFitOBB(uint32_t vcount,
511 const double* points,
512 uint32_t pstride,
513 double* sides,
514 double matrix[16],
515 bool bruteForce = true);
516
517void fm_computeBestFitOBB(uint32_t vcount,
518 const float* points,
519 uint32_t pstride,
520 float* sides,
521 float pos[3],
522 float quat[4],
523 bool bruteForce = true);
524void fm_computeBestFitOBB(uint32_t vcount,
525 const double* points,
526 uint32_t pstride,
527 double* sides,
528 double pos[3],
529 double quat[4],
530 bool bruteForce = true);
531
532void fm_computeBestFitABB(uint32_t vcount, const float* points, uint32_t pstride, float* sides, float pos[3]);
533void fm_computeBestFitABB(uint32_t vcount, const double* points, uint32_t pstride, double* sides, double pos[3]);
534
535//** Note, if the returned capsule height is less than zero, then you must represent it is a sphere of size radius.
536void fm_computeBestFitCapsule(uint32_t vcount,
537 const float* points,
538 uint32_t pstride,
539 float& radius,
540 float& height,
541 float matrix[16],
542 bool bruteForce = true);
543void fm_computeBestFitCapsule(uint32_t vcount,
544 const double* points,
545 uint32_t pstride,
546 float& radius,
547 float& height,
548 double matrix[16],
549 bool bruteForce = true);
550
551void fm_planeToMatrix(const float plane[4], float matrix[16]); // convert a plane equation to a 4x4 rotation matrix.
552 // Reference vector is 0,1,0
553void fm_planeToQuat(const float plane[4], float quat[4], float pos[3]); // convert a plane equation to a quaternion and
554 // translation
555
556void fm_planeToMatrix(const double plane[4], double matrix[16]); // convert a plane equation to a 4x4 rotation matrix
557void fm_planeToQuat(const double plane[4], double quat[4], double pos[3]); // convert a plane equation to a quaternion
558 // and translation
559
560inline void fm_doubleToFloat3(const double p[3], float t[3])
561{
562 t[0] = (float)p[0];
563 t[1] = (float)p[1];
564 t[2] = (float)p[2];
565};
566inline void fm_floatToDouble3(const float p[3], double t[3])
567{
568 t[0] = (double)p[0];
569 t[1] = (double)p[1];
570 t[2] = (double)p[2];
571};
572
573void fm_eulerMatrix(float ax, float ay, float az, float matrix[16]); // convert euler (in radians) to a dest 4x4 matrix
574 // (translation set to zero)
575void fm_eulerMatrix(double ax, double ay, double az, double matrix[16]); // convert euler (in radians) to a dest 4x4
576 // matrix (translation set to zero)
577
578float fm_computeMeshVolume(const float* vertices, uint32_t tcount, const uint32_t* indices);
579double fm_computeMeshVolume(const double* vertices, uint32_t tcount, const uint32_t* indices);
580
581#define FM_DEFAULT_GRANULARITY 0.001f // 1 millimeter is the default granularity
582
584{
585public:
586 virtual ~fm_VertexIndex() = default;
587 virtual uint32_t getIndex(const float pos[3], bool& newPos) = 0; // get welded index for this float vector[3]
588 virtual uint32_t getIndex(const double pos[3], bool& newPos) = 0; // get welded index for this double vector[3]
589 virtual const float* getVerticesFloat(void) const = 0;
590 virtual const double* getVerticesDouble(void) const = 0;
591 virtual const float* getVertexFloat(uint32_t index) const = 0;
592 virtual const double* getVertexDouble(uint32_t index) const = 0;
593 virtual uint32_t getVcount(void) const = 0;
594 virtual bool isDouble(void) const = 0;
595 virtual bool saveAsObj(const char* fname, uint32_t tcount, uint32_t* indices) = 0;
596};
597
598fm_VertexIndex* fm_createVertexIndex(double granularity,
599 bool snapToGrid); // create an indexed vertex system for doubles
600fm_VertexIndex* fm_createVertexIndex(float granularity,
601 bool snapToGrid); // create an indexed vertext system for floats
603
605{
606public:
607 virtual ~fm_Triangulate() = default;
608 virtual const double* triangulate3d(uint32_t pcount,
609 const double* points,
610 uint32_t vstride,
611 uint32_t& tcount,
612 bool consolidate,
613 double epsilon) = 0;
614
615 virtual const float* triangulate3d(uint32_t pcount,
616 const float* points,
617 uint32_t vstride,
618 uint32_t& tcount,
619 bool consolidate,
620 float epsilon) = 0;
621};
622
625
626const float* fm_getPoint(const float* points, uint32_t pstride, uint32_t index);
627const double* fm_getPoint(const double* points, uint32_t pstride, uint32_t index);
628
629bool fm_insideTriangle(float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py);
630bool fm_insideTriangle(double Ax, double Ay, double Bx, double By, double Cx, double Cy, double Px, double Py);
631float fm_areaPolygon2d(uint32_t pcount, const float* points, uint32_t pstride);
632double fm_areaPolygon2d(uint32_t pcount, const double* points, uint32_t pstride);
633
634bool fm_pointInsidePolygon2d(uint32_t pcount,
635 const float* points,
636 uint32_t pstride,
637 const float* point,
638 uint32_t xindex = 0,
639 uint32_t yindex = 1);
640bool fm_pointInsidePolygon2d(uint32_t pcount,
641 const double* points,
642 uint32_t pstride,
643 const double* point,
644 uint32_t xindex = 0,
645 uint32_t yindex = 1);
646
647uint32_t fm_consolidatePolygon(uint32_t pcount,
648 const float* points,
649 uint32_t pstride,
650 float* dest,
651 float epsilon = 0.999999f); // collapses co-linear edges.
652uint32_t fm_consolidatePolygon(uint32_t pcount,
653 const double* points,
654 uint32_t pstride,
655 double* dest,
656 double epsilon = 0.999999); // collapses co-linear edges.
657
658bool fm_computeSplitPlane(uint32_t vcount,
659 const double* vertices,
660 uint32_t tcount,
661 const uint32_t* indices,
662 double* plane);
663bool fm_computeSplitPlane(uint32_t vcount,
664 const float* vertices,
665 uint32_t tcount,
666 const uint32_t* indices,
667 float* plane);
668
669void fm_nearestPointInTriangle(const float* pos, const float* p1, const float* p2, const float* p3, float* nearest);
670void fm_nearestPointInTriangle(const double* pos,
671 const double* p1,
672 const double* p2,
673 const double* p3,
674 double* nearest);
675
676float fm_areaTriangle(const float* p1, const float* p2, const float* p3);
677double fm_areaTriangle(const double* p1, const double* p2, const double* p3);
678
679void fm_subtract(const float* A, const float* B, float* diff); // compute A-B and store the result in 'diff'
680void fm_subtract(const double* A, const double* B, double* diff); // compute A-B and store the result in 'diff'
681
682void fm_multiply(float* A, float scaler);
683void fm_multiply(double* A, double scaler);
684
685void fm_add(const float* A, const float* B, float* sum);
686void fm_add(const double* A, const double* B, double* sum);
687
688void fm_copy3(const float* source, float* dest);
689void fm_copy3(const double* source, double* dest);
690
691// re-indexes an indexed triangle mesh but drops unused vertices. The output_indices can be the same pointer as the
692// input indices.
693// the output_vertices can point to the input vertices if you desire. The output_vertices buffer should be at least the
694// same size
695// is the input buffer. The routine returns the new vertex count after re-indexing.
696uint32_t fm_copyUniqueVertices(uint32_t vcount,
697 const float* input_vertices,
698 float* output_vertices,
699 uint32_t tcount,
700 const uint32_t* input_indices,
701 uint32_t* output_indices);
702uint32_t fm_copyUniqueVertices(uint32_t vcount,
703 const double* input_vertices,
704 double* output_vertices,
705 uint32_t tcount,
706 const uint32_t* input_indices,
707 uint32_t* output_indices);
708
709bool fm_isMeshCoplanar(uint32_t tcount,
710 const uint32_t* indices,
711 const float* vertices,
712 bool doubleSided); // returns true if this collection of indexed triangles are co-planar!
713bool fm_isMeshCoplanar(uint32_t tcount,
714 const uint32_t* indices,
715 const double* vertices,
716 bool doubleSided); // returns true if this collection of indexed triangles are co-planar!
717
718bool fm_samePlane(const float p1[4],
719 const float p2[4],
720 float normalEpsilon = 0.01f,
721 float dEpsilon = 0.001f,
722 bool doubleSided = false); // returns true if these two plane equations are identical within an
723 // epsilon
724bool fm_samePlane(const double p1[4],
725 const double p2[4],
726 double normalEpsilon = 0.01,
727 double dEpsilon = 0.001,
728 bool doubleSided = false);
729
730void fm_OBBtoAABB(const float obmin[3], const float obmax[3], const float matrix[16], float abmin[3], float abmax[3]);
731
732// a utility class that will tessellate a mesh.
734{
735public:
736 virtual ~fm_Tesselate() = default;
737 virtual const uint32_t* tesselate(fm_VertexIndex* vindex,
738 uint32_t tcount,
739 const uint32_t* indices,
740 float longEdge,
741 uint32_t maxDepth,
742 uint32_t& outcount) = 0;
743};
744
747
748void fm_computeMeanNormals(uint32_t vcount, // the number of vertices
749 const float* vertices, // the base address of the vertex position data.
750 uint32_t vstride, // the stride between position data.
751 float* normals, // the base address of the destination for mean vector normals
752 uint32_t nstride, // the stride between normals
753 uint32_t tcount, // the number of triangles
754 const uint32_t* indices); // the triangle indices
755
756void fm_computeMeanNormals(uint32_t vcount, // the number of vertices
757 const double* vertices, // the base address of the vertex position data.
758 uint32_t vstride, // the stride between position data.
759 double* normals, // the base address of the destination for mean vector normals
760 uint32_t nstride, // the stride between normals
761 uint32_t tcount, // the number of triangles
762 const uint32_t* indices); // the triangle indices
763
764bool fm_isValidTriangle(const float* p1, const float* p2, const float* p3, float epsilon = 0.00001f);
765bool fm_isValidTriangle(const double* p1, const double* p2, const double* p3, double epsilon = 0.00001);
766
767} // namespace FLOAT_MATH
768} // namespace tesseract_collision
virtual const uint32_t * tesselate(fm_VertexIndex *vindex, uint32_t tcount, const uint32_t *indices, float longEdge, uint32_t maxDepth, uint32_t &outcount)=0
virtual const float * triangulate3d(uint32_t pcount, const float *points, uint32_t vstride, uint32_t &tcount, bool consolidate, float epsilon)=0
virtual const double * triangulate3d(uint32_t pcount, const double *points, uint32_t vstride, uint32_t &tcount, bool consolidate, double epsilon)=0
virtual bool saveAsObj(const char *fname, uint32_t tcount, uint32_t *indices)=0
virtual const double * getVertexDouble(uint32_t index) const =0
virtual uint32_t getIndex(const float pos[3], bool &newPos)=0
virtual const float * getVerticesFloat(void) const =0
virtual uint32_t getVcount(void) const =0
virtual const float * getVertexFloat(uint32_t index) const =0
virtual uint32_t getIndex(const double pos[3], bool &newPos)=0
virtual const double * getVerticesDouble(void) const =0
Definition: FloatMath.inl:1849
Definition: FloatMath.inl:1833
results distance
Definition: collision_core_unit.cpp:139
results normal
Definition: collision_core_unit.cpp:154
double scale
Definition: collision_margin_data_unit.cpp:133
float fm_sphereVolume(float radius)
uint32_t fm_clipTestPoint(const float bmin[3], const float bmax[3], const float pos[3])
void fm_subtract(const float *A, const float *B, float *diff)
fm_Tesselate * fm_createTesselate(void)
Definition: FloatMath.inl:4102
void fm_releaseTesselate(fm_Tesselate *t)
Definition: FloatMath.inl:4108
bool fm_computeWindingOrder(const float p1[3], const float p2[3], const float p3[3])
void fm_quatToMatrix(const float quat[4], float matrix[16])
void fm_multiply(float *A, float scaler)
float fm_distanceSquaredXZ(const float p1[3], const float p2[3])
fm_Triangulate * fm_createTriangulate(void)
Definition: FloatMath.inl:5004
IntersectResult
Definition: FloatMath.h:439
@ IR_DO_INTERSECT
Definition: FloatMath.h:441
@ IR_PARALLEL
Definition: FloatMath.h:443
@ IR_DONT_INTERSECT
Definition: FloatMath.h:440
@ IR_COINCIDENT
Definition: FloatMath.h:442
bool fm_raySphereIntersect(const float center[3], float radius, const float pos[3], const float dir[3], float distance, float intersect[3])
float fm_computeMeshVolume(const float *vertices, uint32_t tcount, const uint32_t *indices)
bool fm_isValidTriangle(const float *p1, const float *p2, const float *p3, float epsilon=0.00001f)
void fm_decomposeTransform(const float local_transform[16], float trans[3], float rot[4], float scale[3])
void fm_setTranslation(const float *translation, float matrix[16])
void fm_inflateMinMax(float bmin[3], float bmax[3], float ratio)
void fm_doubleToFloat3(const double p[3], float t[3])
Definition: FloatMath.h:560
void fm_getAABB(uint32_t vcount, const float *points, uint32_t pstride, float bmin[3], float bmax[3])
void fm_getAABBCenter(const float bmin[3], const float bmax[3], float center[3])
bool fm_lineTestAABB(const float p1[3], const float p2[3], const float bmin[3], const float bmax[3], float &time)
void fm_inverseTransform(const float matrix[16], float inverse_matrix[16])
void fm_quatRotate(const float quat[4], const float v[3], float r[3])
void fm_matrixToQuat(const float matrix[16], float quat[4])
const float FM_PI
Definition: FloatMath.h:34
void fm_planeToMatrix(const float plane[4], float matrix[16])
float fm_capsuleVolume(float radius, float h)
float fm_solveZ(const float plane[4], float x, float y)
void fm_matrixMultiply(const float A[16], const float B[16], float dest[16])
const float FM_DEG_TO_RAD
Definition: FloatMath.h:35
void fm_multiplyTransform(const float *pA, const float *pB, float *pM)
float fm_computeNormalVector(float n[3], const float p1[3], const float p2[3])
void fm_add(const float *A, const float *B, float *sum)
void fm_composeTransform(const float position[3], const float quat[4], const float scale[3], float matrix[16])
void fm_eulerToQuatDX(float x, float y, float z, float quat[4])
uint32_t fm_clipTestAABB(const float bmin[3], const float bmax[3], const float p1[3], const float p2[3], const float p3[3], uint32_t &andCode)
float fm_dot(const float p1[3], const float p2[3])
FM_ClipState
Definition: FloatMath.h:11
@ FMCS_XMIN
Definition: FloatMath.h:12
@ FMCS_XMAX
Definition: FloatMath.h:13
@ FMCS_YMIN
Definition: FloatMath.h:14
@ FMCS_YMAX
Definition: FloatMath.h:15
@ FMCS_ZMAX
Definition: FloatMath.h:17
@ FMCS_ZMIN
Definition: FloatMath.h:16
FM_Axis
Definition: FloatMath.h:21
@ FM_YAXIS
Definition: FloatMath.h:23
@ FM_ZAXIS
Definition: FloatMath.h:24
@ FM_XAXIS
Definition: FloatMath.h:22
fm_VertexIndex * fm_createVertexIndex(double granularity, bool snapToGrid)
Definition: FloatMath.inl:3168
float fm_normalize(float n[3])
float fm_areaTriangle(const float *p1, const float *p2, const float *p3)
void fm_quatToEuler(const float quat[4], float &ax, float &ay, float &az)
void fm_eulerToMatrix(float ax, float ay, float az, float matrix[16])
void fm_rotate(const float matrix[16], const float pos[3], float t[3])
bool fm_isMeshCoplanar(uint32_t tcount, const uint32_t *indices, const float *vertices, bool doubleSided)
void fm_cross(float cross[3], const float a[3], const float b[3])
float fm_computeBestFitSphere(uint32_t vcount, const float *points, uint32_t pstride, float center[3])
uint32_t fm_clipTestPointXZ(const float bmin[3], const float bmax[3], const float pos[3])
bool fm_insideAABB(const float pos[3], const float bmin[3], const float bmax[3])
float fm_solveY(const float plane[4], float x, float z)
float fm_normalizeQuat(float n[4])
void fm_releaseVertexIndex(fm_VertexIndex *vindex)
Definition: FloatMath.inl:3180
bool fm_rayIntersectsTriangle(const float origin[3], const float dir[3], const float v0[3], const float v1[3], const float v2[3], float &t)
void fm_inverseRT(const float matrix[16], const float pos[3], float t[3])
float fm_cylinderVolume(float radius, float h)
void fm_nearestPointInTriangle(const float *pos, const float *p1, const float *p2, const float *p3, float *nearest)
float fm_distToPlane(const float plane[4], const float pos[3])
PlaneTriResult fm_planeTriIntersection(const float plane[4], const float *triangle, uint32_t tstride, float epsilon, float *front, uint32_t &fcount, float *back, uint32_t &bcount)
void fm_lerp(const float p1[3], const float p2[3], float dest[3], float lerpValue)
uint32_t fm_consolidatePolygon(uint32_t pcount, const float *points, uint32_t pstride, float *dest, float epsilon=0.999999f)
void fm_releaseTriangulate(fm_Triangulate *t)
Definition: FloatMath.inl:5010
void fm_getSubMatrix(int32_t ki, int32_t kj, float pDst[16], const float matrix[16])
void fm_copy3(const float *source, float *dest)
bool fm_intersectAABB(const float bmin1[3], const float bmax1[3], const float bmin2[3], const float bmax2[3])
PlaneTriResult
Definition: FloatMath.h:473
@ PTR_FRONT
Definition: FloatMath.h:475
@ PTR_ON_PLANE
Definition: FloatMath.h:474
@ PTR_BACK
Definition: FloatMath.h:476
@ PTR_SPLIT
Definition: FloatMath.h:477
bool fm_intersectRayAABB(const float bmin[3], const float bmax[3], const float pos[3], const float dir[3], float intersect[3])
Definition: FloatMath.inl:4144
bool fm_computeSplitPlane(uint32_t vcount, const double *vertices, uint32_t tcount, const uint32_t *indices, double *plane)
void fm_minmax(const float p[3], float bmin[3], float bmax[3])
void fm_eulerMatrix(float ax, float ay, float az, float matrix[16])
PlaneTriResult fm_getSidePlane(const float p[3], const float plane[4], float epsilon)
float fm_computeArea(const float p1[3], const float p2[3], const float p3[3])
IntersectResult fm_intersectLineSegments2d(const float a1[3], const float a2[3], const float b1[3], const float b2[3], float intersectionPoint[3])
void fm_OBBtoAABB(const float obmin[3], const float obmax[3], const float matrix[16], float abmin[3], float abmax[3])
Definition: FloatMath.inl:4231
void fm_catmullRom(float out_vector[3], const float p1[3], const float p2[3], const float p3[3], const float *p4, const float s)
bool fm_lineSphereIntersect(const float center[3], float radius, const float p1[3], const float p2[3], float intersect[3])
bool fm_pointInsidePolygon2d(uint32_t pcount, const float *points, uint32_t pstride, const float *point, uint32_t xindex=0, uint32_t yindex=1)
void fm_getTranslation(const float matrix[16], float t[3])
void fm_scale(float x, float y, float z, float matrix[16])
float fm_distancePointLineSegment(const float Point[3], const float LineStart[3], const float LineEnd[3], float intersection[3], LineSegmentType &type, float epsilon)
void fm_multiplyQuat(const float *qa, const float *qb, float *quat)
void fm_floatToDouble3(const float p[3], double t[3])
Definition: FloatMath.h:566
void fm_initMinMax(const float p[3], float bmin[3], float bmax[3])
float fm_solveX(const float plane[4], float y, float z)
void fm_rotationArc(const float v0[3], const float v1[3], float quat[4])
void fm_identity(float matrix[16])
float fm_computePlane(const float p1[3], const float p2[3], const float p3[3], float *n)
float fm_areaPolygon2d(uint32_t pcount, const float *points, uint32_t pstride)
bool fm_insideTriangle(float Ax, float Ay, float Bx, float By, float Cx, float Cy, float Px, float Py)
void fm_eulerToQuat(float x, float y, float z, float quat[4])
bool fm_intersectLineSegmentAABB(const float bmin[3], const float bmax[3], const float p1[3], const float p2[3], float intersect[3])
Definition: FloatMath.inl:4203
void fm_transform(const float matrix[16], const float pos[3], float t[3])
bool fm_lineTestAABBXZ(const float p1[3], const float p2[3], const float bmin[3], const float bmax[3], float &time)
void fm_planeToQuat(const float plane[4], float quat[4], float pos[3])
bool fm_colinear(const double p1[3], const double p2[3], const double p3[3], double epsilon=0.999)
void fm_computeBestFitOBB(uint32_t vcount, const float *points, uint32_t pstride, float *sides, float matrix[16], bool bruteForce=true)
bool fm_lineIntersectsTriangle(const float rayStart[3], const float rayEnd[3], const float p1[3], const float p2[3], const float p3[3], float sect[3])
IntersectResult fm_intersectLineSegments2dTime(const float a1[3], const float a2[3], const float b1[3], const float b2[3], float &t1, float &t2)
void fm_computeBestFitCapsule(uint32_t vcount, const float *points, uint32_t pstride, float &radius, float &height, float matrix[16], bool bruteForce=true)
FM_Axis fm_getDominantAxis(const float normal[3])
float fm_distanceSquared(const float p1[3], const float p2[3])
void fm_eulerToMatrixDX(float x, float y, float z, float matrix[16])
const float FM_RAD_TO_DEG
Definition: FloatMath.h:36
void fm_computeMeanNormals(uint32_t vcount, const float *vertices, uint32_t vstride, float *normals, uint32_t nstride, uint32_t tcount, const uint32_t *indices)
bool fm_computeBestFitPlane(uint32_t vcount, const float *points, uint32_t vstride, const float *weights, uint32_t wstride, float plane[4], float center[3])
bool fm_samePlane(const float p1[4], const float p2[4], float normalEpsilon=0.01f, float dEpsilon=0.001f, bool doubleSided=false)
float fm_getDeterminant(const float matrix[16])
void fm_computeBestFitABB(uint32_t vcount, const float *points, uint32_t pstride, float *sides, float pos[3])
void fm_transformAABB(const float bmin[3], const float bmax[3], const float matrix[16], float tbmin[3], float tbmax[3])
LineSegmentType
Definition: FloatMath.h:28
@ LS_MIDDLE
Definition: FloatMath.h:30
@ LS_START
Definition: FloatMath.h:29
@ LS_END
Definition: FloatMath.h:31
float fm_distance(const float p1[3], const float p2[3])
bool fm_computeCentroid(uint32_t vcount, const float *points, float *center)
uint32_t fm_copyUniqueVertices(uint32_t vcount, const float *input_vertices, float *output_vertices, uint32_t tcount, const uint32_t *input_indices, uint32_t *output_indices)
bool fm_insideTriangleXZ(const float test[3], const float p1[3], const float p2[3], const float p3[3])
bool intersect(const REAL *si, const REAL *ei, const REAL *bmin, const REAL *bmax, REAL *time)
Definition: FloatMath.inl:908
bool fm_intersectPointPlane(const float p1[3], const float p2[3], float *split, const float plane[4])
const float * fm_getPoint(const float *points, uint32_t pstride, uint32_t index)
float fm_computeBestFitAABB(uint32_t vcount, const float *points, uint32_t pstride, float bmin[3], float bmax[3])
Definition: bullet_cast_bvh_manager.h:49
std::set< std::string > s
Definition: plugin_loader_unit.cpp:45
joint_state time
Definition: tesseract_common_serialization_unit.cpp:80
joint_state position
Definition: tesseract_common_serialization_unit.cpp:76
std::vector< std::string > v2
Definition: tesseract_common_unit.cpp:418
v1["1"]
Definition: tesseract_common_unit.cpp:434
v
Definition: tesseract_common_unit.cpp:369
mCollisionCheckConfig contact_request type
Definition: tesseract_environment_collision.cpp:103
pose translation()