julia语言绘制三维xOy平面

1.源码实现

using CairoMakie
using LaTeXStrings

θ = deg2rad(225)
s = 0.5

Lx, Ly, Lz = s*0.8, s*1.0, s*1.0
ex = (Lx*cos(θ), Lx*sin(θ)); ey = (Ly, 0.0); ez = (0.0, Lz)

fig = Figure(size = (600, 600), backgroundcolor = :white)
ax = Axis(fig[1, 1];
    aspect = DataAspect(),
    limits = (-1.1, 1.1, -1.1, 1.1),        # ← limits 也同步收小
    xticks = (Float64[], String[]), yticks = (Float64[], String[]),
    xgridvisible = false, ygridvisible = false,
    leftspinevisible = false, rightspinevisible = false,
    bottomspinevisible = false, topspinevisible = false,
    backgroundcolor = :white
)

# ---- xOy 平面:平行四边形(同样乘 s)----
ux = (cos(θ), sin(θ)); uy = (1.0, 0.0)
ax_ = s * 1.00
ay_ = s * 1.25

P1 = ( ax_*ux[1] + ay_*uy[1],  ax_*ux[2] + ay_*uy[2])
P2 = ( ax_*ux[1] - ay_*uy[1],  ax_*ux[2] - ay_*uy[2])
P3 = (-ax_*ux[1] - ay_*uy[1], -ax_*ux[2] - ay_*uy[2])
P4 = (-ax_*ux[1] + ay_*uy[1], -ax_*ux[2] + ay_*uy[2])
xs = [P1[1], P2[1], P3[1], P4[1], P1[1]]
ys = [P1[2], P2[2], P3[2], P4[2], P1[2]]

lines!(ax, xs, ys; color = (:black, 0.7), linewidth = 1.2)

# ---- 轴线 ----
for (e, name, off) in ((ex, L"$x$", (-0.05*s, -0.05*s)),
    (ey, L"$y$", ( 0.02*s, -0.06*s)),
    (ez, L"$z$", (-0.10*s, -0.03*s)))
    arrows2d!(ax, [0.0], [0.0], [e[1]], [e[2]];
    shaftcolor = :black, shaftwidth = 2,
    tipcolor = :black, tipwidth = 14, tiplength = 18)
    text!(ax, e[1] + off[1], e[2] + off[2];
        text = name, fontsize = 26, color = :black,
        align = (:center, :center)
    )
end

scatter!(ax, [0.0], [0.0]; color = :black, markersize = 8, marker = :circle)
    text!(ax, 0.02, -0.12*s; text = L"$O$", fontsize = 24,
    color = :black, align = (:center, :center)
)

save("axes3d_plane.png", fig; px_per_unit = 2)

2.结果展示

axes3d_plane.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容