PeriDyno 1.0.0
Loading...
Searching...
No Matches
ComputeGeometry.h
Go to the documentation of this file.
1
16
17#pragma once
18#include "Platform.h"
19
20#include "Matrix.h"
21#include "Vector/Vector3D.h"
22#include "Vector.h"
23
24namespace dyno
25{
26 // Refer to https://www.geometrictools.com/index.html
27 namespace cgeo
28 {
29 template<typename T>
30 inline DYN_FUNC void Swap(T& a, T& b);
31
32 inline DYN_FUNC float Dot(Vec3f const& U, Vec3f const& V);
33 inline DYN_FUNC float Dot(Vec2f const& U, Vec2f const& V);
34 inline DYN_FUNC Vec2f Perp(Vec2f const& v);
35 inline DYN_FUNC float DotPerp(Vec2f const& v0, Vec2f const& v1);
36 // U x V
37 inline DYN_FUNC Vec3f Cross(Vec3f const& U, Vec3f const& V);
38 // U (V x W)
39 inline DYN_FUNC float DotCross(Vec3f const& U, Vec3f const& V, Vec3f const& W);
40 inline DYN_FUNC bool isOverLap(float& c0, float& c1, float a0, float a1, float b0, float b1);
41 inline DYN_FUNC bool Sign(Vec3f const& n, Vec3f const& p0, Vec3f const& p1, Vec3f const& p2);
42
43 inline DYN_FUNC Vec3f getProjectionVF(Vec3f p,
44 Vec3f a0, Vec3f a1, Vec3f a2);
45
46 inline DYN_FUNC Vec3f getDirectionVF(Vec3f p,
47 Vec3f a0, Vec3f a1, Vec3f a2);
48
49 inline DYN_FUNC float getDistanceVF(Vec3f p,
50 Vec3f a0, Vec3f a1, Vec3f a2);
51
52 inline DYN_FUNC bool isInNarrowBand(Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3,
53 Vec3f a0, Vec3f a1, Vec3f a2, float d);
54
55 // Test for intersection of two Convex Polygon in 2D. (2D Separating Axis)
56 inline DYN_FUNC bool isConPolyOverLap2D(Vec3f face_n, int n_a, Vec3f* a,
57 int n_b, Vec3f* b);
58
59 // Test for intersection of a triangle and a tetrahedron.
60 inline DYN_FUNC bool isIntrTri2Tet(Vec3f a0, Vec3f a1, Vec3f a2,
61 Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
62
63 // Test for intersection of a triangle and a tetrahedron that have a shared vertex.
64 inline DYN_FUNC bool isIntrTri2Tet(Vec3f a0, Vec3f a1, Vec3f a2,
65 Vec3f b1, Vec3f b2, Vec3f b3); // b0 = a0
66
67 // Test for containment of a point by a tetrahedron.
68 inline DYN_FUNC bool isInTet(Vec3f p,
69 Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
70
71 // get the box area(approx) of intersection of two Convex Polygon in 2D
72 inline DYN_FUNC float getOverLapBoxAreaInPoly2D(Vec3f face_n, int n_a, Vec3f* a,
73 int n_b, Vec3f* b);
74
75 // get the box area(approx) of a triangle in a tetrahedron
76 inline DYN_FUNC float getTriBoxAreaInTet(Vec3f a0, Vec3f a1, Vec3f a2,
77 Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
78
79 // Volume for tetrahedron(b0 b1 b2 b3)
80 inline DYN_FUNC float getVolume(Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
81
82 // Barycentric coordinates(l0l1l2, l3 = 1-l0-l1-l2) for a point p with respect to a tetrahedron (b0 b1 b2 b3)
83 inline DYN_FUNC bool getBarycentric(Vec3f& bary, Vec3f p,
84 Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
85
86 // Compute the intersection of a line and a triangle in 2D [return num of intersection: 0, 1, 2]
87 inline DYN_FUNC int getIntersection(float& t0, float& t1,
88 Vec2f a0, Vec2f a1,
89 Vec2f b0, Vec2f b1, Vec2f b2);
90
91 // Compute the intersection of two triangle [return num of intersection: 0, 1, 2]
92 inline DYN_FUNC int getIntersection(Vec3f& p0, Vec3f& p1,
93 Vec3f a0, Vec3f a1, Vec3f a2,
94 Vec3f b0, Vec3f b1, Vec3f b2);
95
96
97 // Compute Projection of p onto parallelogram
98 inline DYN_FUNC Vec2f projectWithParall(Vec3f p, Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a3);
99
100
101 // Compute the intersection of a plane and a seg [return num of intersection: <= 2]
102 inline DYN_FUNC int intrSegWithPlane(Vec3f* q,
103 Vec3f oA, Vec3f nA,
104 Vec3f b0, Vec3f b1);
105
106 // Compute the intersection of a plane and a triangle [return num of intersection: <= 3]
107 inline DYN_FUNC int intrTriWithPlane(Vec3f* q,
108 Vec3f oA, Vec3f nA,
109 Vec3f b0, Vec3f b1, Vec3f b2);
110
111 // Compute the intersection of a plane and a tet [return num of intersection: <= 4]
112 inline DYN_FUNC int intrTetWithPlane(Vec3f* q,
113 Vec3f oA, Vec3f nA,
114 Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3);
115
116 // Compute the intersection of a plane and a box [return num of intersection: <= 4]
117 inline DYN_FUNC int intrBoxWithPlane(Vec3f* q,
118 Vec3f oA, Vec3f nA,
119 Vec3f center, Vec3f halfU, Vec3f halfV, Vec3f halfW);
120
121 // Compute the intersection of polygon( 3<=n<=4 ) with line on 2D [return num of intersection: <= 2]
122 inline DYN_FUNC int intrPolyWithLine(float* t,
123 int n, Vec2f* p,
124 Vec2f a0, Vec2f a1);
125
126 // Compute the intersection of polygon( n<=4 ) with coplanar tri on 3D [return num of intersection: <= 6]
127 inline DYN_FUNC int intrPolyWithTri(Vec3f* q,
128 int n, Vec3f* p,
129 Vec3f a0, Vec3f a1, Vec3f a2);
130
131 // Compute the intersection of polygon( n<=4 ) with coplanar rect on 3D [return num of intersection: <= 8]
132 inline DYN_FUNC int intrPolyWithRect(Vec3f* q,
133 int n, Vec3f* p,
134 Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a3);
135 };
136};
137#include "ComputeGeometry.inl"
#define V(a, b, c)
#define T(t)
DYN_FUNC int intrSegWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1)
DYN_FUNC bool isInNarrowBand(Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3, Vec3f a0, Vec3f a1, Vec3f a2, float d)
DYN_FUNC Vec2f projectWithParall(Vec3f p, Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a3)
DYN_FUNC float getDistanceVF(Vec3f p, Vec3f a0, Vec3f a1, Vec3f a2)
DYN_FUNC float DotPerp(Vec2f const &v0, Vec2f const &v1)
DYN_FUNC int intrBoxWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f center, Vec3f halfU, Vec3f halfV, Vec3f halfW)
DYN_FUNC bool isConPolyOverLap2D(Vec3f face_n, int n_a, Vec3f *a, int n_b, Vec3f *b)
DYN_FUNC float DotCross(Vec3f const &U, Vec3f const &V, Vec3f const &W)
DYN_FUNC int intrPolyWithRect(Vec3f *q, int n, Vec3f *p, Vec3f a0, Vec3f a1, Vec3f a2, Vec3f a3)
DYN_FUNC Vec3f getProjectionVF(Vec3f p, Vec3f a0, Vec3f a1, Vec3f a2)
DYN_FUNC int intrTetWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC float getTriBoxAreaInTet(Vec3f a0, Vec3f a1, Vec3f a2, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC bool isInTet(Vec3f p, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC void Swap(T &a, T &b)
DYN_FUNC bool isIntrTri2Tet(Vec3f a0, Vec3f a1, Vec3f a2, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC int intrPolyWithLine(float *t, int n, Vec2f *p, Vec2f a0, Vec2f a1)
DYN_FUNC int intrPolyWithTri(Vec3f *q, int n, Vec3f *p, Vec3f a0, Vec3f a1, Vec3f a2)
DYN_FUNC Vec3f Cross(Vec3f const &U, Vec3f const &V)
DYN_FUNC int intrTriWithPlane(Vec3f *q, Vec3f oA, Vec3f nA, Vec3f b0, Vec3f b1, Vec3f b2)
DYN_FUNC int getIntersection(float &t0, float &t1, Vec2f a0, Vec2f a1, Vec2f b0, Vec2f b1, Vec2f b2)
DYN_FUNC bool isOverLap(float &c0, float &c1, float a0, float a1, float b0, float b1)
DYN_FUNC float getOverLapBoxAreaInPoly2D(Vec3f face_n, int n_a, Vec3f *a, int n_b, Vec3f *b)
DYN_FUNC bool Sign(Vec3f const &n, Vec3f const &p0, Vec3f const &p1, Vec3f const &p2)
DYN_FUNC Vec2f Perp(Vec2f const &v)
DYN_FUNC Vec3f getDirectionVF(Vec3f p, Vec3f a0, Vec3f a1, Vec3f a2)
DYN_FUNC float Dot(Vec3f const &U, Vec3f const &V)
DYN_FUNC float getVolume(Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
DYN_FUNC bool getBarycentric(Vec3f &bary, Vec3f p, Vec3f b0, Vec3f b1, Vec3f b2, Vec3f b3)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< float, 2 > Vec2f
Definition Vector2D.h:81
Vector< float, 3 > Vec3f
Definition Vector3D.h:93