https://hrubos.tech/blogy/content/images/20251219203250-zotrvacnik_3d_tlmenie3.gif

https://hrubos.tech/blogy/content/images/20251219203518-zotrvacnik_3d_tlmenie2.gif
############################################################
# 3D NEVYVÁŽENÝ ZOTRVAČNÍK S TLMENÍM – JULIA (OPRAVA)
############################################################
using Pkg
println("➡️ Inštalujem potrebné balíky (ak chýbajú)...")
Pkg.add([
"DifferentialEquations",
"GLMakie",
"GeometryBasics"
])
############################################################
# BALÍKY
############################################################
using DifferentialEquations
using GLMakie
using GeometryBasics # <-- DÔLEŽITÉ
############################################################
# 3D NEVYVÁŽENÝ ZOTRVAČNÍK S TLMENÍM – JULIA (FINÁL ✔)
############################################################
using Pkg
println("➡️ Inštalujem potrebné balíky (ak chýbajú)...")
Pkg.add([
"DifferentialEquations",
"GLMakie",
"GeometryBasics"
])
############################################################
# BALÍKY
############################################################
using DifferentialEquations
using GLMakie
using GeometryBasics
############################################################
# FYZIKÁLNY MODEL
############################################################
M = 1.0
m = 0.5
R = 0.5
g = 0
c = 0.10
I = (M + m) * R^2
function flywheel_damped!(du, u, p, t)
θ, ω = u
du[1] = ω
du[2] = -(m * g * R / I) * sin(θ) - (c / I) * ω
end
############################################################
# SIMULÁCIA
############################################################
u0 = [0.0, 18.0]
tspan = (0.0, 12.0)
prob = ODEProblem(flywheel_damped!, u0, tspan)
sol = solve(prob, Tsit5(), saveat = 0.03)
############################################################
# FIGURE + AXIS3
############################################################
fig = Figure(size = (1200, 700))
# 3D animácia
ax3d = Axis3(
fig[1, 1],
limits = (-0.7, 0.7, -0.7, 0.7, -0.2, 0.2),
aspect = (1, 1, 0.2),
title = "3D nevyvážený zotrvačník g==0, Rotujúca Zem s ťažkou vodnou priehradou",
xlabel = "X",
ylabel = "Y",
zlabel = "Z"
)
# Graf energie
axE = Axis(
fig[1, 2],
title = "Energia v čase",
xlabel = "čas [s]",
ylabel = "energia [J]"
)
############################################################
# ENERGIA – OBSERVABLES
############################################################
t_obs = Observable(Float64[])
Ek_obs = Observable(Float64[])
Ep_obs = Observable(Float64[])
Et_obs = Observable(Float64[])
lines!(axE, t_obs, Ek_obs, label = "Eₖ=E", color = :blue)
lines!(axE, t_obs, Ep_obs, label = "Eₚ=0=>g==0", color = :green)
lines!(axE, t_obs, Et_obs, label = "E=Eₖ+0", color = :red)
axislegend(axE)
############################################################
# GEOMETRIA
############################################################
disk = Cylinder(
Point3f(0, 0, -0.05),
Point3f(0, 0, 0.05),
R
)
mesh!(ax3d, disk, color = :lightgray)
lines!(ax3d, [-0.6, 0.6], [0, 0], [0, 0],
linewidth = 4, color = :black)
mass_pos = Observable(Point3f(R, 0, 0))
lines!(
ax3d,
lift(p -> [Point3f(0, 0, 0), p], mass_pos),
linewidth = 3,
color = :black
)
scatter!(
ax3d,
mass_pos,
markersize = 20,
color = :red
)
#######################################
############################################################
# ANIMÁCIA
############################################################
println("🎥 Renderujem animáciu + energiu...")
record(fig, "zotrvacnik_3d_tlmenie4.gif",
1:length(sol.t); framerate = 30) do i
θ = sol[1, i]
ω = sol[2, i]
t = sol.t[i]
# poloha prílepku
mass_pos[] = Point3f(R*cos(θ), R*sin(θ), 0)
# energie
Ek = 0.5 * I * ω^2
Ep = m * g * R * (1 - cos(θ)) # pri g=0 bude vždy 0
Et = Ek + Ep
push!(t_obs[], t)
push!(Ek_obs[], Ek)
push!(Ep_obs[], Ep)
push!(Et_obs[], Et)
notify(t_obs)
notify(Ek_obs)
notify(Ep_obs)
notify(Et_obs)
end
############################################################
# KONIEC
############################################################
println("✅ Hotovo!")
println("📁 Výstup: zotrvacnik_3d_tlmenie4.gif")
println()
println("Stlač ENTER pre ukončenie...")
readline()
Niektorí sa pýtajú, prečo je Ep==0? No a aká je výška planéty od daného telesa? Je to od Mesiaca alebo od Supernovy? Od Galaxie? Odkiaľ? Preto Ep==0

Comments “Čo sa deje s Energiou planéty Zem, ak postavíme na povrch Zeme ťažkú priehradu ako je tá čínska/americká? Pozrime simuláciu:”