OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::sdf Namespace Reference

Functions

template<typename T >
mix (T a, T b, T h) any_platform
 
template<typename T0 , typename T1 , typename T2 >
decltype(T0 {} *T1 {} *T2 {}) clamp (T0 x, T1 a, T2 b) any_platform
 
template<typename T >
Vector< bool, 3 > isSymmetric (std::function< T(const Vector< T, 3 > &)> sdf, Vector< T, 3 > center) any_platform
 A rough test for symmetry.
 
template<typename T , unsigned D>
sphere (Vector< T, D > p, T r) any_platform
 Exact signed distance to the surface of circle (in 2D) or sphere (in 3D).
 
template<typename T >
box (Vector< T, 2 > p, Vector< T, 2 > b) any_platform
 Exact signed distance to the surface of two-dimensional cuboid.
 
template<typename T >
box (Vector< T, 3 > p, Vector< T, 3 > b) any_platform
 Exact signed distance to the surface of three-dimensional cuboid.
 
template<typename T , unsigned D>
line (Vector< T, D > p, Vector< T, D > a, Vector< T, D > b, T r) any_platform
 
template<typename 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.
 
template<typename T >
triangle (Vector< T, 3 > p, Vector< T, 3 > a, Vector< T, 3 > b, Vector< T, 3 > c) any_platform
 Exact signed distance to the surface of three-dimensional triangle.
 
template<typename 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.
 
template<typename T >
cylinder (Vector< T, 3 > p, Vector< T, 3 > a, Vector< T, 3 > b, T r) any_platform
 Calculate signed distance to the surface of three-dimensional cylinder defined by the centers of the two extremities and the radius.
 
template<typename 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.
 
template<typename T >
cone (Vector< T, 3 > p, Vector< T, 3 > a, Vector< T, 3 > b, T ra, T rb) any_platform
 Calculate signed distance to the surface of three-dimensional capped cone defined by the centers of the two extremities and the corresponding radius.
 
template<typename 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.
 
template<typename 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.
 
template<typename 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 y=0 to y=r) and a sphere.
 
template<typename T , unsigned D>
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 translated/shifted objects.
 
template<typename T >
Vector< T, 3 > flip (Vector< T, 3 > p) any_platform
 
template<typename T >
subtraction (T a, T b) any_platform
 Volume of a is subtracted from b.
 
template<typename T >
unify (T a, T b) any_platform
 Volume of a and volume of b are combined as a new object.
 
template<typename T >
intersection (T a, T b) any_platform
 Volume which is shared by a and b creates a new object.
 
template<typename T >
smooth_union (T a, T b, T k) any_platform
 
template<typename T >
smooth_subtraction (T a, T b, T k) any_platform
 
template<typename T >
smooth_intersection (T a, T b, T k) any_platform
 
template<typename T >
rounding (T a, T r) any_platform
 Computes a layer of a constant thickness around the surface.
 
template<typename T , bool symmetryCheck = true>
elongation (std::function< T(const Vector< T, 3 > &)> sdf, const Vector< T, 3 > &p, const Vector< T, 3 > &h, const Vector< T, 3 > &center=(T(0))) any_platform
 Elongation splits the object in 2 (4 or 8) parts, moves them apart and connects them again The object has to be placed in the origin of the coodinate system.
 
template<typename T , unsigned D>
scale (std::function< T(const Vector< T, D > &)> sdf, const Vector< T, D > &p, T s, const Vector< T, D > &center=(T(0))) any_platform
 Function to scale a geometry The object has to be placed in the origin of the coodinate system.
 
template<typename T >
signedDistanceToPorosity (T signedDist, T eps) any_platform
 Converts signed distance to values for the smooth epsilon boundary.
 
template<typename T >
bool evalSolidVolumeFraction (T output[], T signedDist, T eps) any_platform
 

Function Documentation

◆ box() [1/2]

template<typename T >
T olb::sdf::box ( Vector< T, 2 > p,
Vector< T, 2 > b )

Exact signed distance to the surface of two-dimensional cuboid.

Parameters
ppoint for which the distance to the surface is calculated
bvector containing half side lengths to describe the cuboid

Definition at line 115 of file sdf.h.

116{
117 Vector<T, 2> q = abs(p) - b;
118 return norm(maxv(q, Vector<T, 2>(0.0))) +
119 util::min(util::max({q[0], q[1]}), T());
120}
Plain old scalar vector.
constexpr Vector< T, D > maxv(const ScalarVector< T, D, IMPL > &v, const ScalarVector< T, D, IMPL_ > &w)
Definition vector.h:457
constexpr T norm(const ScalarVector< T, D, IMPL > &a) any_platform
Euclidean vector norm.

References olb::abs(), olb::util::max(), olb::maxv(), olb::util::min(), and olb::norm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ box() [2/2]

template<typename T >
T olb::sdf::box ( Vector< T, 3 > p,
Vector< T, 3 > b )

Exact signed distance to the surface of three-dimensional cuboid.

Parameters
ppoint for which the distance to the surface is calculated
bvector containing half side lengths to describe the cuboid

Definition at line 128 of file sdf.h.

129{
130 Vector<T, 3> q = abs(p) - b;
131 return norm(maxv(q, Vector<T, 3>(0.0))) +
132 util::min(util::max({q[0], q[1], q[2]}), T());
133}

References olb::abs(), olb::util::max(), olb::maxv(), olb::util::min(), and olb::norm().

+ Here is the call graph for this function:

◆ clamp()

template<typename T0 , typename T1 , typename T2 >
decltype(T0 {} *T1 {} *T2 {}) olb::sdf::clamp ( T0 x,
T1 a,
T2 b )

Definition at line 50 of file sdf.h.

50 {} * T1 {} * T2 {}) clamp(T0 x, T1 a, T2 b) any_platform
51{
52 if (x < a) {
53 return a;
54 }
55 else if (x > b) {
56 return b;
57 }
58 else {
59 return x;
60 }
61}
decltype(T0 {} *T1 {} *T2 {}) clamp(T0 x, T1 a, T2 b) any_platform
Definition sdf.h:50
#define any_platform
Define preprocessor macros for device-side functions, constant storage.
Definition platform.h:77
+ Here is the caller graph for this function:

◆ cone() [1/2]

template<typename T >
T olb::sdf::cone ( Vector< T, 3 > p,
Vector< T, 3 > a,
Vector< T, 3 > b,
T ra,
T rb )

Calculate signed distance to the surface of three-dimensional capped cone defined by the centers of the two extremities and the corresponding radius.

For the calculation of a cone, the second radius is set to zero

Parameters
ppoint for which the distance to the surface is calculated
avector containing center of the first circular end of the capped cone
bvector containing center of the second circular end of the capped cone or the apex of the cone
raradius of the first circular end of the capped cone
rbradius of the second circular end of the capped cone

Definition at line 281 of file sdf.h.

282{
283 Vector<T, 3> ba = b - a;
284 T baba = ba * ba;
285 return sdf::cone(p, a, ba, baba, ra, rb);
286}

References cone().

+ Here is the call graph for this function:

◆ cone() [2/2]

template<typename T >
T olb::sdf::cone ( Vector< T, 3 > p,
Vector< T, 3 > a,
Vector< T, 3 > ba,
T baba,
T ra,
T rb )

Exact signed distance to the surface of three-dimensional (capped) cone.

Parameters
ppoint for which the distance to the surface is calculated
avector containing center of the first circular end of the (capped) cone
bavector representing the axis of the (capped) cone
babalength of the cone height squared

Definition at line 250 of file sdf.h.

252{
253 T rba = rb - ra;
254 T papa = (p - a) * (p - a);
255 T paba = (p - a) * (ba) / baba;
256 // x distance to the axis of the cone
257 // note: abs() prevents from negative values, e.g. caused by rounding errors
258 T x = util::sqrt(util::abs(papa - paba * paba * baba));
259 // cax and cay for the distances to the caps
260 T cax = util::max(0.0, x - ((paba < 0.5) ? ra : rb));
261 T cay = util::abs(paba - 0.5) - 0.5;
262 // cbx and cby for the distance to the side wall
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;
266 T cby = paba - f;
267 T s = (cbx < 0.0 && cay < 0.0) ? -1.0 : 1.0;
268 return s * util::sqrt(util::min(cax * cax + cay * cay * baba,
269 cbx * cbx + cby * cby * baba));
270}

References olb::util::abs(), clamp(), olb::util::max(), olb::util::min(), and olb::util::sqrt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cylinder() [1/2]

template<typename T >
T olb::sdf::cylinder ( Vector< T, 3 > p,
Vector< T, 3 > a,
Vector< T, 3 > b,
T r )

Calculate signed distance to the surface of three-dimensional cylinder defined by the centers of the two extremities and the radius.

Parameters
ppoint for which the distance to the surface is calculated
avector containing center of the first circular end of the cylinder
bvector containing center of the second circular end of the cylinder
rradius of the cylinder

Definition at line 235 of file sdf.h.

236{
237 Vector<T, 3> ba = b - a;
238 T baba = ba * ba;
239 return sdf::cylinder(p, a, ba, baba, r);
240}

References cylinder().

+ Here is the call graph for this function:

◆ cylinder() [2/2]

template<typename T >
T olb::sdf::cylinder ( Vector< T, 3 > p,
Vector< T, 3 > a,
Vector< T, 3 > ba,
T baba,
T r )

Exact signed distance to the surface of three-dimensional cylinder.

Parameters
ppoint for which the distance to the surface is calculated
avector containing center of the first circular end of the cylinder
bavector representing the axis of the cylinder
babalength of the cylinder height squared
rradius of cylinder

Definition at line 213 of file sdf.h.

214{
215 const Vector<T, 3> pa = p - a;
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};
219 const T x2 = x * x;
220 const T y2 = y * y * baba;
221 const T d = (util::max(x, y) < T {0})
222 ? -util::min(x2, y2)
223 : (((x > T {0}) ? x2 : T {0}) + ((y > T {0}) ? y2 : T {0}));
224 return util::sign(d) * util::sqrt(util::abs(d)) / baba;
225}

References olb::util::abs(), olb::util::max(), olb::util::min(), olb::norm(), olb::util::sign(), and olb::util::sqrt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ellipsoid()

template<typename T >
T olb::sdf::ellipsoid ( Vector< T, 3 > p,
Vector< T, 3 > r )

Calculate the NOT EXACT (!) signed distance to the surface of three-dimensional ellipsoid.

Parameters
ppoint for which the distance to the surface is calculated
rvector containing half the length of the principal axes

Definition at line 293 of file sdf.h.

294{
295 const Vector<T, 3> a(p[0] / r[0], p[1] / r[1], p[2] / r[2]);
296 T k0 = norm(a);
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]);
299 T k1 = norm(b);
300 return (k0 < 1.0) ? (k0 - 1.0) * util::min(util::min(r[0], r[1]), r[2])
301 : k0 * (k0 - 1.0) / k1;
302}

References olb::util::min(), and olb::norm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ elongation()

template<typename T , bool symmetryCheck = true>
T olb::sdf::elongation ( std::function< T(const Vector< T, 3 > &)> sdf,
const Vector< T, 3 > & p,
const Vector< T, 3 > & h,
const Vector< T, 3 > & center = (T(0)) )

Elongation splits the object in 2 (4 or 8) parts, moves them apart and connects them again The object has to be placed in the origin of the coodinate system.

Symmetry is required so that the splitted parts are symmetric (check can be disabled)

Parameters
sdfsigned Distance Function of the object which is altered
ppoint for which the distance to the surface is calculated
hvector containing the information how far the splitted parts are moved apart
centervector containing the center, to shift the object to the origin of the coordinate system for the calculation of the elongation

Definition at line 426 of file sdf.h.

429{
430 Vector<T, 3> q = abs(p - center) - h;
431 Vector<T, 3> p_elong = p - center;
432 // elongation requires symmetry e.g. for elongation in x --> plane of symmetry = YZ-plane
433 Vector<bool, 3> sdfIsSymmetric;
434 if constexpr (symmetryCheck) {
435 sdfIsSymmetric = isSymmetric(sdf, center);
436 }
437
438 if (h[0] != 0) {
439 p_elong[0] = util::max(q[0], 0.);
440 if constexpr (symmetryCheck) {
441 if (!sdfIsSymmetric[0]) {
442 std::cout << "Warning: symmetry in x is not met" << std::endl;
443 }
444 }
445 }
446
447 if (h[1] != 0) {
448 p_elong[1] = util::max(q[1], 0.);
449 if constexpr (symmetryCheck) {
450 if (!sdfIsSymmetric[1]) {
451 std::cout << "Warning: symmetry in y is not met" << std::endl;
452 }
453 }
454 }
455
456 if (h[2] != 0) {
457 p_elong[2] = util::max(q[2], 0.);
458 if constexpr (symmetryCheck) {
459 if (!sdfIsSymmetric[2]) {
460 std::cout << "Warning: symmetry in z is not met" << std::endl;
461 }
462 }
463 }
464
465 // Second term needed in case of 3D-Elongation if all parts of Vector q are negative
466 return sdf(p_elong + center) + util::min(util::max({q[0], q[1], q[2]}), 0.);
467}
constexpr int q() any_platform
Definition functions.h:140
Vector< bool, 3 > isSymmetric(std::function< T(const Vector< T, 3 > &)> sdf, Vector< T, 3 > center) any_platform
A rough test for symmetry.
Definition sdf.h:65

References olb::abs(), isSymmetric(), olb::util::max(), and olb::util::min().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ evalSolidVolumeFraction()

template<typename T >
bool olb::sdf::evalSolidVolumeFraction ( T output[],
T signedDist,
T eps )

Definition at line 493 of file sdf.h.

494{
495 T const halfEps = .5 * eps;
496 if (signedDist <= -halfEps) {
497 output[0] = 1.;
498 return true;
499 }
500 else if (signedDist < halfEps) {
501 output[0] = signedDistanceToPorosity(signedDist, eps);
502 return true;
503 }
504 output[0] = 0.;
505 return false;
506}

References signedDistanceToPorosity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flip()

template<typename T >
Vector< T, 3 > olb::sdf::flip ( Vector< T, 3 > p)

Definition at line 345 of file sdf.h.

346{
347 return {p[1], p[0], p[2]};
348}

◆ intersection()

template<typename T >
T olb::sdf::intersection ( T a,
T b )

Volume which is shared by a and b creates a new object.

The returned distance is not exact if the signed Distance of both objects points to the part of the surface which is removed for creating the combined object

Parameters
asigned Distance of the first object
bsigned Distance of the second object

Definition at line 381 of file sdf.h.

382{
383 return util::max(a, b);
384}

References olb::util::max().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSymmetric()

template<typename T >
Vector< bool, 3 > olb::sdf::isSymmetric ( std::function< T(const Vector< T, 3 > &)> sdf,
Vector< T, 3 > center )

A rough test for symmetry.

Definition at line 65 of file sdf.h.

67{
69
70 isSymmetric[0] = sdf(Vector<T, 3> {1., 1., 1.} + center) ==
71 sdf(Vector<T, 3> {-1., 1., 1.} + center) &&
72 sdf(Vector<T, 3> {1., -1., 1.} + center) ==
73 sdf(Vector<T, 3> {-1., -1., 1.} + center) &&
74 sdf(Vector<T, 3> {1., 1., -1.} + center) ==
75 sdf(Vector<T, 3> {-1., 1., -1.} + center) &&
76 sdf(Vector<T, 3> {1., -1., -1.} + center) ==
77 sdf(Vector<T, 3> {-1., -1., -1.} + center);
78 isSymmetric[1] = sdf(Vector<T, 3> {1., 1., 1.} + center) ==
79 sdf(Vector<T, 3> {1., -1., 1.} + center) &&
80 sdf(Vector<T, 3> {-1., 1., 1.} + center) ==
81 sdf(Vector<T, 3> {-1., -1., 1.} + center) &&
82 sdf(Vector<T, 3> {1., 1., -1.} + center) ==
83 sdf(Vector<T, 3> {1., -1., -1.} + center) &&
84 sdf(Vector<T, 3> {-1., 1., -1.} + center) ==
85 sdf(Vector<T, 3> {-1., -1., -1.} + center);
86 isSymmetric[2] = sdf(Vector<T, 3> {1., 1., 1.} + center) ==
87 sdf(Vector<T, 3> {1., 1., -1.} + center) &&
88 sdf(Vector<T, 3> {-1., 1., 1.} + center) ==
89 sdf(Vector<T, 3> {-1., 1., -1.} + center) &&
90 sdf(Vector<T, 3> {1., -1., 1.} + center) ==
91 sdf(Vector<T, 3> {1., -1., -1.} + center) &&
92 sdf(Vector<T, 3> {-1., -1., 1.} + center) ==
93 sdf(Vector<T, 3> {-1., -1., -1.} + center);
94
95 return isSymmetric;
96}

References isSymmetric().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ line()

template<typename T , unsigned D>
T olb::sdf::line ( Vector< T, D > p,
Vector< T, D > a,
Vector< T, D > b,
T r )

Definition at line 136 of file sdf.h.

137{
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;
142}

References clamp(), and olb::norm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mix()

template<typename T >
T olb::sdf::mix ( T a,
T b,
T h )

Definition at line 44 of file sdf.h.

45{
46 return b * (1.0 - h) + a * h;
47}
+ Here is the caller graph for this function:

◆ rounding()

template<typename T >
T olb::sdf::rounding ( T a,
T r )

Computes a layer of a constant thickness around the surface.

Parameters
asigned Distance of the object
rlayer thickness

Definition at line 412 of file sdf.h.

413{
414 return a - r;
415}

◆ scale()

template<typename T , unsigned D>
T olb::sdf::scale ( std::function< T(const Vector< T, D > &)> sdf,
const Vector< T, D > & p,
T s,
const Vector< T, D > & center = (T(0)) )

Function to scale a geometry The object has to be placed in the origin of the coodinate system.

Parameters
sdfsigned Distance Function of the object which is altered
ppoint for which the distance to the surface is calculated
sscaling factor
centervector containing the center, to shift the object to the origin of the coordinate system for the calculation of the elongation

Definition at line 477 of file sdf.h.

479{
480 return sdf((p - center) / s) * s;
481}
+ Here is the caller graph for this function:

◆ signedDistanceToPorosity()

template<typename T >
T olb::sdf::signedDistanceToPorosity ( T signedDist,
T eps )

Converts signed distance to values for the smooth epsilon boundary.

Definition at line 486 of file sdf.h.

487{
488 const T d = signedDist + .5 * eps;
489 return util::pow(util::cos(M_PI2 * d / eps), 2);
490}
#define M_PI2
Definition sdf.h:36

References olb::util::cos(), M_PI2, and olb::util::pow().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ smooth_intersection()

template<typename T >
T olb::sdf::smooth_intersection ( T a,
T b,
T k )

Definition at line 401 of file sdf.h.

402{
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);
405}
T mix(T a, T b, T h) any_platform
Definition sdf.h:44

References clamp(), and mix().

+ Here is the call graph for this function:

◆ smooth_subtraction()

template<typename T >
T olb::sdf::smooth_subtraction ( T a,
T b,
T k )

Definition at line 394 of file sdf.h.

395{
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);
398}

References clamp(), and mix().

+ Here is the call graph for this function:

◆ smooth_union()

template<typename T >
T olb::sdf::smooth_union ( T a,
T b,
T k )

Definition at line 387 of file sdf.h.

388{
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);
391}

References clamp(), and mix().

+ Here is the call graph for this function:

◆ solidAngle()

template<typename T >
T olb::sdf::solidAngle ( Vector< T, 3 > p,
Vector< T, 2 > c,
T r )

Exact signed distance to the surface of a solid angle which represents a combination of a cone (axis y=0 to y=r) and a sphere.

Parameters
ppoint for which the distance to the surface is calculated
c[0]sin of the angle
c[1]cos of the angle
rradius of the sphere

Definition at line 326 of file sdf.h.

327{
328 Vector<T, 2> q {norm(Vector<T, 2> {p[0], p[2]}), p[1]};
329 T l = norm(q) - r;
330 T m = norm(q - c * clamp(q * c, 0.0, r));
331 return util::max(l, m * util::sign(c[1] * q[0] - c[0] * q[1]));
332}

References clamp(), olb::util::max(), olb::norm(), and olb::util::sign().

+ Here is the call graph for this function:

◆ sphere()

template<typename T , unsigned D>
T olb::sdf::sphere ( Vector< T, D > p,
T r )

Exact signed distance to the surface of circle (in 2D) or sphere (in 3D).

Parameters
ppoint for which the distance to the surface is calculated
rradius describing the geometry

Definition at line 104 of file sdf.h.

105{
106 return norm(p) - r;
107}

References olb::norm().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subtraction()

template<typename T >
T olb::sdf::subtraction ( T a,
T b )

Volume of a is subtracted from b.

The returned distance is not exact if the signed Distance of both objects points to the part of the surface which is removed for creating the combined object

Parameters
asigned Distance of the first object
bsigned Distance of the second object

Definition at line 357 of file sdf.h.

358{
359 return util::max(-a, b);
360}

References olb::util::max().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ torus()

template<typename T >
T olb::sdf::torus ( Vector< T, 3 > p,
Vector< T, 2 > t )

Exact signed distance to the surface of a torus placed in the XZ-plane of the coordinate system.

Parameters
ppoint for which the distance to the surface is calculated
t[0]distance center of the tube to center of the torus
t[1]radius of the tube

Definition at line 311 of file sdf.h.

312{
313 Vector<T, 2> b {p[0], p[2]};
314 Vector<T, 2> q {norm(b) - t[0], p[1]};
315 return norm(q) - t[1];
316}

References olb::norm().

+ Here is the call graph for this function:

◆ translate()

template<typename T , unsigned D>
Vector< T, D > olb::sdf::translate ( Vector< T, D > p,
Vector< T, D > origin )

Translation: The output of this function is used for the calculation of the signed distance to translated/shifted objects.

Parameters
ppoint for which the distance to the surface is calculated
originpoint to which the object is shifted to

Definition at line 339 of file sdf.h.

340{
341 return p - origin;
342}
+ Here is the caller graph for this function:

◆ triangle() [1/2]

template<typename T >
T olb::sdf::triangle ( Vector< T, 2 > p,
Vector< T, 2 > a,
Vector< T, 2 > b,
Vector< T, 2 > c )

Exact signed distance to the surface of two-dimensional triangle.

Parameters
ppoint for which the distance to the surface is calculated
avector containing first vertex
bvector containing second vertex
cvector containing third vertex

Definition at line 152 of file sdf.h.

154{
155 Vector<T, 2> e0 = b - a;
156 Vector<T, 2> v0 = p - a;
157 Vector<T, 2> e1 = c - b;
158 Vector<T, 2> v1 = p - b;
159 Vector<T, 2> e2 = a - c;
160 Vector<T, 2> v2 = p - c;
161 Vector<T, 2> pq0 = v0 - e0 * clamp((v0 * e0) / (e0 * e0), 0., 1.);
162 Vector<T, 2> pq1 = v1 - e1 * clamp((v1 * e1) / (e1 * e1), 0., 1.);
163 Vector<T, 2> pq2 = v2 - e2 * clamp((v2 * e2) / (e2 * e2), 0., 1.);
164 T s = util::sign(e0[0] * e2[1] - e0[1] * e2[0]);
165
166 T dx = util::min(util::min((pq0 * pq0), (pq1 * pq1)), (pq2 * pq2));
167 T dy = util::min(util::min(s * (v0[0] * e0[1] - v0[1] * e0[0]),
168 s * (v1[0] * e1[1] - v1[1] * e1[0])),
169 s * (v2[0] * e2[1] - v2[1] * e2[0]));
170 return -util::sqrt(dx) * util::sign(dy);
171}

References clamp(), olb::util::min(), olb::util::sign(), and olb::util::sqrt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ triangle() [2/2]

template<typename T >
T olb::sdf::triangle ( Vector< T, 3 > p,
Vector< T, 3 > a,
Vector< T, 3 > b,
Vector< T, 3 > c )

Exact signed distance to the surface of three-dimensional triangle.

Parameters
ppoint for which the distance to the surface is calculated
avector containing first vertex
bvector containing second vertex
cvector containing third vertex

Definition at line 181 of file sdf.h.

182{
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;
186 auto nor = crossProduct(ba, ac);
187
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;
191
192 return util::sqrt(
193 (util::sign(crossProduct(ba,nor) * pa) +
194 util::sign(crossProduct(cb,nor) * pb) +
195 util::sign(crossProduct(ac,nor) * pc) < T{2})
196 ?
197 util::min(util::min((x1*x1),
198 (x2*x2)),
199 (x3*x3))
200 :
201 (nor*pa)*(nor*pa)/(nor*nor));
202}
auto crossProduct(const ScalarVector< T, D, IMPL > &a, const ScalarVector< T, D, IMPL_ > &b) any_platform
Definition vector.h:274

References clamp(), olb::crossProduct(), olb::util::min(), olb::util::sign(), and olb::util::sqrt().

+ Here is the call graph for this function:

◆ unify()

template<typename T >
T olb::sdf::unify ( T a,
T b )

Volume of a and volume of b are combined as a new object.

The returned distance is not exact if the signed Distance of both objects points to the part of the surface which is removed for creating the combined object

Parameters
asigned Distance of the first object
bsigned Distance of the second object

Definition at line 369 of file sdf.h.

370{
371 return util::min(a, b);
372}

References olb::util::min().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: