绘图-着陆表面呈现角度

时间:2019-03-03 16:24:54

标签: plot julia plotly

下面是我在火星表面的代码。

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)

如您可能从代码中解释的那样,我为未来的火箭飞船设置了三个着陆区(虚线)。但是,三个着陆区中的两个都与它们成一定角度,因此我将无法在其上着陆。有人知道如何使虚线区域变直吗?

1 个答案:

答案 0 :(得分:0)

对于有类似问题的任何人: 解决方案非常简单,在随机地形中,我忘记将数组缩小一个值,因此随机地形的最后一个值将覆盖着陆点的第一个值。