Skip to content

Commit

Permalink
Add missing Frustum methods
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Mar 28, 2024
1 parent b387402 commit 28ffc65
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 55 deletions.
22 changes: 22 additions & 0 deletions docs/src/algorithms/refinement.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ viz(fig[2,2], ref3, showfacets = true)
fig
```

## RegularRefinement

```@docs
RegularRefinement
```

```@example refinement
grid = CartesianGrid(10, 10)
# refine three times
ref1 = refine(grid, RegularRefinement(2, 2))
ref2 = refine(ref1, RegularRefinement(3, 2))
ref3 = refine(ref2, RegularRefinement(2, 3))
fig = Mke.Figure(size = (800, 800))
viz(fig[1,1], grid, showfacets = true)
viz(fig[1,2], ref1, showfacets = true)
viz(fig[2,1], ref2, showfacets = true)
viz(fig[2,2], ref3, showfacets = true)
fig
```

## Catmull-Clark

```@docs
Expand Down
61 changes: 17 additions & 44 deletions docs/src/geometries/primitives.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,80 +68,58 @@ Box
Box((0.,0.,0.), (1.,1.,1.)) |> viz
```

### Ball
### Ball/Sphere

```@docs
Ball
```

```@example primitives
Ball((0.,0.,0.), 1.) |> viz
```

### Sphere

```@docs
Sphere
```

```@example primitives
Sphere((0.,0.,0.), 1.) |> viz
Ball((0.,0.,0.), 1.) |> viz
```

### Disk
### Disk/Circle

```@docs
Disk
```

### Circle

```@docs
Circle
```

### Cylinder
### Cylinder/CylinderSurface

```@docs
Cylinder
```

```@example primitives
Cylinder(1.0) |> viz
```

### CylinderSurface

```@docs
CylinderSurface
```

```@example primitives
CylinderSurface(1.0) |> viz
Cylinder(1.0) |> viz
```

### Cone
### Cone/ConeSurface

```@docs
Cone
ConeSurface
```

### ConeSurface

```@docs
ConeSurface
```@example primitives
Cone(Disk(Plane((0,0,0), (0,0,1)), 1), (0,0,1)) |> viz
```

### Frustum
### Frustum/FrustumSurface

```@docs
Frustum
FrustumSurface
```

### FrustumSurface

```@docs
FrustumSurface
```@example primitives
Frustum(
Disk(Plane((0,0,0), (0,0,1)), 2),
Disk(Plane((0,0,10), (0,0,1)), 1)
) |> viz
```

### Torus
Expand All @@ -161,10 +139,5 @@ ParaboloidSurface
```

```@example primitives
a = Point3(5, 2, 4)
r = 1.0
f = 0.25
par = ParaboloidSurface(a, r, f)
disk = Disk(Plane(a, Vec(0, 0, 1)), r)
viz([par, disk], color = [:green, :gray])
ParaboloidSurface((5., 2., 4.), 1.0, 0.25) |> viz
```
18 changes: 9 additions & 9 deletions src/boundary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,20 @@ boundary(d::Disk) = Circle(plane(d), radius(d))

boundary(::Circle) = nothing

boundary(c::Cone) = ConeSurface(base(c), apex(c))

boundary(::ConeSurface) = nothing

boundary(c::Cylinder) = CylinderSurface(bottom(c), top(c), radius(c))

boundary(::CylinderSurface) = nothing

boundary(::ParaboloidSurface) = nothing
boundary(c::Cone) = ConeSurface(base(c), apex(c))

function boundary(p::Pyramid)
indices = [(4, 3, 2, 1), (5, 1, 2), (5, 4, 1), (5, 3, 4), (5, 2, 3)]
SimpleMesh(pointify(p), connect.(indices))
end
boundary(::ConeSurface) = nothing

boundary(f::Frustum) = FrustumSurface(bottom(f), top(f))

boundary(::FrustumSurface) = nothing

boundary(::ParaboloidSurface) = nothing

boundary(::Torus) = nothing

boundary(s::Segment) = Multi(pointify(s))
Expand All @@ -100,6 +95,11 @@ function boundary(h::Hexahedron)
SimpleMesh(pointify(h), connect.(indices))
end

function boundary(p::Pyramid)
indices = [(4, 3, 2, 1), (5, 1, 2), (5, 4, 1), (5, 3, 4), (5, 2, 3)]
SimpleMesh(pointify(p), connect.(indices))
end

function boundary(m::Multi)
bounds = [boundary(geom) for geom in parent(m)]
valid = filter(!isnothing, bounds)
Expand Down
2 changes: 1 addition & 1 deletion src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ include("primitives/disk.jl")
include("primitives/circle.jl")
include("primitives/cylinder.jl")
include("primitives/cylindersurface.jl")
include("primitives/paraboloidsurface.jl")
include("primitives/cone.jl")
include("primitives/conesurface.jl")
include("primitives/frustum.jl")
include("primitives/frustumsurface.jl")
include("primitives/paraboloidsurface.jl")
include("primitives/torus.jl")
6 changes: 5 additions & 1 deletion src/primitives/frustum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ end

Frustum(bot::Disk{T}, top::Disk{T}) where {T} = Frustum{T}(bot, top)

paramdim(::Type{<:Frustum}) = 3

bottom(f::Frustum) = f.bot

top(f::Frustum) = f.top

height(f::Frustum) = norm(center(bottom(f)) - center(top(f)))
height(f::Frustum) = height(boundary(f))

axis(f::Frustum) = axis(boundary(f))

function Random.rand(rng::Random.AbstractRNG, ::Random.SamplerType{Frustum{T}}) where {T}
bottom = rand(rng, Disk{T})
Expand Down

0 comments on commit 28ffc65

Please sign in to comment.