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>
155 T s =
util::sign(e0[0] * e2[1] - e0[1] * e2[0]);
159 s * (v1[0] * e1[1] - v1[1] * e1[0])),
160 s * (v2[0] * e2[1] - v2[1] * e2[0]));
176 const T paba = pa * ba;
177 const T x =
norm(pa * baba - ba * paba) - r * baba;
178 const T y =
util::abs(paba - baba * T {0.5}) - baba * T {0.5};
180 const T y2 = y * y * baba;
183 : (((x > T {0}) ? x2 : T {0}) + ((y > T {0}) ? y2 : T {0}));
214 T papa = (p - a) * (p - a);
215 T paba = (p - a) * (ba) / baba;
220 T cax =
util::max(0.0, x - ((paba < 0.5) ? ra : rb));
223 T k = rba * rba + baba;
224 T f =
clamp((rba * (x - ra) + paba * baba) / k, 0.0, 1.0);
225 T cbx = x - ra - f * rba;
227 T s = (cbx < 0.0 && cay < 0.0) ? -1.0 : 1.0;
229 cbx * cbx + cby * cby * baba));
245 return sdf::cone(p, a, ba, baba, ra, rb);
255 const Vector<T, 3> a(p[0] / r[0], p[1] / r[1], p[2] / r[2]);
257 const Vector<T, 3> r2(r[0] * r[0], r[1] * r[1], r[2] * r[2]);
258 const Vector<T, 3> b(p[0] / r2[0], p[1] / r2[1], p[2] / r2[2]);
261 : k0 * (k0 - 1.0) / k1;
275 return norm(q) - t[1];
290 T m =
norm(q - c *
clamp(q * c, 0.0, r));
298template <
typename T,
unsigned D>
307 return {p[1], p[0], p[2]};
349 T h =
clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
350 return mix(a, b, h) - k * h * (1.0 - h);
356 T h =
clamp(0.5 - 0.5 * (b + a) / k, 0.0, 1.0);
357 return mix(b, -a, h) + k * h * (1.0 - h);
363 T h =
clamp(0.5 - 0.5 * (b - a) / k, 0.0, 1.0);
364 return mix(b, a, h) + k * h * (1.0 - h);
385template <
typename T,
bool symmetryCheck = true>
394 if constexpr (symmetryCheck) {
400 if constexpr (symmetryCheck) {
401 if (!sdfIsSymmetric[0]) {
402 std::cout <<
"Warning: symmetry in x is not met" << std::endl;
409 if constexpr (symmetryCheck) {
410 if (!sdfIsSymmetric[1]) {
411 std::cout <<
"Warning: symmetry in y is not met" << std::endl;
418 if constexpr (symmetryCheck) {
419 if (!sdfIsSymmetric[2]) {
420 std::cout <<
"Warning: symmetry in z is not met" << std::endl;
436template <
typename T,
unsigned D>
440 return sdf((p - center) / s) * s;
448 const T d = signedDist + .5 * eps;
455 T
const halfEps = .5 * eps;
456 if (signedDist <= -halfEps) {
460 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 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
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
ADf< T, DIM > abs(const ADf< T, DIM > &a)
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
ADf< T, DIM > cos(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
std::enable_if_t< std::is_arithmetic< T >::type::value, T > abs(T x)
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
constexpr T norm(const ScalarVector< T, D, IMPL > &a)
Euclidean vector norm.
efficient implementation of a vector class