Ticket #12083: trac12083_tikz_polytope_review.patch
File trac12083_tikz_polytope_review.patch, 22.4 KB (added by , 10 years ago) |
---|
-
sage/geometry/polyhedra.py
# HG changeset patch # User Jean-Philippe Labbé <labbe at math.fu-berlin.de> # Date 1338471031 -7200 # Node ID 0bfb394ac7bd32f7896c4607da026b4f717b01c0 # Parent 65c1e557ebb3ce13d509a0eecabb8605598b920d trac #12083: first review version diff --git a/sage/geometry/polyhedra.py b/sage/geometry/polyhedra.py
a b 120 120 121 121 from subprocess import Popen, PIPE 122 122 from sage.misc.all import tmp_filename 123 from sage.misc.functional import norm , n123 from sage.misc.functional import norm 124 124 from sage.misc.package import is_package_installed 125 from sage.misc.latex import LatexExpr 125 126 126 127 from sage.rings.all import Integer, QQ, ZZ, primes_first_n 127 128 from sage.rings.real_double import RDF 128 129 from sage.modules.free_module_element import vector 129 from sage.modules.free_module import VectorSpace130 130 from sage.matrix.constructor import matrix, identity_matrix 131 131 from sage.functions.other import sqrt, floor, ceil 132 132 from sage.functions.trig import sin, cos … … 4879 4879 self._restricted_automorphism_group = group 4880 4880 return group 4881 4881 4882 def tikz(self, view=[0,0,1], rot_angle=0, scale=2,4882 def tikz(self, view=[0,0,1], angle=0, scale=2, 4883 4883 edge_color='blue!95!black', facet_color='blue!95!black', 4884 4884 opacity=0.8, vertex_color='green', axis=False): 4885 4885 """ 4886 4886 Return a string ``tikz_pic`` consisting of a tikz picture of ``self`` 4887 according to a projection ``view`` and an angle `` rot_angle``4887 according to a projection ``view`` and an angle ``angle`` 4888 4888 obtained via Jmol through the current state property. 4889 4889 4890 4890 INPUT: 4891 4891 4892 - ``view`` -- a list of length 3 representing a vector; 4893 - ``rot_angle`` -- an angle in degree from 0 to 360; 4894 - ``scale`` -- an integer specifying the scaling of the tikz picture; 4895 - ``edge_color``, ``facet_color``, ``vertex_color`` -- string representing 4896 colors which tikz recognize; 4897 - ``opacity`` -- a real number between 0 and 1 giving the opacity of 4898 the front facets; 4899 - ``axis`` -- a Boolean, to draw the axes at the origin. 4892 - ``view`` - list (default: [0,0,1]) representing the rotation axis (see note below). 4893 - ``angle`` - integer (default: 0) angle of rotation in degree from 0 to 360 (see note 4894 below). 4895 - ``scale`` - integer (default: 2) specifying the scaling of the tikz picture. 4896 - ``edge_color`` - string (default: 'blue!95!black') representing colors which tikz 4897 recognize. 4898 - ``facet_color`` - string (default: 'blue!95!black') representing colors which tikz 4899 recognize. 4900 - ``vertex_color`` - string (default: 'green') representing colors which tikz 4901 recognize. 4902 - ``opacity`` - real number (default: 0.8) between 0 and 1 giving the opacity of 4903 the front facets. 4904 - ``axis`` - Boolean (default: False) draw the axes at the origin or not. 4900 4905 4901 4906 OUTPUT: 4902 4907 4903 - ``tikz_pic`` -- a string containing the raw text of aTikZ picture.4908 - LatexExpr -- containing the TikZ picture. 4904 4909 4905 4910 .. NOTE:: 4906 4911 4907 The inputs ``view`` and `` rot_angle`` can be obtained from the viewer4912 The inputs ``view`` and ``angle`` can be obtained from the viewer 4908 4913 Jmol: 4909 4914 4910 4915 1) Right click on the image; 4911 2) Select ``Console` ;4912 3) Select the tab ``State` ;4916 2) Select ``Console``; 4917 3) Select the tab ``State``; 4913 4918 4) Scroll to the line ``moveto`` 4914 4919 4915 It read something like: 4920 It read something like:: 4916 4921 4917 4922 moveto 0.0 {x y z angle} Scale 4918 4923 4919 The ``view`` is then [x,y,z] and `` rot_angle`` is angle.4924 The ``view`` is then [x,y,z] and ``angle`` is angle. 4920 4925 The following number is the scale. 4926 Jmol performs a rotation of ``angle`` degrees along the vector [x,y,z] and show 4927 the result from the z-axis. 4921 4928 4922 4929 EXAMPLES:: 4923 4930 4924 4931 sage: P1 = polytopes.small_rhombicuboctahedron() 4925 4932 sage: Image1 = P1.tikz([1,3,5], 175, scale=4) 4926 sage: open('polytope-tikz.tex', 'w').write(Image1) 4933 sage: type(Image1) 4934 <class 'sage.misc.latex.LatexExpr'> 4935 sage: print '\n'.join(Image1.splitlines()[:4]) 4936 \begin{tikzpicture}% 4937 [x={(-0.939161cm, 0.244762cm)}, 4938 y={(0.097442cm, -0.482887cm)}, 4939 z={(0.329367cm, 0.840780cm)}, 4940 sage: open('polytope-tikz1.tex', 'w').write(Image1) # not tested 4927 4941 4928 4942 sage: P2 = Polyhedron(vertices=[[1, 1],[1, 2],[2, 1]]) 4929 4943 sage: Image2 = P2.tikz(scale=3, edge_color='blue!95!black', facet_color='orange!95!black', opacity=0.4, vertex_color='yellow', axis=True) 4930 sage: open('polytope-tikz2.tex', 'w').write(Image2) 4944 sage: type(Image1) 4945 <class 'sage.misc.latex.LatexExpr'> 4946 sage: print '\n'.join(Image2.splitlines()[:4]) 4947 \begin{tikzpicture}% 4948 [scale=3.000000, 4949 back/.style={loosely dotted, thin}, 4950 edge/.style={color=blue!95!black, thick}, 4951 sage: open('polytope-tikz2.tex', 'w').write(Image2) # not tested 4931 4952 4932 4953 sage: P3 = Polyhedron(vertices=[[-1, -1, 2],[-1, 2, -1],[2, -1, -1]]) 4933 4954 sage: P3 4934 4955 A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices. 4935 sage: Image3 = P3.tikz([0.5,-1,-0.1], 55, scale=3, edge_color='blue!95!black', facet_color='orange!95!black', opacity=0.7, vertex_color='yellow', axis=True) 4936 sage: open('polytope-tikz3.tex', 'w').write(Image3) 4956 sage: Image3 = P3.tikz([0.5,-1,-0.1], 55, scale=3, edge_color='blue!95!black',facet_color='orange!95!black', opacity=0.7, vertex_color='yellow', axis=True) 4957 sage: print '\n'.join(Image3.splitlines()[:4]) 4958 \begin{tikzpicture}% 4959 [x={(0.658184cm, -0.242192cm)}, 4960 y={(-0.096240cm, 0.912008cm)}, 4961 z={(-0.746680cm, -0.331036cm)}, 4962 sage: open('polytope-tikz3.tex', 'w').write(Image3) # not tested 4937 4963 4938 4964 sage: P=Polyhedron(vertices=[[1,1,0,0],[1,2,0,0],[2,1,0,0],[0,0,1,0],[0,0,0,1]]) 4939 4965 sage: P … … 4943 4969 ... 4944 4970 NotImplementedError: The polytope has to live in 2 or 3 dimensions. 4945 4971 4946 4947 4972 .. TO DO:: 4948 4973 4949 4974 Make it possible to draw Schlegel diagram for 4-polytope. … … 4965 4990 return self._tikz_2d(scale, edge_color, facet_color, opacity, 4966 4991 vertex_color, axis) 4967 4992 elif self.dim() == 2: 4968 return self._tikz_2d_in_3d(view, rot_angle, scale, edge_color,4993 return self._tikz_2d_in_3d(view, angle, scale, edge_color, 4969 4994 facet_color, opacity, vertex_color, axis) 4970 4995 else: 4971 return self._tikz_3d_in_3d(view, rot_angle, scale, edge_color,4996 return self._tikz_3d_in_3d(view, angle, scale, edge_color, 4972 4997 facet_color, opacity, vertex_color, axis) 4973 4998 4974 4999 def _tikz_2d(self, scale, edge_color, facet_color, opacity, vertex_color, axis): … … 4977 5002 4978 5003 INPUT: 4979 5004 4980 - ``scale`` -- an integer specifying the scaling of the tikz picture; 4981 - ``edge_color``, ``facet_color``, ``vertex_color`` -- string representing 4982 colors which tikz recognize; 4983 - ``opacity`` -- a real number between 0 and 1 giving the opacity of 4984 the front facets; 4985 - ``axis`` -- a Boolean, to draw the axes at the origin. 5005 - ``scale`` - integer specifying the scaling of the tikz picture. 5006 - ``edge_color`` - string representing colors which tikz 5007 recognize. 5008 - ``facet_color`` - string representing colors which tikz 5009 recognize. 5010 - ``vertex_color`` - string representing colors which tikz 5011 recognize. 5012 - ``opacity`` - real number between 0 and 1 giving the opacity of 5013 the front facets. 5014 - ``axis`` - Boolean (default: False) draw the axes at the origin or not. 5015 5016 OUTPUT: 5017 5018 - LatexExpr -- containing the TikZ picture. 5019 5020 EXAMPLES:: 5021 5022 sage: P = Polyhedron(vertices=[[1, 1],[1, 2],[2, 1]]) 5023 sage: Image = P._tikz_2d(scale=3, edge_color='black', facet_color='orange', opacity=0.75, vertex_color='yellow', axis=True) 5024 sage: type(Image) 5025 <class 'sage.misc.latex.LatexExpr'> 5026 sage: print '\n'.join(Image.splitlines()[:4]) 5027 \begin{tikzpicture}% 5028 [scale=3.000000, 5029 back/.style={loosely dotted, thin}, 5030 edge/.style={color=black, thick}, 5031 sage: open('polytope-tikz2.tex', 'w').write(Image2) # not tested 4986 5032 4987 5033 .. NOTE:: 4988 5034 … … 5018 5064 tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color 5019 5065 tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity) 5020 5066 tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color 5021 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n \n\n' %vertex_color5067 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color 5022 5068 5023 5069 # Draws the axes if True 5024 5070 if axis: … … 5026 5072 tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};\n' 5027 5073 5028 5074 # Create the coordinate of the vertices: 5029 tikz_pic += '%% Coordinate of the vertices:\n \n'5075 tikz_pic += '%% Coordinate of the vertices:\n%%\n' 5030 5076 for v in self.Vrep_generator(): 5031 5077 tikz_pic += dict_drawing[v][1] 5032 5078 5033 5079 # Draw the interior by going in a cycle 5034 tikz_pic += ' \n\n%% Drawing the interior\n\n'5080 tikz_pic += '%%\n%%\n%% Drawing the interior\n%%\n' 5035 5081 cyclic_vert = cyclic_sort_vertices_2d(list(self.Vrep_generator())) 5036 5082 tikz_pic += '\\fill[facet] ' 5037 5083 for v in cyclic_vert: … … 5039 5085 tikz_pic += 'cycle {};\n' 5040 5086 5041 5087 # Draw the edges in the front 5042 tikz_pic += ' \n\n%% Drawing edges in the front\n\n'5088 tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n' 5043 5089 tikz_pic += edges 5044 5090 5045 5091 # Finally, the vertices in front are drawn on top of everything. 5046 tikz_pic += ' \n\n%% Drawing the vertices in the front\n\n'5092 tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n' 5047 5093 for v in self.Vrep_generator(): 5048 5094 tikz_pic += dict_drawing[v][0] 5049 tikz_pic += ' \n\n\\end{tikzpicture}'5050 5051 return tikz_pic5052 5053 def _tikz_2d_in_3d(self, view, rot_angle, scale, edge_color, facet_color,5095 tikz_pic += '%%\n%%\n\\end{tikzpicture}' 5096 5097 return LatexExpr(tikz_pic) 5098 5099 def _tikz_2d_in_3d(self, view, angle, scale, edge_color, facet_color, 5054 5100 opacity, vertex_color, axis): 5055 5101 """ 5056 5102 Return a string ``tikz_pic`` consisting of a tikz picture of ``self`` 5057 according to a projection ``view`` and an angle `` rot_angle``5103 according to a projection ``view`` and an angle ``angle`` 5058 5104 obtained via Jmol through the current state property. 5059 5105 5060 5106 INPUT: 5061 5107 5062 - ``view`` -- a list of length 3 representing a vector; 5063 - ``rot_angle`` -- an angle in degree from 0 to 360 (rotation along the view); 5064 - ``scale`` -- an integer specifying the scaling of the tikz picture; 5065 - ``edge_color``, ``facet_color``, ``vertex_color`` -- string 5066 representing colors which tikz recognize; 5067 - ``opacity`` -- a real number between 0 and 1 giving the opacity of 5068 the front facets; 5069 - ``axis`` -- a Boolean, to draw the axes at the origin. 5108 - ``view`` - list (default: [0,0,1]) representing the rotation axis. 5109 - ``angle`` - integer angle of rotation in degree from 0 to 360. 5110 - ``scale`` - integer specifying the scaling of the tikz picture. 5111 - ``edge_color`` - string representing colors which tikz 5112 recognize. 5113 - ``facet_color`` - string representing colors which tikz 5114 recognize. 5115 - ``vertex_color`` - string representing colors which tikz 5116 recognize. 5117 - ``opacity`` - real number between 0 and 1 giving the opacity of 5118 the front facets. 5119 - ``axis`` - Boolean draw the axes at the origin or not. 5120 5121 OUTPUT: 5122 5123 - LatexExpr -- containing the TikZ picture. 5124 5125 EXAMPLE:: 5126 5127 sage: P = Polyhedron(vertices=[[-1, -1, 2],[-1, 2, -1],[2, -1, -1]]) 5128 sage: P 5129 A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices. 5130 sage: Image = P._tikz_2d_in_3d(view=[0.5,-1,-0.5], angle=55, scale=3, edge_color='blue!95!black', facet_color='orange', opacity=0.5, vertex_color='yellow', axis=True) 5131 sage: print '\n'.join(Image.splitlines()[:4]) 5132 \begin{tikzpicture}% 5133 [x={(0.644647cm, -0.476559cm)}, 5134 y={(0.192276cm, 0.857859cm)}, 5135 z={(-0.739905cm, -0.192276cm)}, 5136 sage: open('polytope-tikz3.tex', 'w').write(Image3) # not tested 5070 5137 5071 5138 .. NOTE:: 5072 5139 … … 5074 5141 5075 5142 """ 5076 5143 5077 V = VectorSpace(RDF,3) 5078 view_vector = V(view) 5079 rot = rotate_arbitrary(view_vector,-(rot_angle/360)*2*pi) 5144 view_vector = vector(RDF, view) 5145 rot = rotate_arbitrary(view_vector,-(angle/360)*2*pi) 5080 5146 rotation_matrix = rot[:2].transpose() 5081 5147 5082 5148 # Creates the nodes, coordinate and tag for every vertex of the polytope. … … 5103 5169 # Start to write the output 5104 5170 tikz_pic = '' 5105 5171 tikz_pic += '\\begin{tikzpicture}%\n' 5106 tikz_pic += '\t[x={(%fcm, %fcm)},\n' %( n(rotation_matrix[0][0]),n(rotation_matrix[0][1]))5107 tikz_pic += '\ty={(%fcm, %fcm)},\n' %( n(rotation_matrix[1][0]),n(rotation_matrix[1][1]))5108 tikz_pic += '\tz={(%fcm, %fcm)},\n' %( n(rotation_matrix[2][0]),n(rotation_matrix[2][1]))5172 tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[0][0]),RDF(rotation_matrix[0][1])) 5173 tikz_pic += '\ty={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[1][0]),RDF(rotation_matrix[1][1])) 5174 tikz_pic += '\tz={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[2][0]),RDF(rotation_matrix[2][1])) 5109 5175 tikz_pic += '\tscale=%f,\n' %scale 5110 5176 tikz_pic += '\tback/.style={loosely dotted, thin},\n' 5111 5177 tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color 5112 5178 tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity) 5113 5179 tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color 5114 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n \n\n' %vertex_color5180 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color 5115 5181 5116 5182 # Draws the axes if True 5117 5183 if axis: … … 5120 5186 tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};\n' 5121 5187 5122 5188 # Create the coordinate of the vertices: 5123 tikz_pic += '%% Coordinate of the vertices:\n \n'5189 tikz_pic += '%% Coordinate of the vertices:\n%%\n' 5124 5190 for v in self.Vrep_generator(): 5125 5191 tikz_pic += dict_drawing[v][1] 5126 5192 5127 5193 # Draw the interior by going in a cycle 5128 tikz_pic += ' \n\n%% Drawing the interior\n\n'5194 tikz_pic += '%%\n%%\n%% Drawing the interior\n%%\n' 5129 5195 cyclic_vert = cyclic_sort_vertices_2d(list(self.Vrep_generator())) 5130 5196 tikz_pic += '\\fill[facet] ' 5131 5197 for v in cyclic_vert: … … 5133 5199 tikz_pic += 'cycle {};\n' 5134 5200 5135 5201 # Draw the edges in the front 5136 tikz_pic += ' \n\n%% Drawing edges in the front\n\n'5202 tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n' 5137 5203 tikz_pic += edges 5138 5204 5139 5205 # Finally, the vertices in front are drawn on top of everything. 5140 tikz_pic += ' \n\n%% Drawing the vertices in the front\n\n'5206 tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n' 5141 5207 for v in self.Vrep_generator(): 5142 5208 tikz_pic += dict_drawing[v][0] 5143 tikz_pic += ' \n\n\\end{tikzpicture}'5144 5145 return tikz_pic5146 5147 def _tikz_3d_in_3d(self, view, rot_angle, scale, edge_color,5209 tikz_pic += '%%\n%%\n\\end{tikzpicture}' 5210 5211 return LatexExpr(tikz_pic) 5212 5213 def _tikz_3d_in_3d(self, view, angle, scale, edge_color, 5148 5214 facet_color, opacity, vertex_color, axis): 5149 5215 """ 5150 5216 Return a string ``tikz_pic`` consisting of a tikz picture of ``self`` 5151 according to a projection ``view`` and an angle `` rot_angle``5217 according to a projection ``view`` and an angle ``angle`` 5152 5218 obtained via Jmol through the current state property. 5153 5219 5154 5220 INPUT: 5155 5221 5156 - ``view`` -- a list of length 3 representing a vector; 5157 - ``rot_angle`` -- an angle in degree from 0 to 360; 5158 - ``scale`` -- an integer specifying the scaling of the tikz picture; 5159 - ``edge_color``, ``facet_color``, ``vertex_color`` -- string 5160 representing colors which tikz recognize; 5161 - ``opacity`` -- a real number between 0 and 1 giving the opacity of 5162 the front facets; 5163 - ``axis`` -- a Boolean, to draw the axes at the origin. 5164 5165 """ 5166 V = VectorSpace(RDF,3) 5167 view_vector = V(view) 5168 rot = rotate_arbitrary(view_vector,-(rot_angle/360)*2*pi) 5222 - ``view`` - list (default: [0,0,1]) representing the rotation axis. 5223 - ``angle`` - integer angle of rotation in degree from 0 to 360. 5224 - ``scale`` - integer specifying the scaling of the tikz picture. 5225 - ``edge_color`` - string representing colors which tikz 5226 recognize. 5227 - ``facet_color`` - string representing colors which tikz 5228 recognize. 5229 - ``vertex_color`` - string representing colors which tikz 5230 recognize. 5231 - ``opacity`` - real number between 0 and 1 giving the opacity of 5232 the front facets. 5233 - ``axis`` - Boolean draw the axes at the origin or not. 5234 5235 OUTPUT: 5236 5237 - LatexExpr -- containing the TikZ picture. 5238 5239 EXAMPLES:: 5240 5241 sage: P = polytopes.small_rhombicuboctahedron() 5242 sage: Image = P._tikz_3d_in_3d([3,7,5], 100, scale=3, edge_color='blue', facet_color='orange', opacity=0.5, vertex_color='green', axis=True) 5243 sage: type(Image) 5244 <class 'sage.misc.latex.LatexExpr'> 5245 sage: print '\n'.join(Image.splitlines()[:4]) 5246 \begin{tikzpicture}% 5247 [x={(-0.046385cm, 0.837431cm)}, 5248 y={(-0.243536cm, 0.519228cm)}, 5249 z={(0.968782cm, 0.170622cm)}, 5250 sage: open('polytope-tikz1.tex', 'w').write(Image1) # not tested 5251 5252 """ 5253 5254 view_vector = vector(RDF, view) 5255 rot = rotate_arbitrary(view_vector,-(angle/360)*2*pi) 5169 5256 rotation_matrix = rot[:2].transpose() 5170 proj_vector = (rot**(-1))* V([0,0,1])5257 proj_vector = (rot**(-1))*vector(RDF, [0,0,1]) 5171 5258 5172 5259 # First compute the back and front vertices and facets 5173 5260 front_facets = [] … … 5228 5315 # Start to write the output 5229 5316 tikz_pic = '' 5230 5317 tikz_pic += '\\begin{tikzpicture}%\n' 5231 tikz_pic += '\t[x={(%fcm, %fcm)},\n' %( n(rotation_matrix[0][0]),n(rotation_matrix[0][1]))5232 tikz_pic += '\ty={(%fcm, %fcm)},\n' %( n(rotation_matrix[1][0]),n(rotation_matrix[1][1]))5233 tikz_pic += '\tz={(%fcm, %fcm)},\n' %( n(rotation_matrix[2][0]),n(rotation_matrix[2][1]))5318 tikz_pic += '\t[x={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[0][0]),RDF(rotation_matrix[0][1])) 5319 tikz_pic += '\ty={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[1][0]),RDF(rotation_matrix[1][1])) 5320 tikz_pic += '\tz={(%fcm, %fcm)},\n' %(RDF(rotation_matrix[2][0]),RDF(rotation_matrix[2][1])) 5234 5321 tikz_pic += '\tscale=%f,\n' %scale 5235 5322 tikz_pic += '\tback/.style={loosely dotted, thin},\n' 5236 5323 tikz_pic += '\tedge/.style={color=%s, thick},\n' %edge_color 5237 5324 tikz_pic += '\tfacet/.style={fill=%s,fill opacity=%f},\n' %(facet_color,opacity) 5238 5325 tikz_pic += '\tvertex/.style={inner sep=1pt,circle,draw=%s!25!black,' %vertex_color 5239 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n \n\n' %vertex_color5326 tikz_pic += 'fill=%s!75!black,thick,anchor=base}]\n%%\n%%\n' %vertex_color 5240 5327 5241 5328 # Draws the axes if True 5242 5329 if axis: … … 5245 5332 tikz_pic += '\\draw[color=black,thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};\n' 5246 5333 5247 5334 # Create the coordinate of the vertices 5248 tikz_pic += '%% Coordinate of the vertices:\n \n'5335 tikz_pic += '%% Coordinate of the vertices:\n%%\n' 5249 5336 for v in self.Vrep_generator(): 5250 5337 tikz_pic += dict_drawing[v][1] 5251 5338 5252 5339 # Draw the edges in the back 5253 tikz_pic += ' \n\n%% Drawing edges in the back\n\n'5340 tikz_pic += '%%\n%%\n%% Drawing edges in the back\n%%\n' 5254 5341 tikz_pic += first_part 5255 5342 5256 5343 # Draw the vertices on top of the back-edges 5257 tikz_pic += ' \n\n%% Drawing vertices in the back\n\n'5344 tikz_pic += '%%\n%%\n%% Drawing vertices in the back\n%%\n' 5258 5345 for v in self.Vrep_generator(): 5259 5346 if v in back_vertices and v not in front_vertices: 5260 5347 tikz_pic += dict_drawing[v][0] 5261 5348 5262 5349 # Draw the facets in the front by going in cycles for every facet. 5263 tikz_pic += ' \n\n%% Drawing the facets\n\n'5350 tikz_pic += '%%\n%%\n%% Drawing the facets\n%%\n' 5264 5351 for facet in front_facets: 5265 5352 cyclic_vert = cyclic_sort_vertices_2d(list(facet.incident())) 5266 5353 tikz_pic += '\\fill[facet] ' … … 5269 5356 tikz_pic += 'cycle {};\n' 5270 5357 5271 5358 # Draw the edges in the front 5272 tikz_pic += ' \n\n%% Drawing edges in the front\n\n'5359 tikz_pic += '%%\n%%\n%% Drawing edges in the front\n%%\n' 5273 5360 tikz_pic += second_part 5274 5361 5275 5362 # Finally, the vertices in front are drawn on top of everything. 5276 tikz_pic += ' \n\n%% Drawing the vertices in the front\n\n'5363 tikz_pic += '%%\n%%\n%% Drawing the vertices in the front\n%%\n' 5277 5364 for v in self.Vrep_generator(): 5278 5365 if v in front_vertices: 5279 5366 tikz_pic += dict_drawing[v][0] 5280 tikz_pic += ' \n\n\\end{tikzpicture}'5281 5282 return tikz_pic5367 tikz_pic += '%%\n%%\n\\end{tikzpicture}' 5368 5369 return LatexExpr(tikz_pic) 5283 5370 5284 5371 ############################################################# 5285 5372 def cyclic_sort_vertices_2d(Vlist):