Skip to content

Commit 081566f

Browse files
authored
Add Makie plotting extension (#199)
* Add plotting methods * Plot panels * Plot body aero * Add transforms * Rebase example * No specific data type * Return plots * Remove white stuff
1 parent 38be704 commit 081566f

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
3131

3232
[weakdeps]
3333
ControlPlots = "23c2ee80-7a9e-4350-b264-8e670f12517c"
34+
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
3435

3536
[extensions]
3637
VortexStepMethodControlPlotsExt = "ControlPlots"
38+
VortexStepMethodMakieExt = "Makie"
3739

3840
[compat]
3941
Aqua = "0.8"
@@ -51,6 +53,7 @@ Interpolations = "0.15, 0.16"
5153
LaTeXStrings = "1"
5254
LinearAlgebra = "1"
5355
Logging = "1"
56+
Makie = "0.24.6"
5457
Measures = "0.3"
5558
NonlinearSolve = "4.8.0"
5659
Parameters = "0.12"

ext/VortexStepMethodMakieExt.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module VortexStepMethodMakieExt
2+
using Makie, VortexStepMethod
3+
4+
"""
5+
plot!(ax, panel::VortexStepMethod.Panel; kwargs...)
6+
7+
Plot a single `Panel` as a `mesh`.
8+
The corner points are ordered as: LE1, TE1, TE2, LE2.
9+
This creates two triangles: (LE1, TE1, TE2) and (LE1, TE2, LE2).
10+
"""
11+
function Makie.plot!(ax, panel::VortexStepMethod.Panel; color=(:red, 0.2), R_b_w=nothing, T_b_w=nothing, kwargs...)
12+
plots = []
13+
points = [Point3f(panel.corner_points[:, i]) for i in 1:4]
14+
if !isnothing(R_b_w) && !isnothing(T_b_w)
15+
points = [Point3f(R_b_w * p + T_b_w) for p in points]
16+
end
17+
faces = [Makie.GLTriangleFace(1, 2, 3), Makie.GLTriangleFace(1, 3, 4)]
18+
p = mesh!(ax, points, faces; color, transparency=true, kwargs...)
19+
push!(plots, p)
20+
border_points = [points..., points[1]]
21+
p = lines!(ax, border_points; color=:black, transparency=true, kwargs...)
22+
push!(plots, p)
23+
return plots
24+
end
25+
26+
"""
27+
plot!(ax, body::VortexStepMethod.BodyAerodynamics; kwargs...)
28+
29+
Plot a `BodyAerodynamics` object by plotting each of its panels.
30+
"""
31+
function Makie.plot!(ax, body::VortexStepMethod.BodyAerodynamics; color=(:red, 0.2), R_b_w=nothing, T_b_w=nothing, kwargs...)
32+
plots = []
33+
for panel in body.panels
34+
p = Makie.plot!(ax, panel; color, R_b_w, T_b_w, kwargs...)
35+
push!(plots, p)
36+
end
37+
return plots
38+
end
39+
40+
function Makie.plot(panel::VortexStepMethod.Panel; size = (1200, 800), kwargs...)
41+
fig = Figure(; size)
42+
ax = Axis3(fig[1, 1]; aspect = :data,
43+
xlabel = "X", ylabel = "Y", zlabel = "Z",
44+
azimuth = 9/8*π, zoommode = :cursor, viewmode = :fit,
45+
)
46+
47+
plot!(ax, panel; kwargs...)
48+
return fig
49+
end
50+
51+
function Makie.plot(body_aero::VortexStepMethod.BodyAerodynamics; size = (1200, 800),
52+
limitmargin = 0.1, kwargs...)
53+
fig = Figure(; size)
54+
ax = Axis3(fig[1, 1]; aspect = :data,
55+
xlabel = "X", ylabel = "Y", zlabel = "Z",
56+
azimuth = 9/8*π, zoommode = :cursor, viewmode = :fit,
57+
xautolimitmargin=(limitmargin, limitmargin),
58+
yautolimitmargin=(limitmargin, limitmargin),
59+
zautolimitmargin=(limitmargin, limitmargin),
60+
)
61+
plot!(ax, body_aero; kwargs...)
62+
return fig
63+
end
64+
65+
end

0 commit comments

Comments
 (0)