# How to create the rotated cube with Makie.jl and GeometryBasics.jl

**URL:** https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720
**Category:** General Usage
**Tags:** makie, geometrybasics
**Created:** [January 29, 2023, 5:31am UTC](https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720 "2023-01-29T05:31:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Mizu49](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mizu49/32/46338_2.png) [@Mizu49](https://discourse.julialang.org/u/Mizu49)
#### Post date: [January 29, 2023, 5:31am UTC](https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720/1 "2023-01-29T05:31:57Z")

</div>

I want to create the rotated cube with `Makie.jl` and `GeometryBasics.jl`. I made the following code, but it did not work well.

```julia
using GLMakie, GeometryBasics

# rotation matrix
theta = pi/4
C = [
    1 0 0
    0 cos(theta) -sin(theta)
    0 sin(theta) cos(theta)
]

# rotated points of a cube
points = [
    Point3{Float64}(C * [0.5, 0.5, 0.5]),
    Point3{Float64}(C * [-0.5, 0.5, 0.5]),
    Point3{Float64}(C * [-0.5, -0.5, 0.5]),
    Point3{Float64}(C * [0.5, -0.5, 0.5]),
    Point3{Float64}(C * [0.5, 0.5, -0.5]),
    Point3{Float64}(C * [-0.5, 0.5, -0.5]),
    Point3{Float64}(C * [-0.5, -0.5, -0.5]),
    Point3{Float64}(C * [0.5, -0.5, -0.5])
]

cube = GeometryBasics.mesh(points)

fig = Figure()
ax = Axis3(
    fig[1, 1],
    aspect = :data,
    viewmode = :fit
    ) 
mesh!(ax, cube, color=:yellow, shading = true)

display(fig)

```

The Makie displays the following, which does not contain any mesh.

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

I investigated the variable `cube`, and it gives the empty mesh. I believe it should have `Triangle`s.

```julia
julia> cube
Mesh{3, Float64, Triangle}

```

How can I resolve this? Or are there any other solutions?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [January 29, 2023, 6:27am UTC](https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720/2 "2023-01-29T06:27:01Z")

</div>

A list of points is not enough for a mesh, you need to define how these points are connected with faces as well.

[https://docs.makie.org/stable/examples/plotting\_functions/mesh/#examples](https://docs.makie.org/stable/examples/plotting_functions/mesh/#examples)

---

<div class="post-metadata">

### Author: ![Mizu49](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mizu49/32/46338_2.png) [@Mizu49](https://discourse.julialang.org/u/Mizu49)
#### Post date: [January 29, 2023, 11:35am UTC](https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720/3 "2023-01-29T11:35:00Z")

</div>

Thank you, Jules!

Adding the faces resolved this.

```julia
using GLMakie, GeometryBasics

theta = pi/4
C = [
    1 0 0
    0 cos(theta) -sin(theta)
    0 sin(theta) cos(theta)
]

points = hcat(
    C * [0.5, 0.5, 0.5],
    C * [-0.5, 0.5, 0.5],
    C * [-0.5, -0.5, 0.5],
    C * [0.5, -0.5, 0.5],
    C * [0.5, 0.5, -0.5],
    C * [-0.5, 0.5, -0.5],
    C * [-0.5, -0.5, -0.5],
    C * [0.5, -0.5, -0.5]
)

faces = [
    1 2 3
    3 4 1
    1 2 6
    1 5 6
    1 4 5
    4 5 8
    3 4 7
    4 7 8
    5 6 7
    5 7 8
    2 3 6
    3 6 7
]

fig = Figure()
ax = Axis3(
    fig[1, 1],
    aspect = :data,
    viewmode = :fit
    )
mesh!(ax, points, faces, color=:yellow, shading = true)

display(fig)

```

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

---

<div class="post-metadata">

### Author: ![Mizu49](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mizu49/32/46338_2.png) [@Mizu49](https://discourse.julialang.org/u/Mizu49)
#### Post date: [January 29, 2023, 12:44pm UTC](https://discourse.julialang.org/t/how-to-create-the-rotated-cube-with-makie-jl-and-geometrybasics-jl/93720/4 "2023-01-29T12:44:13Z")

</div>

Note that the `points` can be `Vector{Point3{Float64}}`.

```julia
points = [
    Point3{Float64}(C * [0.5, 0.5, 0.5]),
    Point3{Float64}(C * [-0.5, 0.5, 0.5]),
    Point3{Float64}(C * [-0.5, -0.5, 0.5]),
    Point3{Float64}(C * [0.5, -0.5, 0.5]),
    Point3{Float64}(C * [0.5, 0.5, -0.5]),
    Point3{Float64}(C * [-0.5, 0.5, -0.5]),
    Point3{Float64}(C * [-0.5, -0.5, -0.5]),
    Point3{Float64}(C * [0.5, -0.5, -0.5])
]   

```
