Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/Meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ export
angles,
innerangles,
normal,
base,
apex,
≗,

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

A pyramid with points `p1`, `p2`, `p3`, `p4`, `p5`.

The first four points form the base and the last is the apex.
"""
@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

apex(p::Pyramid) = last(p.vertices)

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

Base.isapprox(p₁::Pyramid, p₂::Pyramid; atol=atol(lentype(p₁)), kwargs...) =
all(isapprox(v₁, v₂; atol, kwargs...) for (v₁, v₂) in zip(p₁.vertices, p₂.vertices))

function (pyramid::Pyramid)(u, v, w)
function (p::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]³."))
throw(DomainError((u, v, w), "p(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)
q = base(p)
o = apex(p)
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
2 changes: 2 additions & 0 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,8 @@ 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))
@test apex(p) == cart(0, 0, 1)

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
4 changes: 4 additions & 0 deletions test/predicates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ 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