# Path rendering on a Surface

I am having a discrepancy with the z-coordinates of a path on a surface.

The blue path shown below is correctly embedded in the red surface.

The z-coordinates for the green path are "almost" correct. I have gone over the math dozens of times. I need to compute rational powers of cosine and sine. Wondering if it could be a rounding issue?

The surface is parametrized in polar coordinates.

The path is parametrized in rectangular coordinates. (This is because on the full surface this portion is shifted along the x-axis. I reparametrized it polar and it seems less accurate).

What I've done is:

1. Specify the path as $(x(u), y(u))$
2. Compute the radial distance to the point $r(u) = \sqrt{x^2 + y^2}$
3. The path is then given by $(x(u), y(u), z(r(u))$

(I've used the parameter $v$ to give the paths some "thickness")

This works fine for blue, not for green.

The surface height grows linearly with the radius.

The blue path's radius decays linearly.

The green path's radius decays non-linearly. But, I don't think that should matter, as I'm simply getting a list of points and plugging them into the height function.

u, v = var('u, v')
right_curve_u = 8+(14/pi)*(u+pi/2) #8+(14/pi)*(phi+pi/2)
f_x(u, v) = v*cos(u)
f_y(u, v) = v*sin(u)
f_z(u, v) = (((v-16)/12)*(12*cos((pi/11)*(right_curve_u - 17)) + 39.5))/12
T=parametric_plot3d([f_x, f_y, f_z], (u, -pi/2, 0), (v, 16, 28), color="red", opacity=0.5, axes=True, mesh=False)
#c=parametric_plot3d([f_x, f_y, f_z], (u, -pi/2, pi/2), (v, 21.9, 22.1), color="black", mesh=True)
#c is the curve in the first example with constant radius

#Path Equation;  Note, "u" is the parameter for the path, "v" is to give it a bit of "thickness"
right_curve_u = 8+(14/pi)*(u+pi/2) #8+(14/pi)*(phi+pi/2)
right_curve_x(u,v) = v*(16*(cos(u))^(5/6))
right_curve_y(u,v) = v*(-28*(sin(-u))^(5/6))

right_curve_z(u,v) = ( ( (right_curve_path_radius - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12
right_curve_z_2(u,v) = ( ( (right_curve_path_radius_2 - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12

right_curve = parametric_plot3d([right_curve_x, right_curve_y, right_curve_z], (u, -pi/2, -0.01), (v, 0.99, 1.01), color="black")
right_curve_2 = parametric_plot3d([right_curve_x, right_curve_y, right_curve_z_2], (u, -pi/2, -0.01), (v, 0.99, 1.01), color="green")

g_x(u, v) = v*(16-(12*(u-pi/2)/pi))*cos(u)
g_y(u, v) = v*(16-(12*(u-pi/2)/pi))*sin(u)
h(u) = v*(16 - (12/pi)*(u-pi/2))
g_z(u,v) = ( ( (h - 16)/12 ) * ( 12*cos( (pi/11)*(right_curve_u - 17) ) + 39.5 ) )/12
c_xy=parametric_plot3d([g_x, g_y, g_z], (u, -pi/2, 0), (v, 0.99, 1.01), color="blue")
T+c_xy+right_curve+right_curve_2

edit retag close merge delete

1

rational quotients of python integers are not rational numbers. Beware of your "rational" powers

( 2020-11-19 10:32:37 +0200 )edit

Thank you for pointing this out. I read https://stackoverflow.com/questions/6401167/how-do-i-pass-a-fraction-to-python-as-an-exponent-in-order-to-calculate-the-nth/6401264 (https://stackoverflow.com/questions/6...) and https://doc.sagemath.org/html/en/reference/rings_standard/sage/rings/rational.html (https://doc.sagemath.org/html/en/refe...), changed the exponents to floating point, but I get the same result.

( 2020-11-19 23:25:00 +0200 )edit

Sort by » oldest newest most voted

You should be more careful about "expressions" and "functions".

An expression is something like this

var('u,v')
ex = u*cos(v)


A function is something like this

cool(u,v) = u+v


One possible way to go : use only functions, and call them with arguments always :

good(u, v) = cool(u, v) + u - v


Your "right_curve_u" is an expression. Make it a function.

more

Thank you -- fixed that (and above), still getting the same result. I reparametrized the path in polar coordinates as well, but I'm getting different values for r based on the rectangular --> polar conversion and the direct polar definition, for the same theta values. Curiously, the rectangular --> polar produces the closer z-coordinates.

( 2020-11-20 05:37:35 +0200 )edit
1

Did you change all the definitions of functions that contain another function so that the inner function is called with its arguments ? This means : use f(x,y) = g(x,y) + x + y and not f(x,y) = g + x + y.

( 2020-11-20 08:14:06 +0200 )edit

Yes, same result.

( 2020-11-20 16:50:39 +0200 )edit