parametric_plot

34 views
Skip to first unread message

Ricardo Acuna

unread,
Jul 29, 2021, 2:53:59 AM7/29/21
to sage-support
Hello,
I'm trying to recreate a plot that I did in Maple 

P := (x, y) -> WeierstrassP(x + y*I, 1, 0);
PP := (x, y) -> WeierstrassPPrime(x + y*I, 1, 0);
IR := (theta, z) -> cos(theta)*Re(z) + sin(theta)*Im(z);
Gr1 := theta -> [[Re(P(x, y)), Im(P(x, y)), 0.3*IR(theta, PP(x, y))], x = 0.001 .. 3.74, y = 0.001 .. 3.74, color = [sin(2*Pi*x/3.74), 0.5, sin(2*Pi*y/3.74)], view = [-1 .. 1, -1 .. 1, -1 .. 1], grid = [35, 35]];
plots[animate](plot3d, Gr1(t), t = 0 .. Pi - 0.1)

Here's what I have so far.
var('z')
E = EllipticCurve(QQ, [0,0,0,-1/4,0])
wp = E.weierstrass_p().laurent_polynomial()
wpp = derivative(wp,z)

f = (lambda u,v: wp(u+i*v).real(), lambda u,v: wp(u+i*v).imag(), lambda u,v: wpp(u+i*v).imag())

parametric_plot3d(f, (0.001,3.74), (0.001,3.74))

the only problem I see is that I have no control over the view box. With Maple I can have the parameter view = [-1 .. 1, -1 .. 1, -1 .. 1] such that the software only shows stuff in that range.

contour_plot has the optional region parameter, so it's possible someone already implemented something similar in another class.

Best,
RJ Acuña

slelievre

unread,
Jul 29, 2021, 7:18:26 AM7/29/21
to sage-support
So far, limiting the z range in 3D plots from plot3d,
parametric_plot or parametric_plot3d is missing.

Providing this feature is tracked at

- Sage Trac ticket 31264
  Allow setting zmin, zmax in plot3d and other 3d plots

Using implicit_plot3d can be a workaround,
given an equation for the surface ...which is easy
in the case of plot3d but usually not in the case
of parametric_plot3d.

To limit the x, y and z ranges in a parametric plot,
we can alternatively use auxiliary functions which
return their computed value when it is within bounds,
and return "not a number" otherwise.

Here is a way to do that for the plot in the question.
We use cached functions to save computation time.

```
z = SR.var('z')
E = EllipticCurve(QQ, [0, 0, 0, -1/4, 0])
wp = E.weierstrass_p().laurent_polynomial()
wpp = derivative(wp, z)

nan = float('nan')

@cached_function
def wpuv(u, v):
    return wp(u + i*v)

@cached_function
def xuv(u, v):
    return wpuv(u, v).real()

@cached_function
def yuv(u, v):
    return wpuv(u, v).imag()

@cached_function
def zuv(u, v):
    return wpp(u + i*v).imag()

xmin, xmax = -1, 1
ymin, ymax = -1, 1
zmin, zmax = -1, 1

@cached_function
def xok(u, v):
    return xmin < xuv(u, v) < xmax

@cached_function
def yok(u, v):
    return ymin < yuv(u, v) < ymax

@cached_function
def zok(u, v):
    return zmin < zuv(u, v) < zmax

@cached_function
def xyzok(u, v):
    return xok(u, v) and yok(u, v) and zok(u, v)

@cached_function
def xxuv(u, v):
    return xuv(u, v) if xyzok(u, v) else nan

@cached_function
def yyuv(u, v):
    return yuv(u, v) if xyzok(u, v) else nan

@cached_function
def zzuv(u, v):
    return zuv(u, v) if xyzok(u, v) else nan

uu = (1e-3, 3.74)
vv = (1e-3, 3.74)

pp = parametric_plot3d

pp([xxuv, yyuv, zzuv], uu, vv)
```

That's already an interesting view.

To refine it, check which values of (u, v) give (x, y, z) within bounds:

```
good_uv_x = region_plot(xok, uu, vv)
good_uv_y = region_plot(yok, uu, vv)
good_uv_z = region_plot(zok, uu, vv)
good_uv_xyz = region_plot(xyzok, uu, vv)
good_uv = [good_uv_x, good_uv_y, good_uv_z, good_uv_xyz]

graphics_array(good_uv, ncols=2)
```

This reveals that values of u and v beyond 3.2 are not so useful.

Use a reduced range for u and v, and increase the number of plot points:

```
uu = (RDF(1e-3), RDF(3.2))
vv = (RDF(1e-3), RDF(3.2))
pp([xxuv, yyuv, zzuv], uu, vv, plot_points=129)
```

slelievre

unread,
Jul 31, 2021, 1:20:54 PM7/31/21
to sage-support
I was wrong! The functionality exists!

Good thing you asked the question again as

- Ask Sage question 58169
  Change the view box on a 3D graph
  https://ask.sagemath.org/question/58169

and Frédéric Chapoton answered it there,
pointing to the `add_condition` method!

Remember to accept his answer to mark your
question as solved in the list of questions.

Please ignore my previous previous post and
the less than satisfactory approach in it. 


Reply all
Reply to author
Forward
0 new messages