To restrict the domain of a vector field, I have multiplied a coordinate with a non-real complex number (namely a sqrt(of negative expression)). This does work, as shown in this Maple 2017 worksheet program (below). My question is whether this is the best technique of accomplishing this result, or else how to do it better? Would be interested in suggestions for improvements. Here is my program so far:

restart;

#

with(plots):

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(` Vector Field inside Torus`);

print(` ------- ------- ------- ------- ------- ------- -------`);

print(` Assignment: `);

print(` In a circular pipe of radius (my2r), water is flowing in the direction `);

print(` of the pipe, with speed (my2r)^2-(mya)^2, where (mya) is the distance `);

print(` to the axis of the pipe. `);

print(` Depict the vector field describing the flow if the pipe goes around in `);

print(` the shape of a torus with major radius (my1r). `);

print(` `);

print(` `);

print(` `);

print(` ------- ------- ------- ------- ------- ------- -------`);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 1) major radius of torus:`);

#

my1r := 5;

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 2) minor radius of torus (pipe radius):`);

#

my2r := 4;

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 3) definition of torus (polar coordinates):`);

#

c00 := [(my1r+my2r*cos(s))*cos(t),(my1r+my2r*cos(s))*sin(t),my2r*sin(s)];

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 4) 3D plot of solid torus (polar coordinates):`);

#

plot3d({c00},scaling=constrained,color=red);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 5) 3D plot of wireframe torus (polar coordinates):`);

#

P1 := plot3d({c00},scaling=constrained,style=wireframe);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 6) implicit definition of torus (cartesian coordinates):`);

#

c01 := (sqrt(x^2+y^2)-my1r)^2+z^2-my2r^2;

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 7) implicit 3D plot of solid torus (cartesian coordinates):`);

#

gx := my1r+my2r; # min and max of each coordinate

#

implicitplot3d(c01,x=-gx..gx,y=-gx..gx,z=-gx..gx,numpoints=9000);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 8) vector field definition (cartesian coordinates):`);

#

my1vfx := -y;

my1vfy := x;

my1vfz := 0;

#

my1fld := [my1vfx,my1vfy,my1vfz];

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 9) 3D plot of vector field (cartesian coordinates):`);

#

fieldplot3d(my1fld,x=-gx..gx,y=-gx..gx,z=-gx..gx);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 10) definition of vector field with unit length vectors (cartesian coordinates):`);

#

my1vl := sqrt(my1vfx^2+my1vfy^2+my1vfz^2); # vector length

#

my2fld := [my1vfx/my1vl,my1vfy/my1vl,my1vfz/my1vl];

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 11) 3D plot of vector field with unit length vectors (cartesian coordinates):`);

#

fieldplot3d(my2fld,x=-gx..gx,y=-gx..gx,z=-gx..gx);

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 12) definition of vector field with asked for length vectors (cartesian coordinates):`);

#

mya := sqrt((sqrt(x^2+y^2)-my1r)^2+z^2);

c01r := sqrt(my2r^2-mya^2); # also used for domain restricting vector field below

#

my1tsz := solve([c01],[z]);

#

assign(my1tsz[1][1]);

my1tz := z;

unassign('z');

#

assign(my1tsz[2][1]);

my2tz := z;

unassign('z');

#

my1vp := c01r/my2r; # vector length (maximum one unit)

#

my3fld := [my1vp*my1vfx/my1vl,my1vp*my1vfy/my1vl,my1vp*my1vfz/my1vl];

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 13) 3D plot of vector field with asked for length vectors (cartesian coordinates):`);

#

fieldplot3d(my3fld,x=-gx..gx,y=-gx..gx,z=-gx..gx);

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n(Section 14) same asked for vector field with 3-D arrow vectors:`);

print(` `);

print(` (to get this to display properly it was necessary to do: `);

print(` -> Maple 2017 -> Preferences... -> Precision -> `);

print(` [unselect] Limit expression length to `);

print(` Apply to Session`);

print(` `);

#

gr := 15;

#

P3 := fieldplot3d(my3fld,x=-gx..gx,y=-gx..gx,z=-gx..gx,arrows=`3-D`,grid=[gr,gr,gr]);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);

print(`\n display asked for vector field within wireframe torus:`);

#

display([P1,P3]);

#

#

print(` ------- ------- ------- ------- ------- ------- -------`);