# plot the the intersection of two surfaces in 3d, use of a special colour for the intersection

Is it possible to colour the intersection of two surfaces in 3d with a special colour in the following plot?

x, y, z = var('x,y,z')
f1=y-x^3
f2=z-x^5
surface1 = implicit_plot3d(f1,(x,-5,5),(y,-3,3), (z,-5,5), color='blue',opacity=1)
surface2 = implicit_plot3d(f2,(x,-5,5),(y,-3,3), (z,-5,5), color='red',opacity=.3)
show(surface1+surface2)

edit retag close merge delete

Sort by » oldest newest most voted

The "numerical" solution will be slow and artefactual (the rate of variatuns of x, y and z are wildly different, and "one-size-fits-all" plot_points will actually fit none...) :

var("x, y, z")
f1(x, y, z)=y-x^3
f2(x, y, z)=z-x^5
S1=implicit_plot3d(f1, (-5, 5), (-3, 3), (-5, 5), color="blue", opacity=0.5, plot_points=200)
S2=implicit_plot3d(f2, (-5, 5), (-3, 3), (-5, 5), color="red", opacity=0.5, plot_points=200)
f3(x, y, z)=f1(x, y, z)^2+f2(x, y, z)^2-0.01
S3=implicit_plot3d(f3, (-5, 5), (-3, 3), (-5, 5), color="green", opacity=1, plot_points=200)


You can visualize by displaying S1+S2+S3. Ugly...

Better (but more work) to solve for y and z, and plot parametrically wrt x :

Sol=solve([f1(x, y, z), f2(x, y)], (y, z), solution_dict=True)
A3 = parametric_plot3d([x, Sol[0][y], Sol[0][z]], (x, -5^(1/5), 5^(1/5)), color="green")


S1+S2+A3 is faster and better-looking...

More general case : solve z as a function (possibly multi-valued) of x and y and plot3d the result...

HTH,

more