Ask Your Question

A polyhedron little problem

asked 2020-09-16 13:58:42 +0200

Cyrille gravatar image

I do not know if I make a mistake On the following problem. I have the polygon

var('x_1') # toute variable utilisée doit être préalablement définie
p1 = plot((9 - (3/2)*x_1),(x_1,0,6.5),color='red',axes_labels=['$x_1$','$x_2$'], thickness=2,zorder=2)
l0 = line([(0,0),(0,4)],color='magenta', thickness=2)
l1 = line([(0,4),(10/3,4)],color='yellow', thickness=2)
l2 = line([(0,0),(4,0)],color='green', thickness=2)
l3 = line([(4,0),(4,3)],color='cyan', thickness=2)
c1=point((0,0),pointsize=25, rgbcolor=hue(0.75),aspect_ratio='automatic',zorder=1)
c2=point((0,4),pointsize=25, rgbcolor=hue(0.75),aspect_ratio='automatic',zorder=1)
c3=point((4,0),pointsize=25, rgbcolor=hue(0.75),aspect_ratio='automatic',zorder=1)
c4=point((10/3,4),pointsize=25, rgbcolor=hue(0.75),aspect_ratio='automatic',zorder=1)
c5=point((4,3),pointsize=25, rgbcolor=hue(0.75),aspect_ratio='automatic',zorder=1)
D=text(r"$Domaine\,\, faisable$",(2,2),fontsize=8)

( Incidently I am oblige to plot an horizontal line through line not as an equality. Is there an other way ?) Now if I ask directly to plot the polygon by

var('x_1') # toute variable utilisée doit être préalablement définie

S=[s for s in pol1.Vrepresentation()]
SS=[(S[i][0],S[i][1]) for i in range(len(S))]
C = [circle(SS[i],.1,fill=True,edgecolor='#2f974a',facecolor='#2f974a') for i in range(len(SS))]
PC = [plot(C[i])for i in range(len(SS))]
lab=plot(0,(x,0,9), color='black',axes_labels=['$x_1$','$x_2$'],thickness=0.0001)#ligne fictive d'où l'épaisseur pour obtenir les labels des axes

I obtain a simple rectangle which is not the case. show(lab+gon+sum(PC[i] for i in range(len(SS))))

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-09-16 18:04:03 +0200

slelievre gravatar image

This is more a comment than an answer, posted as an answer since it is too long to fit in a comment.

I do not observe (or do not understand) the problem (on macOS with Sage 9.2.beta12 built from source).

Below a slightly rewritten form of the code from the question, with pictures. (The original code gives me the same pictures.)

  • If you get the same pictures, say what the problem is with them.
  • If not, upload yours and say what version of Sage you are using.

If posting an image on Ask Sage is too tedious, there are various other ways to do that:

  • put the code on SageCell, get a link and post it here
  • put the code on CoCalc, share it, post the link here
  • upload a Jupyter worksheet somewhere, link to it here

Below I am adding sectioning to make it easy to ask any question relating to a specific part of my answer (or the corresponding part in the question).



Define graphic options for the various graphics objects.

sage: options_plot = {'axes_labels': ['$x_1$','$x_2$'], 'thickness': 2, 'zorder': 2}
sage: options_line = {'thickness': 2}
sage: options_point = {'pointsize': 25, 'rgbcolor': hue(0.75),
....:                  'aspect_ratio': 'automatic', 'zorder': 1}
sage: options_pol = {'rgbcolor': (0.025, 0.25, 0.5), 'alpha': 0.2}


A function and its plot.

sage: f1 = lambda x: 9 - (3/2)*x
sage: p1 = plot(f1, (0, 6.5), color='red', **options_plot)


Four lines.

sage: l0 = line([(0, 0), (0, 4)], color='magenta', **options_line)
sage: l1 = line([(0, 4), (10/3, 4)], color='yellow', **options_line)
sage: l2 = line([(0, 0), (4, 0)], color='green', **options_line)
sage: l3 = line([(4, 0), (4, 3)], color='cyan', **options_line)


Five corners.

sage: c1 = point((0, 0), **options_point)
sage: c2 = point((0, 4), **options_point)
sage: c3 = point((4, 0), **options_point)
sage: c4 = point((10/3, 4), **options_point)
sage: c5 = point((4, 3), **options_point)


One polygon.

sage: pol = polygon([(0, 0), (0, 4), (10/3, 4), (4, 3), (4, 0)], **options_pol)


A text description, and a graphics with all these elements.

sage: D = text(r"$Domaine\,\, faisable$", (2, 2), fontsize=8)
sage: G = sum([pol, l0, l1, l2, l3, p1, c1, c2, c3, c4, c5], D)


Save the picture to a file.



Show the whole picture.

Launched png viewer for Graphics object consisting of 12 graphics primitives

The polygon G



A list of inequalities and the corresponding polygon.

sage: ieqs1 = [(18, -2, -1), (42, -2, -3), (24, -3, -1), (0, 1, 0), (0, 0, 1)]
sage: pol1 = Polyhedron(ieqs=ieqs1)


Turn the polygon vertices into tuples.

sage: S = [s for s in pol1.Vrepresentation()]
sage: SS = [tuple(s) for s in S]


Small circles around the vertices.

sage: options_circle = {'fill': True, 'edgecolor': '#2f974a', 'facecolor': '#2f974a'}
sage: C = [circle(s, .1, **options_circle) for s in SS]
sage: PC = [plot(c) for c in C]


The polygon as a graphics object.

sage: gon = polygon(SS, fill=True, color='#d2def1', edgecolor="#0e56ad")


The constant zero function and its plot.

sage: z = lambda x: 0
sage: lab = plot(z, (0, 9), color='black', axes_labels=['$x_1$', '$x_2$'], thickness=0.0001)


Everything in one graphics object.

sage: GG = sum(PC, lab + gon)


Save the picture.



Show the whole picture.

Launched png viewer for Graphics object consisting of 7 graphics primitives

The polygon GG

edit flag offensive delete link more


Sorry to take you time But I have realized that I have made a big mistake in writing he polyydron and also that copy/paste can play bad game with me. One more time I am sorry.

Cyrille gravatar imageCyrille ( 2020-09-16 18:11:43 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-09-16 13:58:42 +0200

Seen: 48 times

Last updated: Sep 16 '20