diff --git a/Project.toml b/Project.toml index 580b7d23..5e39dedb 100644 --- a/Project.toml +++ b/Project.toml @@ -31,9 +31,11 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [weakdeps] ControlPlots = "23c2ee80-7a9e-4350-b264-8e670f12517c" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" [extensions] VortexStepMethodControlPlotsExt = "ControlPlots" +VortexStepMethodMakieExt = "Makie" [compat] Aqua = "0.8" @@ -51,6 +53,7 @@ Interpolations = "0.15, 0.16" LaTeXStrings = "1" LinearAlgebra = "1" Logging = "1" +Makie = "0.24.6" Measures = "0.3" NonlinearSolve = "4.8.0" Parameters = "0.12" diff --git a/ext/VortexStepMethodMakieExt.jl b/ext/VortexStepMethodMakieExt.jl new file mode 100644 index 00000000..f72ea3d8 --- /dev/null +++ b/ext/VortexStepMethodMakieExt.jl @@ -0,0 +1,65 @@ +module VortexStepMethodMakieExt +using Makie, VortexStepMethod + +""" + plot!(ax, panel::VortexStepMethod.Panel; kwargs...) + +Plot a single `Panel` as a `mesh`. +The corner points are ordered as: LE1, TE1, TE2, LE2. +This creates two triangles: (LE1, TE1, TE2) and (LE1, TE2, LE2). +""" +function Makie.plot!(ax, panel::VortexStepMethod.Panel; color=(:red, 0.2), R_b_w=nothing, T_b_w=nothing, kwargs...) + plots = [] + points = [Point3f(panel.corner_points[:, i]) for i in 1:4] + if !isnothing(R_b_w) && !isnothing(T_b_w) + points = [Point3f(R_b_w * p + T_b_w) for p in points] + end + faces = [Makie.GLTriangleFace(1, 2, 3), Makie.GLTriangleFace(1, 3, 4)] + p = mesh!(ax, points, faces; color, transparency=true, kwargs...) + push!(plots, p) + border_points = [points..., points[1]] + p = lines!(ax, border_points; color=:black, transparency=true, kwargs...) + push!(plots, p) + return plots +end + +""" + plot!(ax, body::VortexStepMethod.BodyAerodynamics; kwargs...) + +Plot a `BodyAerodynamics` object by plotting each of its panels. +""" +function Makie.plot!(ax, body::VortexStepMethod.BodyAerodynamics; color=(:red, 0.2), R_b_w=nothing, T_b_w=nothing, kwargs...) + plots = [] + for panel in body.panels + p = Makie.plot!(ax, panel; color, R_b_w, T_b_w, kwargs...) + push!(plots, p) + end + return plots +end + +function Makie.plot(panel::VortexStepMethod.Panel; size = (1200, 800), kwargs...) + fig = Figure(; size) + ax = Axis3(fig[1, 1]; aspect = :data, + xlabel = "X", ylabel = "Y", zlabel = "Z", + azimuth = 9/8*π, zoommode = :cursor, viewmode = :fit, + ) + + plot!(ax, panel; kwargs...) + return fig +end + +function Makie.plot(body_aero::VortexStepMethod.BodyAerodynamics; size = (1200, 800), + limitmargin = 0.1, kwargs...) + fig = Figure(; size) + ax = Axis3(fig[1, 1]; aspect = :data, + xlabel = "X", ylabel = "Y", zlabel = "Z", + azimuth = 9/8*π, zoommode = :cursor, viewmode = :fit, + xautolimitmargin=(limitmargin, limitmargin), + yautolimitmargin=(limitmargin, limitmargin), + zautolimitmargin=(limitmargin, limitmargin), + ) + plot!(ax, body_aero; kwargs...) + return fig +end + +end