Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export
angles,
innerangles,
normal,
base,
≗,

# multi-geometries
Expand Down
11 changes: 9 additions & 2 deletions src/geometries/polytopes/pyramid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
Pyramid(p1, p2, p3, p4, p5)

A pyramid with points `p1`, `p2`, `p3`, `p4`, `p5`.
The first four points correspond to the vertices of the base and the last is the top of the pyramid.
Please note, that the current implementation doesn't handle non-convex bases correctly.
"""
@polytope Pyramid 3 5

nvertices(::Type{<:Pyramid}) = 5

function base(p::Pyramid)
a, b, c, d, o = p.vertices
Quadrangle(a, b, c, d)
end

==(p₁::Pyramid, p₂::Pyramid) = p₁.vertices == p₂.vertices

Base.isapprox(p₁::Pyramid, p₂::Pyramid; atol=atol(lentype(p₁)), kwargs...) =
Expand All @@ -20,8 +27,8 @@ function (pyramid::Pyramid)(u, v, w)
if (u < 0 || u > 1) || (v < 0 || v > 1) || (w < 0 || w > 1)
throw(DomainError((u, v, w), "pyramid(u, v, w) is not defined for u, v, w outside [0, 1]³."))
end
a, b, c, d, o = vertices(pyramid)
q = Quadrangle(a, b, c, d)
o = last(pyramid.vertices)
q = base(pyramid)
s = Segment(q(u, v), o)
s(w)
end
2 changes: 2 additions & 0 deletions src/predicates/isconvex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ _isconvex(p::Polygon, ::Val{3}) = isconvex(proj2D(p))

isconvex(h::Hexahedron) = all(isconvex, boundary(h))

isconvex(p::Pyramid) = isconvex(base(p))

isconvex(m::Multi) = isapproxequal(measure(convexhull(m)), measure(m))

# --------------
Expand Down
1 change: 1 addition & 0 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ end
equaltest(p)
isapproxtest(p)
vertextest(p)
@test base(p) == Quadrangle(cart(0, 0, 0), cart(1, 0, 0), cart(1, 1, 0), cart(0, 1, 0))

p = Pyramid(cart(0, 0, 0), cart(1, 0, 0), cart(1, 1, 0), cart(0, 1, 0), cart(0, 0, 1))
@test sprint(show, p) == "Pyramid((x: 0.0 m, y: 0.0 m, z: 0.0 m), ..., (x: 0.0 m, y: 0.0 m, z: 1.0 m))"
Expand Down
16 changes: 16 additions & 0 deletions test/predicates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,22 @@ end
@test isconvex(h0)
@test isconvex(h1)
@test isconvex(h2)
p = Pyramid(
cart(0, 0, 0),
cart(1, 0, 0),
cart(1, 1, 0),
cart(0, 1, 0),
cart(0, 0, 1)
)
@test isconvex(p)
p = Pyramid(
cart(0, 0, 0),
cart(1, 0, 0),
cart(0.25, 0.25, 0),
cart(0, 1, 0),
cart(0, 0, 1)
)
@test !isconvex(p)
end

@testitem "issubset" setup = [Setup] begin
Expand Down
Loading