From bb0773320c101f253d64c2c9d4e6aab874348bef Mon Sep 17 00:00:00 2001 From: Tomas Maly Date: Sat, 27 Jan 2024 03:52:33 +0100 Subject: [PATCH] hemispheres --- sources/modesConfiguration.cpp | 4 ++++ sources/sdf.cpp | 16 ++++++++++++++++ sources/sdf.h | 1 + 3 files changed, 21 insertions(+) diff --git a/sources/modesConfiguration.cpp b/sources/modesConfiguration.cpp index 6f99ff0..e52db47 100644 --- a/sources/modesConfiguration.cpp +++ b/sources/modesConfiguration.cpp @@ -52,6 +52,7 @@ namespace unnatural &sdfH2O, &sdfH3O, &sdfH4O, + &sdfHemispheres, &sdfHexagon, &sdfHexagonalPrism, &sdfInsideCube, @@ -89,6 +90,7 @@ namespace unnatural "h2o", "h3o", "h4o", + "hemispheres", "hexagon", "hexagonalprism", "insidecube", @@ -138,6 +140,8 @@ namespace unnatural return true; if (name == "bowl") return true; + if (name == "hemispheres") + return true; if (name == "hexagon") return true; if (name == "insidecube") diff --git a/sources/sdf.cpp b/sources/sdf.cpp index 21d1764..e46b837 100644 --- a/sources/sdf.cpp +++ b/sources/sdf.cpp @@ -379,4 +379,20 @@ namespace unnatural return sdfCylinder(Vec3(p[0], p[2], p[1]), 10000, Radius) * -1; return Radius - abs(p[2]); } + + Real sdfHemispheres(const Vec3 &p_) + { + const Vec3 p = Vec3(abs(p_[0]), abs(p_[1]), p_[2]); + const auto &rotate = [](Vec3 p) -> Vec3 + { + static constexpr Real s = 0.707106781186547524400844362104; // sin(45) + return Vec3((p[0] - p[1]) * s, (p[0] + p[1]) * s, p[2]); + }; + const Vec3 q = rotate(p + Vec3(-2000, 0, 0)); + const Real c = sdfCylinder(Vec3(q[1], q[2], q[0]), 10000, 200); + const Real s1 = sdfSphere(q, 1000); + const Real s2 = sdfSphere(rotate(p + Vec3(0, -2000, 0)), 1000); + const Real s = min(s1, s2); + return smoothMin(c, s, 100); + } } diff --git a/sources/sdf.h b/sources/sdf.h index 962f742..c78c54f 100644 --- a/sources/sdf.h +++ b/sources/sdf.h @@ -21,6 +21,7 @@ namespace unnatural Real sdfH2O(const Vec3 &pos); Real sdfH3O(const Vec3 &pos); Real sdfH4O(const Vec3 &pos); + Real sdfHemispheres(const Vec3 &p); Real sdfHexagon(const Vec3 &pos); Real sdfHexagonalPrism(const Vec3 &pos); Real sdfInsideCube(const Vec3 &p);