ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 10 Apr 2022 23:53:00 +0200How to flip normals of Graphics3d faces?https://ask.sagemath.org/question/61908/how-to-flip-normals-of-graphics3d-faces/Is there an easy way to flip the normals for all the faces of a `sage.plot.plot3d.base.Graphics3d` or `sage.plot.plot3d.base.Graphics3dGroup` object?
I checked the source of https://github.com/sagemath/sage/blob/develop/src/sage/plot/plot3d/base.pyx but couldn't find any answers there.
### Background:
I am generating a 3-dimensional surface on the YZ plane via `sage.plot.plot.parametric_plot` using long-running functions and want to mirror this surface by the XY plane to produce a final mesh which includes both the original and mirrored surfaces.
mySurface = parametric_plot(
[
0,
lambda u, v: longRunningYFunction(u, v),
lambda u, v: longRunningZFunction(u, v)
],
...
)
The reason I want to mirror the original surface instead of regenerating it is because the long-running functions take a very long time to complete, so doing it this way effectively cuts down the processing time in half.
I tried a few ways to mirror the surface:
- Rotating by `180°` around the Y axis
mirroredSurface = mySurface.rotateY(pi)
- Scaling by `-1` in the Z direction:
mirroredSurface = mySurface.scale([1, 1, -1])
and when I display or write both surfaces it looks ok:
show(mySurface + mirroredSurface)
but when inspected more closely, the normals of `mirroredSurface` are in the opposite direction of `mySurface`. This requires me to manually flip the surfaces with Blender.
### Question:
Is there any extension or function I can apply on the `Graphics3d` object `mirroredSurface` that would flip all the surface normals?
Something like the following?
mirroredSurface.flip_normals()
# or
flip_normals(mirroredSurface)
Dan-KSun, 10 Apr 2022 23:53:00 +0200https://ask.sagemath.org/question/61908/Path rendering on a Surfacehttps://ask.sagemath.org/question/54279/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_path_radius(u,v) = v*(16*28)/(((28*cos(u))^(2.4)+(16*sin(-u))^2.4)^(5/12))
right_curve_path_radius(u,v) = sqrt((right_curve_x)^2+(right_curve_y)^2)
right_curve_path_radius_2(u,v) = v*sqrt((16^2)*(cos(u))^(5/3)+(28^2)*(sin(-u))^(5/3))
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_2Abbas JaffaryWed, 18 Nov 2020 19:59:27 +0100https://ask.sagemath.org/question/54279/