# General Plotting Code for Cone in 3D with GLMakie or Plots

Hi all,

so I want to plot a general cone of pyramid and a right circular cone, I get this formula:

But I think the plotting does not use the volume formula. Because of this torus code for GLMakie that I have:

using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
cmap4 = [(cmap3[i],0.65) for i in 1:100]
ξ = -40:1:40
c = 20
a = 15
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
volume(torus, algorithm = :iso,isovalue =100,isorange =50, colormap=cmap4)
current_figure()


For general cone of pyramid, If the based is made of a closed random curves, then we might need to plot in x-y plane the curves then plot the top of pyramid afterwards.

For the right circular cone, I believe there is a general formula already.

You could conveniently define both as parametric surfaces:

using Plots; plotlyjs()

z, Θ = range(0,10,200), range(0,2π,300)

# Right-cone:
X = [u * cos(v) for u in z, v in Θ]
Y = [u * sin(v) for u in z, v in Θ]
Z = [-2u for u in z, _ in Θ]
surface(X, Y, Z, size=(600,600), cbar=:none, legend=false)

# Trefoil cone:
X = [u/3 * (sin(v) + 2*sin(2v)) for u in z, v in Θ]
Y = [u/3 * (cos(v) - 2*cos(2v)) for u in z, v in Θ]
Z = [-2u for u in z, _ in Θ]
surface(X, Y, Z, size=(600,600), cbar=:none, legend=false)


1 Like

From your questions posted on this forum it seems that you are teaching math. Hence you should explain to your students how is parameterized a general cone,
defined by its vertex V, given as a 3 vector, and a closed (but not necessarily) planar curve,

x = x(u)
y = y(u)
z= b # b from base plane; usually b=0


u \in [\alpha, \beta]
.
The cone is generated by all segments of line connecting its vertex, V, with the points
(x(u), y(u), b), on the base curve.
Such a segment has the equations:
\displaystyle\frac{X-V[1]}{x(u)-V[1]} = \displaystyle\frac{Y-V[2]}{y(u)-V[2]} =\displaystyle\frac{Z-V[3]}{b-V[3]}=v
Hence:

X = v(x(u)-V[1])+V[1]
Y = v(y(u)-V[2])+V[2]
Z = v(b-V[3])+V[3]


u \in [\alpha, \beta], v\in[0,1]
Example:

vert=[0, 0.75, 3] #cone vertex
base = 0 #the cone base is included within the plane z=base (here z=0)
#functions that define the cone base parameterization
x(u) = cos(u)
y(u) = sin(u)+ sin(u/2);
m, n = 72, 30
u= range(0, 2π, length=m)
v = range(0, 1, length=n)
us = ones(n)*u'
vs = v*ones(m)'
#Surface parameterization
X = @. vs* (x(us)-vert[1]) + vert[1]
Y = @. vs* (y(us)-vert[2]) + vert[2]
Z = @. vs*(base-vert[3]) + vert[3];
surface(X, Y, Z, size=(600,600), cbar=:none, legend=false) #line copied from Rafael

2 Likes

Yes 100 for you, I was a Mathematics teacher for Junior High School students in Papua, but it was 2 years ago. Afterwards, I still love learning Mathematics even if I no longer teach, now I am learning the undergraduate Mathematics, from Calculus, It would be lovely to teach Math again in the future.

This is the first time I learn Calculus with Julia from bottom, it is rewarding knowing the application of this is enormous.

Thanks for this I will use your code and learn the parameterization, vertex, etc.

1 Like