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

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

``````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.

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

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

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

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

3 Likes

Thank you, Jules!

``````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)
``````

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

``````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])
]
``````