MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.4k stars 307 forks source link

`poly(::Vector{Point3f})` fails #4015

Open asinghvi17 opened 2 months ago

asinghvi17 commented 2 months ago

MWE:

poly(rand(Point2f, 10)) # works
poly(rand(Point3f, 10)) # does not work
ERROR: MethodError: no method matching poly_convert(::Float32, ::typeof(identity))

Closest candidates are:
  poly_convert(::Polygon, ::Any)
   @ Makie ~/.julia/dev/Makie/src/basic_recipes/poly.jl:85
  poly_convert(::AbstractGeometry{N, T}, ::Any) where {N, T}
   @ Makie ~/.julia/dev/Makie/src/basic_recipes/poly.jl:66
  poly_convert(::GeometryBasics.Mesh, ::Any)
   @ Makie ~/.julia/dev/Makie/src/basic_recipes/poly.jl:83
  ...

Stacktrace:
  [1] macro expansion
    @ ~/.julia/packages/StaticArrays/hLnPS/src/broadcast.jl:135 [inlined]
  [2] __broadcast
    @ ~/.julia/packages/StaticArrays/hLnPS/src/broadcast.jl:123 [inlined]
  [3] _broadcast
    @ ~/.julia/packages/StaticArrays/hLnPS/src/broadcast.jl:119 [inlined]
  [4] copy
    @ ~/.julia/packages/StaticArrays/hLnPS/src/broadcast.jl:60 [inlined]
  [5] materialize
    @ ./broadcast.jl:903 [inlined]
  [6] poly_convert(geometries::Point{3, Float32}, transform_func::Function)
    @ Makie ~/.julia/dev/Makie/src/basic_recipes/poly.jl:63

There is a method https://github.com/MakieOrg/Makie.jl/blob/c4e3b7b7271322330e2b4db424a5e096e5e9acf2/src/basic_recipes/poly.jl#L104-L111

which could be extended to 3d points. This worked in v0.20.

asinghvi17 commented 2 months ago

3d points could also be projected to the best fit plane, meshed, and then plotted. There are some linear algebra based solutions available from StackExchange

ffreyer commented 1 month ago

Isn't that part of the point of poly? To simplify things to 2D?

Also what should rand(Point3f, 10) even generate? These points don't lie on a plane, so they don't form a poylgon. We could do what earcut does

Note that Earcut is a 2D triangulation algorithm, and handles 3D data as if it was projected onto the XY plane (with Z component ignored).

but that means throwing away data the user gave us which I don't like.

jkrumbiegel commented 1 month ago

For me this still doesn't make sense, I think polygons only exist in 2d and the others are simply transformations into 3d. But then they should be plotted as such.

asinghvi17 commented 1 month ago

It's pretty convenient to define tilted/transformed polygons in 3D before plotting. Maybe rand(Point3f, 10) is a bad example but we can at least assume the user wants something reasonable.

Even an area light in e.g. RPRMakie might be defined this way in 3D (maybe as a rectangle with some rotation applied, or similar).