Skip to content

Sphube, 3D squircle, hyper-superellipse, whatever you want to call it. #55

Description

@sh1boot

Maybe add this:

@sdf3
def sphube(radius=1, n=4, center=ORIGIN):
    def psum(*args, n=1):
        return pow(sum(map(lambda x: pow(x, n), args)), 1.0 / n)
    def f(p):
        p = abs(p - center) / radius
        px, py, pz = p[:,0], p[:,1], p[:,2]
        return psum(px, py, pz, n=n) - 1.0
    return f

n=1: an octahedron
n=2: a sphere
n=4: a 3D squircle, or "sphube"
n=+inf: a cube

But n doesn't have to be an integer, and transitions smoothly from 0 to +inf.

https://en.wikipedia.org/wiki/Squircle
https://en.wikipedia.org/wiki/Superellipse

It's like a rounded box, but it doesn't have any flat segments.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions