![]() | 1 | initial version |
Although @slelievre has solve the question, I would like to provide some additional solutions in terms of the plot3d
function which may be helpful.
First solution
This is essentially a rewrite of @slelievre code by replacing parametric_plot3d
by plot3d
:
var("z,t,θ")
r = t*(1-cos(θ))
Cyl = (r*cos(θ),r*sin(θ),z)
plot3d(r^2*cos(θ)^2, (t,0,1), (θ,0,2*pi), transformation=Cyl,
plot_points=[10,120])
Please note that, in cylindrical coordinates, the surface is $z=r^2\cos(\theta)^2$.
Second solution
You can plot a function whose value is NaN
outside the domain. The corresponding points will not appear in the graphic:
var("z,r,θ")
Cyl = (r*cos(θ),r*sin(θ),z)
def fun(r,θ):
if r<=1-cos(θ):
return r^2*cos(θ)^2
else:
return NaN
plot3d(fun, (r,0,2), (θ,0,2*pi), transformation=Cyl,
plot_points=[100, 300])
The problem of this approach is that the surface boundary appears too much jagged.
Third solution
You can plot the surface in a bigger domain and then remove the unwanted part:
var("x,y,z")
fig = plot3d(x^2, (x,-2,2), (y,-2,2))
cond = lambda x,y,z: sqrt(x^2+y^2) <= 1-cos(arctan2(y,x))
fig = fig.add_condition(cond)
show(fig)
In cartesian coordinates, the surface is $z=x^2$. One has to remove those points $(x,y,z)$ whose cylindrical coordinates $(r,\theta,z)$ satisfy the condition $r\leq 1-\cos(\theta)$, which can be expressed in cartesian coordinates as $$ \sqrt{x^2+y^2}\leq 1-\cos(\operatorname{arctan2}(y,x)). $$ The three solutions can be seen in this SageMath cell, painted in red, green and blue.
![]() | 2 | No.2 Revision |
Although @slelievre has solve the question, I would like to provide some additional solutions in terms of the plot3d
function which may be helpful.
First solution
This is essentially a rewrite of @slelievre code by replacing parametric_plot3d
by plot3d
:
var("z,t,θ")
r = t*(1-cos(θ))
Cyl = (r*cos(θ),r*sin(θ),z)
plot3d(r^2*cos(θ)^2, (t,0,1), (θ,0,2*pi), transformation=Cyl,
plot_points=[10,120])
Please note that, in cylindrical coordinates, the surface is $z=r^2\cos(\theta)^2$.
Second solution
You can plot a function whose value is NaN
outside the domain. The corresponding points will not appear in the graphic:
var("z,r,θ")
Cyl = (r*cos(θ),r*sin(θ),z)
def fun(r,θ):
if r<=1-cos(θ):
return r^2*cos(θ)^2
else:
return NaN
plot3d(fun, (r,0,2), (θ,0,2*pi), transformation=Cyl,
plot_points=[100, 300])
The problem of this approach is that the surface boundary appears too much jagged.
Third solution
You can plot the surface in a bigger domain and then remove the unwanted part:
var("x,y,z")
fig = plot3d(x^2, (x,-2,2), (y,-2,2))
cond = lambda x,y,z: sqrt(x^2+y^2) <= 1-cos(arctan2(y,x))
fig = fig.add_condition(cond)
show(fig)
In cartesian coordinates, the surface is $z=x^2$. One has to remove keep only those points $(x,y,z)$ whose cylindrical coordinates $(r,\theta,z)$ satisfy the condition $r\leq 1-\cos(\theta)$, which can be expressed in cartesian coordinates as
$$
\sqrt{x^2+y^2}\leq 1-\cos(\operatorname{arctan2}(y,x)).
$$
The three solutions can be seen in this SageMath cell, painted in red, green and blue.