# 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>"))
show(T)

# calcul des points critiques
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),
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),
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)
# -------------------------------------------

edit retag close merge delete

Sort by » oldest newest most voted

Unless I'm misunderstanding you, what's wrong with :

def dom(x,y): return 1 if x>0 and y>0 and x+y<4 else 0
region_plot(dom, (-4,4), (-4, 4))


(See Sagecell)

(Note that, since you are working on two variables, you should plot in 2D : There's nothing to specify a third dimension...).

EDIT : Redecyphering your code, I guessed you may mean : "plot z(x, y)=(x*y*(x+y-4))^2+(floor(x/4))^2 subject to x>0, y>0, x+y<4", in which case, what you are looking for is :

plot3d(lambda x,y:(x*y*(x+y-4))^2+(floor(x/4))^2, (0, 4), (0, 4)).add_condition(lambda x, y, z:x+y<4)


(see Sagecell).

(Note that the "condition" function is a three-argument one...).

(Note also that I'm not an haruspex : I'm a dentist...).

more