33#define M_PI 3.14159265358979323846
36#define M_PI2 1.57079632679489661923
46 return b * (1.0 - h) + a * h;
49template <
typename T0,
typename T1,
typename T2>
103template <
typename T,
unsigned D>
135template <
typename T,
unsigned D>
138 const auto pa = p - a;
139 const auto ba = b - a;
140 const auto h =
clamp((pa*ba)/(ba*ba), T{0}, T{1});
141 return norm(pa - ba*h) - r;
164 T s =
util::sign(e0[0] * e2[1] - e0[1] * e2[0]);
168 s * (v1[0] * e1[1] - v1[1] * e1[0])),
169 s * (v2[0] * e2[1] - v2[1] * e2[0]));
183 auto ba = b - a;
auto pa = p - a;
184 auto cb = c - b;
auto pb = p - b;
185 auto ac = a - c;
auto pc = p - c;
188 auto x1 = ba*
clamp((ba*pa)/(ba*ba), T{0}, T{1}) - pa;
189 auto x2 = cb*
clamp((cb*pb)/(cb*cb), T{0}, T{1}) - pb;
190 auto x3 = ac*
clamp((ac*pc)/(ac*ac), T{0}, T{1}) - pc;
201 (nor*pa)*(nor*pa)/(nor*nor));
216 const T paba = pa * ba;
217 const T x =
norm(pa * baba - ba * paba) - r * baba;
218 const T y =
util::abs(paba - baba * T {0.5}) - baba * T {0.5};
220 const T y2 = y * y * baba;
223 : (((x > T {0}) ? x2 : T {0}) + ((y > T {0}) ? y2 : T {0}));
254 T papa = (p - a) * (p - a);
255 T paba = (p - a) * (ba) / baba;
260 T cax =
util::max(0.0, x - ((paba < 0.5) ? ra : rb));
263 T k = rba * rba + baba;
264 T f =
clamp((rba * (x - ra) + paba * baba) / k, 0.0, 1.0);
265 T cbx = x - ra - f * rba;
267 T s = (cbx < 0.0 && cay < 0.0) ? -1.0 : 1.0;
269 cbx * cbx + cby * cby * baba));
285 return sdf::cone(p, a, ba, baba, ra, rb);
295 const Vector<T, 3> a(p[0] / r[0], p[1] / r[1], p[2] / r[2]);
297 const Vector<T, 3> r2(r[0] * r[0], r[1] * r[1], r[2] * r[2]);
298 const Vector<T, 3> b(p[0] / r2[0], p[1] / r2[1], p[2] / r2[2]);
301 : k0 * (k0 - 1.0) / k1;
315 return norm(q) - t[1];
330 T m =
norm(q - c *
clamp(q * c, 0.0, r));
338template <
typename T,
unsigned D>
347 return {p[1], p[0], p[2]};
389 T h =
clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
390 return mix(a, b, h) - k * h * (1.0 - h);
396 T h =
clamp(0.5 - 0.5 * (b + a) / k, 0.0, 1.0);
397 return mix(b, -a, h) + k * h * (1.0 - h);
403 T h =
clamp(0.5 - 0.5 * (b - a) / k, 0.0, 1.0);
404 return mix(b, a, h) + k * h * (1.0 - h);
425template <
typename T,
bool symmetryCheck = true>
434 if constexpr (symmetryCheck) {
440 if constexpr (symmetryCheck) {
441 if (!sdfIsSymmetric[0]) {
442 std::cout <<
"Warning: symmetry in x is not met" << std::endl;
449 if constexpr (symmetryCheck) {
450 if (!sdfIsSymmetric[1]) {
451 std::cout <<
"Warning: symmetry in y is not met" << std::endl;
458 if constexpr (symmetryCheck) {
459 if (!sdfIsSymmetric[2]) {
460 std::cout <<
"Warning: symmetry in z is not met" << std::endl;
476template <
typename T,
unsigned D>
480 return sdf((p - center) / s) * s;
488 const T d = signedDist + .5 * eps;
495 T
const halfEps = .5 * eps;
496 if (signedDist <= -halfEps) {
500 else if (signedDist < halfEps) {
T rounding(T a, T r) any_platform
Computes a layer of a constant thickness around the surface.
T torus(Vector< T, 3 > p, Vector< T, 2 > t) any_platform
Exact signed distance to the surface of a torus placed in the XZ-plane of the coordinate system.
Vector< T, 3 > flip(Vector< T, 3 > p) any_platform
T signedDistanceToPorosity(T signedDist, T eps) any_platform
Converts signed distance to values for the smooth epsilon boundary.
T intersection(T a, T b) any_platform
Volume which is shared by a and b creates a new object.
T triangle(Vector< T, 2 > p, Vector< T, 2 > a, Vector< T, 2 > b, Vector< T, 2 > c) any_platform
Exact signed distance to the surface of two-dimensional triangle.
T sphere(Vector< T, D > p, T r) any_platform
Exact signed distance to the surface of circle (in 2D) or sphere (in 3D).
T elongation(std::function< T(const Vector< T, 3 > &)> sdf, const Vector< T, 3 > &p, const Vector< T, 3 > &h, const Vector< T, 3 > ¢er=(T(0))) any_platform
Elongation splits the object in 2 (4 or 8) parts, moves them apart and connects them again The object...
T scale(std::function< T(const Vector< T, D > &)> sdf, const Vector< T, D > &p, T s, const Vector< T, D > ¢er=(T(0))) any_platform
Function to scale a geometry The object has to be placed in the origin of the coodinate system.
T unify(T a, T b) any_platform
Volume of a and volume of b are combined as a new object.
Vector< T, D > translate(Vector< T, D > p, Vector< T, D > origin) any_platform
Translation: The output of this function is used for the calculation of the signed distance to transl...
T mix(T a, T b, T h) any_platform
bool evalSolidVolumeFraction(T output[], T signedDist, T eps) any_platform
T smooth_subtraction(T a, T b, T k) any_platform
T line(Vector< T, D > p, Vector< T, D > a, Vector< T, D > b, T r) any_platform
T cone(Vector< T, 3 > p, Vector< T, 3 > a, Vector< T, 3 > ba, T baba, T ra, T rb) any_platform
Exact signed distance to the surface of three-dimensional (capped) cone.
T smooth_intersection(T a, T b, T k) any_platform
T box(Vector< T, 2 > p, Vector< T, 2 > b) any_platform
Exact signed distance to the surface of two-dimensional cuboid.
T ellipsoid(Vector< T, 3 > p, Vector< T, 3 > r) any_platform
Calculate the NOT EXACT (!) signed distance to the surface of three-dimensional ellipsoid.
T cylinder(Vector< T, 3 > p, Vector< T, 3 > a, Vector< T, 3 > ba, T baba, T r) any_platform
Exact signed distance to the surface of three-dimensional cylinder.
Vector< bool, 3 > isSymmetric(std::function< T(const Vector< T, 3 > &)> sdf, Vector< T, 3 > center) any_platform
A rough test for symmetry.
T solidAngle(Vector< T, 3 > p, Vector< T, 2 > c, T r) any_platform
Exact signed distance to the surface of a solid angle which represents a combination of a cone (axis ...
T subtraction(T a, T b) any_platform
Volume of a is subtracted from b.
decltype(T0 {} *T1 {} *T2 {}) clamp(T0 x, T1 a, T2 b) any_platform
T smooth_union(T a, T b, T k) any_platform
ADf< T, DIM > abs(const ADf< T, DIM > &a)
int sign(T val) any_platform
Expr pow(Expr base, Expr exp)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
std::enable_if_t< std::is_arithmetic< T >::type::value, T > abs(T x) any_platform
auto crossProduct(const ScalarVector< T, D, IMPL > &a, const ScalarVector< T, D, IMPL_ > &b) any_platform
constexpr T norm(const ScalarVector< T, D, IMPL > &a) any_platform
Euclidean vector norm.
efficient implementation of a vector class