implicit plot 3d for a triangle
hi this code is the result of a long work and long interactions with members of this forum (end of the message) i could draw the "domain" fonction here by manual instructions, since this domain is x>0, y>0, x+y<4 but i would like to modify only the code between the two #** so i have to explicit this domain as a dom(x,y) function i have tried :
def dom(x,y):
if ((x*y*(x+y)-4==0) and (x>0)):
return 0
else
return 1
but it did not work now as you see below i have tried:
dom(x,y)=(x*y*(x+y-4))^2+(floor(x/4))^2
which returns 0 only on the triangle ; my aim is to draw the triangle but i draws nothing, without returning any error
how could i proceed ?
# code à personnaliser ---------------------
#**********
f(x,y)=x*log(1+y^2)
lenom="fonction Ah : ****"
leratio=(1,1,1/32)
lacouleur="blue"
(xmin,xmax)=(-8,8)
(ymin,ymax)=(-6,6)
(zmin,zmax)=(-140,50)
def laregion(x,y,z):#domaine de definition
return True
domdom=True # True = afficher un domaine de contrainte
dom(x,y)=(x*y*(x+y-4))^2+(floor(x/4))^2
lacouleurdom="cyan"
(zmindom,zmaxdom)=(zmin,zmax) #idem
#**********
# -------------------------------------------
# code général, ne pas toucher --------------
# calculs généraux
show(html("<h4>"+lenom+"</h4>"))
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
F = E.scalar_field(f)
H=f(x,y).hessian()
show(html("<h5>paramètres généraux</h5>"))
T=table([["f",f],["grad f=",grad(F)[:]],["H=",H]],frame=True,align='center')
show(T)
# calcul des points critiques
Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y],solution_dict=True)
liste=[]
for critique in Cr:
x_et_y_reels=(x(critique).imag()==0 and y(critique).imag()==0)
x_et_y_avec_parametre=(len(x(critique).variables())>0 or len(y(critique).variables())>0)
if(x_et_y_reels or x_et_y_avec_parametre):
liste.append(["(","x","=",x(critique),";","y","=",y(critique),")",H(critique)])
show(html("<h5>points critiques</h5>"))
if (len(liste)!=0):
show(table(liste))
else :
show("pas de points critiques")
# graphique
h(x,y,z)=f(x,y)-z
lasurface=implicit_plot3d(h, (x, xmin,xmax), (y, ymin, ymax), (z, zmin, zmax),
aspect_ratio=leratio,color=lacouleur,adaptive=True,mesh=True,
region=laregion)
from sage.plot.plot3d.shapes import Text
lalegende=Text(str(f)).translate(xmin,ymin,zmin)
#lalegende=Text(pretty_print(str(f))).translate(xmin,ymin,zmin)
ledomaine=implicit_plot3d(dom, (x, xmin,xmax), (y, ymin, ymax), (z, zmindom, zmaxdom),
aspect_ratio=leratio,color=lacouleurdom,adaptive=True,mesh=True,
region=laregion)
#lignes de niveau :
import numpy as np
pas=(zmax-zmin)/20
leslignes=contour_plot(f, (x,xmin, xmax), (y,ymin, ymax),contours=np.arange(zmin,zmax,pas))
# enfin, les show
if domdom:
show(lasurface+ledomaine+lalegende)
else :
show(lasurface+lalegende)
show(leslignes)
# -------------------------------------------