Missing `isconvex` method for `Pyramid`
enhancementgood first issuefeature
I was looking at some pyramids and tried to test if they intersect with other geometries. Currently it throws error with missing method for `insconvex`:
```julia
julia> pir = Pyramid((0,0,0),(1,0,0),(1,1,0),(0,1,0),(0,0,1));
julia> b2d = Box((0.1, 0.1, 0.2), (0.2,0.2,0.2));
julia> intersects(b2d, pir)
ERROR: MethodError: no method matching isconvex(::Pyramid{CoordRefSystems.Cartesian3D{CoordRefSystems.NoDatum, Unitful.Quantity{…}}, 𝔼{3}})
The function `isconvex` exists, but no method is defined for this combination of argument types.
Closest candidates are:
isconvex(::Triangle)
@ Meshes C:\Users\csert\.julia\dev\Meshes\src\predicates\isconvex.jl:57
isconvex(::Quadrangle)
@ Meshes C:\Users\csert\.julia\dev\Meshes\src\predicates\isconvex.jl:75
isconvex(::Box)
@ Meshes C:\Users\csert\.julia\dev\Meshes\src\predicates\isconvex.jl:35
...
Stacktrace:
[1] intersects(g₁::Box{𝔼{3}, CoordRefSystems.Cartesian3D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}}, g₂::Pyramid{CoordRefSystems.Cartesian3D{CoordRefSystems.NoDatum, Unitful.Quantity{Float64, 𝐋, Unitful.FreeUnits{(m,), 𝐋, nothing}}}, 𝔼{3}})
@ Meshes C:\Users\csert\.julia\dev\Meshes\src\predicates\intersects.jl:79
[2] top-level scope
@ REPL[6]:1
Some type information was truncated. Use `show(err)` to see complete types.
```
The easiest solution for me seems to be copying the implementation from `Hexahedron`:
```julia
isconvex(p::Pyramid) = all(isconvex, boundary(p))
```
With this change, it works:
```julia
julia> intersects(b2d, pir)
true
```
I can construct a concave pyramid, which I guess doesn't make sense, but the convexity is correct:
```julia
julia> pir2 = Pyramid((0,0,0),(1,0,0),(0.25,0.25,0),(0,1,0),(0,0,1))
Pyramid
├─ Point(x: 0.0 m, y: 0.0 m, z: 0.0 m)
├─ Point(x: 1.0 m, y: 0.0 m, z: 0.0 m)
├─ Point(x: 0.25 m, y: 0.25 m, z: 0.0 m)
├─ Point(x: 0.0 m, y: 1.0 m, z: 0.0 m)
└─ Point(x: 0.0 m, y: 0.0 m, z: 1.0 m)
julia> isconvex(pir2)
false
```
Would that be a correct implementation? I don't understand this topic well enough to see this right away.
6 条评论