|
10 | 10 | using CairoMakie |
11 | 11 | using Colors |
12 | 12 | using Distributions |
| 13 | +using GeometryBasics |
13 | 14 | using Meshes |
14 | 15 | using MeshIntegrals |
15 | 16 | using Unitful |
|
37 | 38 | Sector(rs, phis) = Sector(rs..., phis...) |
38 | 39 |
|
39 | 40 | # Sector -> Ngon |
40 | | -function Ngon(sector::Sector; N=8) |
| 41 | +function _Ngon(sector::Sector; N=8) |
41 | 42 | ϕs = range(sector.phi_a, sector.phi_b, length=N) |
42 | 43 | arc_o = [point(sector.r_outer, ϕ) for ϕ in ϕs] |
43 | 44 | arc_i = [point(sector.r_inner, ϕ) for ϕ in reverse(ϕs)] |
|
51 | 52 |
|
52 | 53 | _poly(circle::Meshes.Circle; N=32) = [(_Point3f(circle(t)) for t in range(0, 1, length=N))...] |
53 | 54 | _poly(ngon::Meshes.Ngon) = [(_Point3f(pt) for pt in ngon.vertices)...] |
| 55 | +
|
| 56 | +_poly2d(circle::Meshes.Circle; N=32) = [(_Point2f(circle(t)) for t in range(0, 1, length=N))...] |
| 57 | +_poly2d(ngon::Meshes.Ngon) = [(_Point2f(pt) for pt in ngon.vertices)...] |
54 | 58 | ``` |
55 | 59 |
|
56 | 60 | ## Modeling the Dartboard |
@@ -81,36 +85,39 @@ board_colors = hcat(ring1, ring2, ring3, ring4) |
81 | 85 |
|
82 | 86 | # Sector geometries |
83 | 87 | sector_width = 2π/20 |
84 | | -phis_a = range(0, 2π, 20) .- sector_width/2 |
85 | | -phis_b = range(0, 2π, 20) .+ sector_width/2 |
| 88 | +sector_centers = [n * sector_width for n in 0:19] |
| 89 | +phis_a = sector_centers .- sector_width/2 |
| 90 | +phis_b = sector_centers .+ sector_width/2 |
86 | 91 | phis = Iterators.zip(phis_a, phis_b) |
87 | 92 | rs = [ (16mm, 99mm), (99mm, 107mm), (107mm, 162mm), (162mm, 170mm) ] |
88 | 93 | board_coords = Iterators.product(phis, rs) |
89 | 94 | board_sectors = map(((phis, rs),) -> Sector(rs, phis), board_coords) |
90 | | -board_ngons = Ngon.(board_sectors) |
| 95 | +board_ngons = _Ngon.(board_sectors) |
91 | 96 |
|
92 | 97 | # Consolidate the Sectors |
93 | 98 | sector_data = Iterators.zip(board_ngons, board_points, board_colors) |
94 | 99 | board_regions = map(args -> ScoredRegion(args...), sector_data) |
95 | 100 |
|
96 | 101 | # Center region |
97 | 102 | bullseye_inner = ScoredRegion(Meshes.Circle(dartboard_plane, 6.35mm), 50, red) |
98 | | -bullseye_outer = ScoredRegion(Ngon(Sector((6.35mm, 16.0mm), (0.0, 2π)); N=32), 25, green) |
| 103 | +bullseye_outer = ScoredRegion(_Ngon(Sector((6.35mm, 16.0mm), (0.0, 2π)); N=32), 25, green) |
99 | 104 |
|
100 | 105 | # Get set of all regions |
101 | 106 | all_regions = vcat(vec(board_regions), bullseye_inner, bullseye_outer) |
102 | 107 |
|
103 | | -# Initialize a 3D figure |
104 | 108 | fig = Figure() |
105 | | -#ax = LScene(fig[1, 1], scenekw=(show_axis=true,)) |
106 | | -ax = Axis3(fig[1, 1]; xlabel="X", ylabel="Y", zlabel="Z") |
107 | | -limits!(ax, -0.1..0.1, -1.5..1.5, 0..3; fixed=true) |
108 | | -
|
109 | | -# Populate the dart board scored regions |
110 | | -for region in all_regions |
111 | | - poly!(ax, _poly(region.geometry), color=region.color) |
| 109 | +ax = Axis(fig[1, 1], xlabel="y [m]", ylabel="z [m]") |
| 110 | +ax.aspect = DataAspect() |
| 111 | +
|
| 112 | +for region in board_regions |
| 113 | + pts = _poly2d(region.geometry) |
| 114 | + poly!(ax, pts, color=region.color) |
| 115 | + |
| 116 | + centerPt = centroid(region.geometry) |
| 117 | + center = ustrip.(u"m", [centerPt.coords.y, centerPt.coords.z]) |
| 118 | + text!(ax, string(region.points), position=Point2f(center...), align=(:center,:center), color=:blue, fontsize=10) |
112 | 119 | end |
113 | | -
|
| 120 | + |
114 | 121 | fig |
115 | 122 | ``` |
116 | 123 |
|
|
0 commit comments