Can Gnuplot Made by Lazarus Plot 3D surface along with its orthogonal line in Julia?

I have been looking how to create this:

Capture d’écran_2022-08-19_19-27-15

Then saw this link:

and this discussion:

I tried with LazySets to create without the plane:

using LazySets, LaTeXStrings
using Plots: plot, plot!, text, lens!, bbox
gr()
p(args...; kwargs...) = plot(xlims=(0,4), ylims=(0,4), ratio=1, lab="",
                        xlab=L"x_{1}", ylab=L"x_{2}", args...; kwargs...)
p!(args...; kwargs...) = plot!(lab="", args...; kwargs...);

p(xlims=(0,2), ylims=(0,2))
a = [1.0, 1.0]
b = 2.0

H = Hyperplane(a, b)

p!(H, linewidth=2)

# normal arrow
p!([1.0, 1.5], [1.0, 1.5], linecolor=:red, arrow=:arrow,
    linestyle=:dash, width=2, annotations=(1.15, 1.3, text(L"\textbf{n}", 10)))
p!([1.0, 0.5], [1.0, 1.5], linecolor=:red, arrow=:arrow,
    linestyle=:dash, width=2, annotations=(0.75, 1.5, text(L"P(x,y)", 10)))

annotate!([(1.5, 1.6, text(L"(a,b)", 10)), 
           (0.75, 1.0, text(L"P_{0}(x_{0},y_{0})", 10))])

scatter!([1], [1], color = "red", label="", markersize = 4)
scatter!([1.5], [1.5], color = "red", label="", markersize = 4)
scatter!([0.5], [1.5], color = "red", label="", markersize = 4)

Capture d’écran_2022-12-08_21-49-46

Hopefully anyone can help me…

1 Like

I always wanna to do a simplex, quantum mechanics memories. Anyway, not a solution with Gnuplot, but I hope something with Makie.jl also works for you. The code is here and below:

Code
using GLMakie
GLMakie.activate!()
vertices = [
    0 0 0
    1 0 0
    0 1 0 
    0 0 1
    ]
faces = [
    3 2 1
    4 1 2
    4 3 1
    4 2 3
    ]
## m = GLMakie.GeometryBasics.Mesh(GLMakie.Makie.to_vertices(vertices), GLMakie.Makie.to_triangles(faces))
## mesh(m)

marker = Sphere(Point3f(0), 1) # 0 -> -0.5, fully inside, 0 -> 0.5 fully outside

fig = Figure(resolution = (600,600))
ax = LScene(fig[1,1], show_axis=false)
m = mesh!(ax, vertices, faces; color = :white, transparency=true,)
poly!(ax, vertices, faces; color = :transparent, 
    transparency=true, strokewidth = 1.0)
meshscatter!(ax, 
    Point3f(1/3, 1/3,1/3),  # you need to calculate this for your use case
    marker = marker, markersize = 0.025, transparency=true)
## the following are not over the plane nither perpendicular.
arrows!(ax, 
    [Point3f(1/3, 1/3,1/3)],  # you need to calculate this for your use case
    [Point3f(0.2, 0.1,0.3)],  # you need to calculate this for your use case
    arrowsize = Vec3f(0.05, 0.05, 0.08),
    color = :red,
    arrowcolor = :black)
arrows!(ax, 
    [Point3f(1/3, 1/3,1/3)],  # you need to calculate this for your use case
    [Point3f(-0.1, -0.1,0.3)],  # you need to calculate this for your use case
    arrowsize = Vec3f(0.08, 0.08, 0.08),
    linewidth = 0.02,
    color = :dodgerblue,
    arrowcolor = :orange)
zoom!(ax.scene, cameracontrols(ax.scene), 0.9)
rotate!(ax.scene, -0.1)
fig

2 Likes

With Plots.jl it is possible to draw such a transparent plane and the orthogonal arrows:

However, there is no 3D annotation, only 2D, with which the text could be placed in the right places after some trial and error.

Plots.jl code
using Plots; pyplot(dpi=100)

function arrow3d!(P, V; lc=:black, lw=2, camera=(10,30))
    n = 7                           # break arrowhead in n-parts
    ni = (0:n-1)/n 
    lwi = range(0.1, 4*lw, n)       # arrowhead variable thickness                   
    d = V .* 1/10                   # controls relative arrow length
    P1 =  P + V
    P0 =  P1 - d
    plot!([P[1], P1[1]], [P[2], P1[2]], [P[3], P1[3]], lw=lw, lc=lc, label=false, camera=camera)
    for (i,li) in zip(ni,lwi)
        di = d .* i
        plot!([P0[1], P1[1]-di[1]], [P0[2], P1[2]-di[2]], [P0[3], P1[3]-di[3]], lw=li, lc=lc, label=false)
    end
    return Plots.current()
end

using LinearAlgebra
p1, p2, p3 = [2,0,0], [0,2,0], [0,0,2]
c = .+(p1, p2, p3) ./ 3
n = cross(p1-p2, p1-p3) ./ (norm(p1-p2)*norm(p1-p3))
surface(p1, p2, p3, c=:blues, alpha=0.3, aspect_ratio=:equal, cbar=false)
scatter!([c[1]], [c[2]], [c[3]], ms=7, label=false)
arrow3d!(c, n; lc=:blue, camera=(70,30))
arrow3d!(c, (p3-c)*1/3; lc=:blue, camera=(70,30))
2 Likes

Don’t worry I am still at chapter 4 calculus, one day I will ask in this discourse how to create great simplex calculation.

I like Plots.jl !

Thanks for the code, I will work with the annotations or edit it with inkscape is easier.