Ниже приведен мой код поверхности Марса.
using Plots
using ForwardDiff
gr(fmt=:png)
function mars_surface()
surfaceN = rand(2:30)
land = zeros(Int64, surfaceN, 2)
# Creating three flat landing sites at least 1000m long
landing_site_1 = rand(2:surfaceN-5)
land[landing_site_1, 1] = rand(2000:4000)
land[landing_site_1+1, 1] = min(land[landing_site_1, 1] + rand(1000:2000), 20999)
land[landing_site_1+1, 2] = land[landing_site_1, 2] = rand(2000:3000)
landing_site_2 = rand(2:surfaceN-3)
land[landing_site_2, 1] = rand(7000:9000)
land[landing_site_2+1, 1] = min(land[landing_site_2, 1] + rand(1000:2000), 20999)
land[landing_site_2+1, 2] = land[landing_site_2, 2] = rand(1000:2000)
landing_site_3 = rand(2:surfaceN-1)
land[landing_site_3, 1] = rand(11000:13000)
land[landing_site_3+1, 1] = min(land[landing_site_3, 1] + rand(1000:2000), 20999)
land[landing_site_3+1, 2] = land[landing_site_3, 2] = rand(4000:5000)
# fill in the rest of the terrain
for i=1:landing_site_1-1
land[i, 1] = (land[landing_site_1,1] ÷ landing_site_1) * i
land[i, 2] = rand(2000:7000)
end
for i=landing_site_1+2:landing_site_2
land[i, 1] = (land[landing_site_1+1,1] +
(land[landing_site_2,1] - land[landing_site_1+1,1]) ÷ (surfaceN-3 - landing_site_1) * i)
land[i, 2] = rand(1:2000)
end
for i=landing_site_2+2:landing_site_3
land[i, 1] = (land[landing_site_2+1,1] +
(land[landing_site_3,1] - land[landing_site_2+1,1]) ÷ (surfaceN-1 - landing_site_2) * i)
land[i, 2] = rand(2000:7000)
end
for i=landing_site_3+2:surfaceN
land[i, 1] = (land[landing_site_3+1,1] +
(21000 - land[landing_site_3+1,1]) ÷ (surfaceN - landing_site_3) * i)
land[i, 2] = rand(1:2000)
end
# imposing boundary conditions
land[1, 1] = 0
land[end, 1] = 20999
return land, landing_site_1, landing_site_2, landing_site_3 end
function plot_surface(land, landing_site_1, landing_site_2, landing_site_3)
p = plot(land[1:landing_site_1, 1], land[1:landing_site_1, 2], c=:black, legend=false, background_colour=:orange)
plot!(land[landing_site_1+1:landing_site_2, 1], land[landing_site_1+1:landing_site_2, 2], c=:black, legend=false, background_colour=:orange)
plot!(land[landing_site_2+1:landing_site_3, 1], land[landing_site_2+1:landing_site_3, 2], c=:black, legend=false, background_colour=:orange)
plot!(land[landing_site_3+1:end, 1], land[landing_site_3+1:end, 2], c=:black, legend=false, background_colour=:orange)
plot!([land[landing_site_1, 1], land[landing_site_1+1, 1]],
[land[landing_site_1, 2], land[landing_site_1+1, 2]], c=:black, ls=:dash, background_colour=:orange)
plot!([land[landing_site_2, 1], land[landing_site_2+1, 1]],
[land[landing_site_2, 2], land[landing_site_2+1, 2]], c=:black, ls=:dash, background_colour=:orange)
plot!([land[landing_site_3, 1], land[landing_site_3+1, 1]],
[land[landing_site_3, 2], land[landing_site_3+1, 2]], c=:black, ls=:dash, background_colour=:orange)
xlims!(0, 21000)
ylims!(0, 10000)
return p
end
srand(123)
land, landing_site_1, landing_site_2, landing_site_3 = mars_surface()
plot_surface(land, landing_site_1, landing_site_2, landing_site_3)
Поскольку вы можете интерпретировать код, у меня есть три посадочные зоны для моего будущего ракетного корабля (пунктирные линии).Однако две из трех зон посадки имеют угол, под которым я не смогу посадить свой корабль.У кого-нибудь есть идеи, как сделать участки пунктирных линий прямыми?