# Makie - How does one plot a cube w/ rounded edges & corners?

**URL:** <https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [December 7, 2022, 12:17pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360 "2022-12-07T12:17:09Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [December 7, 2022, 12:17pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/1 "2022-12-07T12:17:09Z")

</div>

* * *

The following Julia program uses Makie to create the image shown below, a “cube with holes.” However, I would like to **eliminate the holes** , and also **make the cube nearer the shape of an actual cube, with only _slightly_ rounded corners and edges**. I’ve tried changing the exponent to values other than `^2` and also passing the `range` directly to the `volume!` function, to no avail. Examples of the types of cubes desired can be found in `three-rounded-box` images at [CodeSandbox](https://codesandbox.io/examples/package/three-rounded-box).

* * *

```julia
using Makie, GLMakie
fig = Figure()
range = LinRange(-1, 1, 5) # LinRange{Float64, Int64}
cube = [(x.^2 + y.^2 + z.^2) for x = range, y = range, z = range] # Array{Float64, 3}
ax = Axis3( fig[1,1], aspect = :data, azimuth = 1.17 * pi, viewmode = :fit, title = "Cube" )
volume!( cube, algorithm = :iso, isorange = 0.05, isovalue = 1.7 )
fig

```

* * *

 ![image](https://global.discourse-cdn.com/julialang/original/3X/5/1/51a3909b86e97229634bc733eacd10c6e314339c.png)

* * *

I would consider another plotting library, if there is another that is much more suitable to this task.

* * *

---

<div class="post-metadata">

**Author:** ![fedoroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedoroff/32/53209_2.png) [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Post date:** [December 7, 2022, 12:30pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/2 "2022-12-07T12:30:10Z")

</div>

You can do it with [super-Gaussian](https://en.wikipedia.org/wiki/Gaussian_function#Higher-order_Gaussian_or_super-Gaussian_function) function:

```julia
using GLMakie
fig = Figure()
range = LinRange(-1, 1, 5) # LinRange{Float64, Int64}
p = 4 # supergauss order
a = 1 # radius
cube = [@. exp(-(x/a)^p) * exp(-(y/a)^p) + exp(-(z/a)^p) for x = range, y = range, z = range] # Array{Float64, 3}
ax = Axis3(fig[1,1], aspect = :data, azimuth = 1.17 * pi, viewmode = :fit, title = "Cube" )
volume!( cube, algorithm = :iso, isorange = 0.05, isovalue = 1.7 )
fig

```

 ![test](https://global.discourse-cdn.com/julialang/original/3X/9/5/95e146ee7486de42bd75bac8bc3c09f7c68d7277.png)  
Higher order `p` will give more sharp edges.

---

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [December 7, 2022, 1:58pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/3 "2022-12-07T13:58:33Z")

</div>

Thank you for this information. A couple of more questions. (1) How does one save the image to a, say, PNG, file. I’m looking into at [`Makie.save`](https://docs.juliahub.com/AbstractPlotting/6fydZ/0.12.16/output.html). (2) Running in Windows from command line, but plot does not appear unless I copy Julia source code and paste it into REPL. How does one make plot appear when running, say, `Cube_Program.jl` from Windows command line.

---

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [December 7, 2022, 2:11pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/4 "2022-12-07T14:11:44Z")

</div>

Sorry, you can disregard Question (1) as I have solved it using `Makie.save`.

---

<div class="post-metadata">

**Author:** ![fedoroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedoroff/32/53209_2.png) [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Post date:** [December 7, 2022, 2:26pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/5 "2022-12-07T14:26:48Z")

</div>

Sorry. I have only Linux.

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [December 7, 2022, 3:41pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/6 "2022-12-07T15:41:54Z")

</div>

See [https://discourse.julialang.org/t/color-of-a-parametric-surface-with-makie/91363/3](https://discourse.julialang.org/t/color-of-a-parametric-surface-with-makie/91363/3).

---

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [December 7, 2022, 4:02pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/7 "2022-12-07T16:02:36Z")

</div>

Thanks for this additional information. I’m also using the following to draw a cube, but would like to add line segments to emphasize the cube’s edges, as shown in red in the figure below. Any suggestions on how to add line segments for the cube’s edges?

```julia
using GLMakie
vertices = [ 0.0 0.0 0.0;
             1.0 0.0 0.0;
             1.0 1.0 0.0;
             0.0 1.0 0.0;
             0.0 0.0 1.0;
             1.0 0.0 1.0;
             1.0 1.0 1.0;
             0.0 1.0 1.0; ]
faces = [ 1 2 3; 3 4 1;
          5 6 7; 7 8 5;
          6 2 3; 3 7 6;
          5 1 4; 4 8 5;
          8 7 3; 3 4 8;
          5 6 2; 2 1 5 ]
colors = [:gray, :gray, :gray, :gray, :gray, :gray, :gray, :gray]
scene = GLMakie.mesh(vertices, faces, color = colors, shading = true )

```

* * *

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/7/a7784ecd2f5768c9ae744d7b255aad1a7be631fc.png)

* * *

---

<div class="post-metadata">

**Author:** ![\_stla](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/_stla/32/35613_2.png) [@\_stla](https://discourse.julialang.org/u/_stla)\
**Post date:** [December 7, 2022, 5:20pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/8 "2022-12-07T17:20:35Z")

</div>

There’s probably a function to draw some segments in **Makie**.

---

<div class="post-metadata">

**Author:** ![Cougar](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Cougar](https://discourse.julialang.org/u/Cougar)\
**Post date:** [December 7, 2022, 5:39pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/9 "2022-12-07T17:39:14Z")

</div>

* * *

The cube’s edges can be drawn utilizing the function [lines](https://docs.juliahub.com/AbstractPlotting/6fydZ/0.12.12/plotting_functions.html#lines) …

```julia
using GLMakie
theScene = GLMakie.Scene()
vertices = [ 0.0 0.0 0.0;
             1.0 0.0 0.0;
             1.0 1.0 0.0;
             0.0 1.0 0.0;
             0.0 0.0 1.0;
             1.0 0.0 1.0;
             1.0 1.0 1.0;
             0.0 1.0 1.0; ]
faces = [ 1 2 3; 3 4 1;
          5 6 7; 7 8 5;
          6 2 3; 3 7 6;
          5 1 4; 4 8 5;
          8 7 3; 3 4 8;
          5 6 2; 2 1 5 ]
colors = [:gray, :gray, :gray, :gray, :gray, :gray, :gray, :gray]
GLMakie.mesh!(theScene,vertices,faces, color = colors, shading = true)

GLMakie.lines!(theScene, LinRange(0,1,2), LinRange(0,0,2), LinRange(0,0,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(0,1,2), LinRange(0,0,2), LinRange(1,1,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(0,1,2), LinRange(1,1,2), LinRange(0,0,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(0,1,2), LinRange(1,1,2), LinRange(1,1,2), linewidth = 10)

GLMakie.lines!(theScene, LinRange(0,0,2), LinRange(0,1,2), LinRange(0,0,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(0,0,2), LinRange(0,1,2), LinRange(1,1,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(1,1,2), LinRange(0,1,2), LinRange(0,0,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(1,1,2), LinRange(0,1,2), LinRange(1,1,2), linewidth = 10)

GLMakie.lines!(theScene, LinRange(0,0,2), LinRange(0,0,2), LinRange(0,1,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(0,0,2), LinRange(1,1,2), LinRange(0,1,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(1,1,2), LinRange(0,0,2), LinRange(0,1,2), linewidth = 10)
GLMakie.lines!(theScene, LinRange(1,1,2), LinRange(1,1,2), LinRange(0,1,2), linewidth = 10)

```

* * *

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/6/b6bb4bfa59186a0e9d7da37fc0fd5103e85b3614.png)

* * *

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [December 7, 2022, 6:17pm UTC](https://discourse.julialang.org/t/makie-how-does-one-plot-a-cube-w-rounded-edges-corners/91360/10 "2022-12-07T18:17:56Z")

</div>

you might be interested in this section [How to Cube - Beautiful Makie](https://beautiful.makie.org/dev/examples/generated/2d/meshes/how_to_cube/)
