# There's a hole in a sphere generated by makie.surface

**URL:** <https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555>\
**Category:** Visualization\
**Tags:** bug, mesh, makie, sphere\
**Created:** [August 24, 2024, 10:43am UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555 "2024-08-24T10:43:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![xczphysics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xczphysics/32/211370_2.png) [@xczphysics](https://discourse.julialang.org/u/xczphysics)\
**Post date:** [August 24, 2024, 10:43am UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/1 "2024-08-24T10:43:02Z")

</div>

Take a look at this Eye !!!

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/9/0999ff90c37c073295839dd3442581b4ff8bbf98.jpeg)

Unlike `mesh(spheremesh)` method, current `surface(x,y,z)` method leaves a **circular hole** at the **north pole** of the ball, see:

- [Transparent surfaces in Makie.jl - #2 by sdanisch](https://discourse.julialang.org/t/transparent-surfaces-in-makie-jl/15775/2)
- [CairoMakie invert\_normals = true not working](https://discourse.julialang.org/t/cairomakie-invert-normals-true-not-working/104496)
- [How to get a Semi transparent sphere in Makie? - #2 by p\_f](https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944/2)

and sometimes leave an **1. circular hole / 2. irregular hole** composed of several **black triangular faces** at the **south pole** as well, see:

1. [How to Create a 3D-Transparent Cylinder with GLMakie or Plots if possible?](https://discourse.julialang.org/t/how-to-create-a-3d-transparent-cylinder-with-glmakie-or-plots-if-possible/92099)
2. [Drawing an ellipsoid to visualize a tensor - #11 by AndiMD](https://discourse.julialang.org/t/drawing-an-ellipsoid-to-visualize-a-tensor/31286/11)

a MWE would be

```julia
# https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944/2?u=xczphysics

using Colors, GeometryBasics #versions 0.10.5, 0.12.11, 0.9.20
using GLMakie
GLMakie.activate!()
# A sphere
n = 13

function gan_sphere_points(num, Θ_L, Θ_R)
    r = 1.0f0
    Θ = range(Θ_L, Θ_R, num)
    Φ = range(-π, π, num)
    x = [r * sin(θ) * cos(ϕ) for ϕ in Φ, θ in Θ] # 这里的 ϕ,θ 顺序会影响 可否穿透球表面获取位置
    y = [r * sin(θ) * sin(ϕ) for ϕ in Φ, θ in Θ]
    z = [r * cos(θ) for ϕ in Φ, θ in Θ]

    # return [x, y, z]

    # 应用旋转变换
    rotation_angle = -π/3 # 45度
    rotation_matrix = [cos(rotation_angle) 0 -sin(rotation_angle);
                    0 1 0;
                    sin(rotation_angle) 0 cos(rotation_angle)]

    x_rotated = rotation_matrix[1,1] .* x + rotation_matrix[1,3] .* z
    y_rotated = y
    z_rotated = rotation_matrix[3,1] .* x + rotation_matrix[3,3] .* z

    return [x_rotated, y_rotated, z_rotated]
end

sphere_points = gan_sphere_points(n, 0, π)
fig, ax, p = GLMakie.surface(sphere_points...,
    color=sphere_points[3], invert_normals=true, transparency=true)

fig

```

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 24, 2024, 12:12pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/2 "2024-08-24T12:12:03Z")

</div>

If your ultimate goal is to simply show a Sphere or Ellipsoid after rotations, take a look at Meshes.jl. In particular, you can

```julia
using Meshes
import GLMakie as Mke

ellipsoid = Ellipsoid(...)

viz(ellipsoid)

```

You can further rotate the ellipsoid with the `Rotate` transform:

```julia
ellipsoid |> Rotate(...) |> viz

```

You need both triangles and quadrangles to properly discretize the sphere/ellipsoid. The `Makie.surface` displays meshes that are made of quadrangles.

---

<div class="post-metadata">

**Author:** ![xczphysics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xczphysics/32/211370_2.png) [@xczphysics](https://discourse.julialang.org/u/xczphysics)\
**Post date:** [August 24, 2024, 4:36pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/3 "2024-08-24T16:36:38Z")

</div>

**Thanks for your kind hint!** During my testing,

this rotates correctly:

```julia
using Meshes, Rotations, GLMakie
Ellipsoid((3., 2., 1.), (0., 0., 0.), RotXYZ(π/4, π/5, π/3)) |> viz

```

but the following doesn’t even rotate:

```julia
using Meshes, Rotations, GLMakie
Ellipsoid((3., 2., 1.)) |> Rotate(RotXYZ(π/4, π/5, π/3)) |> viz

```

for what? args works, while the operator fails to work…

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 24, 2024, 4:42pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/4 "2024-08-24T16:42:46Z")

</div>

Can you please try to call `discretize` before `viz`? This will force the discretization of the `Ellipsoid` into a mesh. If it works, then this is an issue on our side. I am far from my computer now.

---

<div class="post-metadata">

**Author:** ![xczphysics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xczphysics/32/211370_2.png) [@xczphysics](https://discourse.julialang.org/u/xczphysics)\
**Post date:** [August 24, 2024, 4:57pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/5 "2024-08-24T16:57:08Z")

</div>

it works 🙂 🙂

```julia
using Meshes, Rotations, GLMakie
discretize(Ellipsoid((3., 2., 1.)), RegularDiscretization(10,10)) |> Rotate(RotXYZ(π/4, π/5, π/3)) |> viz

```

and the kwarg `color = 1:nelements(mesh)` of the method `viz` seems to need `discretize(mesh)` first too:

```julia
using Meshes, Rotations, GLMakie
ellipsoid = Ellipsoid((3., 2., 1.), (0., 0., 0.), RotXYZ(π/4, π/5, π/3))
ellipsoid = discretize(ellipsoid, RegularDiscretization(10,10))
viz(ellipsoid, color = 1:nelements(ellipsoid), showsegments = true)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/f/0fd007057efed694307e22b30e26ce1c91174328.jpeg)

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 24, 2024, 4:58pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/6 "2024-08-24T16:58:59Z")

</div>

Fyi, starting/ending the polar angles at a small delta from the poles (instead of the `0` and `pi` endpoints) allows us to fill the holes as much as we like.

```julia
δ = 1e-6
sphere_points = gan_sphere_points(n, δ, π-δ)

```

Of course we also need to increase `n` to make the sphere smooth and round.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 24, 2024, 5:08pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/7 "2024-08-24T17:08:04Z")

</div>

Nice that it works. So the `Rotate` doesn’t change the visualization? Mind opening an issue in Meshes.jl so that we can take a look over the week?

---

<div class="post-metadata">

**Author:** ![xczphysics](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xczphysics/32/211370_2.png) [@xczphysics](https://discourse.julialang.org/u/xczphysics)\
**Post date:** [August 24, 2024, 5:14pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/8 "2024-08-24T17:14:23Z")

</div>

OOObservant 👀 and SSSmart 🧠 !!!

Compared to **the _x,y_ coordinate of the eye’s pupil always = 0,0** (when the sphere is not rotated), I had also found **the _x,y_ coordinate of the “ass” → 0,0 but mostly ≠ 0,0** may be the reason why the “ass” sew itself, but never took a closer look into it…

Thanks bro, this is a beautiful shortcut.  
The solution to this problem should be gifted to you.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 24, 2024, 5:38pm UTC](https://discourse.julialang.org/t/theres-a-hole-in-a-sphere-generated-by-makie-surface/118555/9 "2024-08-24T17:38:12Z")

</div>

Glad it helped. I am not sure if I totally followed your description, but as Émile Zola once said, the celestial sphere and the ass are two great levers.
