cormullion / Thebes.jl

Thebes.jl is a simple little package that provides 3D services to Luxor.jl.
https://cormullion.github.io/Thebes.jl/
Other
31 stars 3 forks source link

carpet() gets cut at some viewpoints #5

Open schneiderfelipe opened 3 years ago

schneiderfelipe commented 3 years ago

The following code produces the image below, which I find surprising:

using Thebes, Luxor

@draw begin
    origin()
    background("grey10")
    θ = π/4
    ϕ = π/3
    eyepoint(Point3D(250cos(θ) * sin(ϕ), 250sin(θ) * sin(ϕ), 100cos(ϕ)))
    sethue("grey90")
    carpet(300)
    axes3D()
    for i in 1:300
        sethue("lightblue")
        randpoint3D = Point3D(rand(0.0:200, 3)...)
        pin(randpoint3D,
            gfunction=(_, p2) -> circle(p2, 2, :fill)
        )
        sethue("grey30")
        pin(Point3D(randpoint3D.x, randpoint3D.y, 0),
            gfunction=(_, p2) -> circle(p2, 2, :fill)
        )
    end
end 1000 1000

surprising

By changing θ and ϕ, less or more of the xy circle gets shown. The same thing happens with @png and @svg. Am I missing something?

Versions used:

(@v1.4) pkg> status Thebes Luxor
Status `~/.julia/environments/v1.4/Project.toml`
  [ae8d54c2] Luxor v2.7.0
  [8b424ff8] Thebes v0.4.0
cormullion commented 3 years ago

Hi there! I think this might just be how the clipping works when there's no perspective. In your example, you're

distance(Point3D(0, 0, 0), eyepoint()) = 222.2048604328897

222 units from the origin, but the carpet has radius 150, so at the front it's very close, probably too near to you to be drawn, and so it gets clipped.

If you turn on the perspective, lines can be distorted more:

    perspective(150)

and you'll get a better idea of how close you are:

Screenshot 2021-01-08 at 10 46 28

I do struggle with this 3D stuff, I admit. While I consider Thebes.jl a bit of a toy, I occasionally find it useful for the odd logo... :)

schneiderfelipe commented 3 years ago

Now I see. Thanks for the explanation!

While I consider Thebes.jl a bit of a toy, I occasionally find it useful for the odd logo... :)

I think Thebes.jl is awesome! I never managed to use Makie.jl to produce a scene piece by piece like it is possible with Thebes.jl (like drawing spheres, etc.). I'm interested in using Julia to produce scientific diagrams/animations, small figures for publications, etc. Thebes.jl seems perfect for that.

cormullion commented 3 years ago

Ha, I'm not very confident that Thebes will satisfy your needs, but I'm very happy to help you establish its limitations... :)