Hi,
This is second post related to https://discourse.julialang.org/t/glmakie-beginners-help-multiple-sliders-and-an-arrow/92113.
Currently: I am facing the following issues:
- Arrow heads pointing in the other direction: If I switch the base and head then it works fine[see figure of point 3].
arrows!(ax1, xbase, ybase, xhead, yhead)
#replaced with
arrows!(ax1, xhead, yhead, xbase, ybase)
- How to get the point coordinates on the figure? GLMakie does not recognize the following:
refpoint = @lift(Point($xreference,$yreference))
scatter!(refpoint, color = :red, markersize = 20)
arrowheadpoint = @lift(Point(xhead,yhead))
scatter!(arrowheadpoint, color = :blue, markersize = 20)
- Creating another figure with multiple arrows all together but still using sliders: is that possible? For example, create a slider with 3 points then plot all the arrows?
Is the following strategy correct?
#Create a observables list [refpoint1, refpoint2, refpoint3, refpoint4]
b1 = [-4, 2, 6, -5]
b2 = [16, 8, -18, -15]
#Create a list [arrowheadpoint1, arrowheadpoint2, arrowheadpoint3, arrowheadpoint4]
h1 = [(x/(1 + 2 * 0.5 * r(x,y,0.5))) for x in b1, y in b2]
h2 = [y + r(x,y,0.5) for x in b1, y in b2]
#plot corresponding 4 arrows
arrows!(b1, b2, h1, h2, arrowsize = 0.2, lengthscale = 0.3)
The code so far with all the tries is attached here!
using GLMakie
using GeometryBasics
fig = Figure(resolution = (3456, 2234))
ax1 = fig[1, 1] = Axis(fig,
# borders
aspect = 1, limits = ((-10, 10), (-10, 10)),
# title
title = "sliders demo",
titlegap = 48, titlesize = 60,
# x-axis
xautolimitmargin = (0, 0), xgridwidth = 2, xticklabelsize = 36,
xticks = LinearTicks(20), xticksize = 18,
# y-axis
yautolimitmargin = (0, 0), ygridwidth = 2, yticklabelpad = 14,
yticklabelsize = 36, yticks = LinearTicks(20), yticksize = 18
)
# darken axes
vlines!(ax1, [0], linewidth = 2)
hlines!(ax1, [0], linewidth = 2)
# create sliders
lsgrid = labelslidergrid!(fig,
["scale", "xcoordinate", "ycoordinate"],
Ref(LinRange(-10:0.01:10));
formats = [x -> "$(round(x, digits = 2))"],
labelkw = Dict([(:fontsize, 30)]),
sliderkw = Dict([(:linewidth, 24)]),
valuekw = Dict([(:fontsize, 30)])
)
# set starting position for scale
set_close_to!(lsgrid.sliders[1], 1.0)
# layout sliders
sl_sublayout = GridLayout(height = 150)
fig[2, 1] = sl_sublayout
fig[2, 1] = lsgrid.layout
# create listener
scale = lsgrid.sliders[1].value
xreference = lsgrid.sliders[2].value
yreference = lsgrid.sliders[3].value
# arrow base points
xbase = @lift([$xreference])
ybase = @lift([$yreference])
refpoint = @lift(Point($xreference,$yreference))
scatter!(refpoint, color = :red, markersize = 20)
x = -10:0.01:10
m = @lift($scale .* x.^2)
d = @lift(1 ./ (2 .* $scale) .+ (1 ./(2 .* $scale)) .* cbrt.((13.5) .* $scale.^2 .* x.^2))
the_max = max(f(X[end]), g(X[1]))
#plot(X, f, fill = (the_max, 0.5, :auto))
line1 = lines!(ax1, x, m, color = :blue, linewidth = 5)
line2 = lines!(ax1, x, d, color = :red, linewidth = 5)
x = -10:0.01:10
p(x,y,scale) = -(2* scale *y-1)^2/(12 * scale^2) #p
q(x,y,scale) = ((2 * scale * y-1)^3-(27* scale^2) * (x^2))/(108 * scale^3) #q
del(x,y,scale) = ((27 * scale^2 * x^2 - 2((2 * scale * y)-1)^3) * x^2)/(1728* scale^4) #delta
r(x,y,scale) = del(x,y,scale) ā„ 0 ? (-(scale * y+1)/(3* scale) + cbrt(-q(x,y, scale)/2 + sqrt(del(x,y, scale))) + cbrt(-q(x,y, scale)/2 - sqrt(del(x,y, scale)))) : -(scale * y+1)/(3* scale) + (abs(2* scale *y+1)/(3* scale))* cos((1/3) * acos((-q(x,y, scale)/2)/(-p(x,y, scale)/3)^(3/2))) #piecewise expression
xhead = lift(xreference, yreference, scale) do x, y, s
return [ x/(1 + 2 * s * r(x,y,s)) ]
end
yhead = lift(xreference, yreference, scale) do x, y, s
return [ y + r(x,y,s) ]
end
arrowheadpoint = @lift(Point(xhead,yhead))
scatter!(arrowheadpoint, color = :blue, markersize = 20)
arrows!(ax1, xbase, ybase, xhead, yhead)
#Figure 1
display(fig)
#Figure 2
#Create a observables list [refpoint1, refpoint2, refpoint3, refpoint4]
b1 = [-4, 2, 6, -5]
b2 = [16, 8, -18, -15]
#Create a list [arrowheadpoint1, arrowheadpoint2, arrowheadpoint3, arrowheadpoint4]
h1 = [(x/(1 + 2 * 0.5 * r(x,y,0.5))) for x in b1, y in b2]
h2 = [y + r(x,y,0.5) for x in b1, y in b2]
#plot corresponding 4 arrows
arrows!(b1, b2, h1, h2, arrowsize = 0.2, lengthscale = 0.3)
Thanks so much for your time! Any help with the code restructuring comments/criticisms and hints/references is highly appreciated.:).