def plot3d(self): """ Plots the braid in 3d. EXAMPLES:: sage: B = BraidGroup(4, 's') sage: b = B([1, 2, 3, 1, 2, 1]) sage: b.plot3d() """ from sage.plot.plot3d.shapes2 import bezier3d b = [] braid = self.Tietze() n = self.strands() for i in range(len(braid)): m = braid[i] for j in range(n): if m==j+1: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (0.25, j, i+0.25), (0.25, j+0.5, i+0.5)], [(0.25, j+1, i+0.75), (0, j+1, i+0.75), (0, j+1, i+1)]])) elif -m==j+1: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (-0.25, j, i+0.25), (-0.25, j+0.5, i+0.5)], [(-0.25, j+1, i+0.75), (0, j+1, i+0.75), (0, j+1, i+1)]])) elif m==j: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (-0.25, j, i+0.25), (-0.25, j-0.5, i+0.5)], [(-0.25, j-1, i+0.75), (0, j-1, i+0.75), (0, j-1, i+1)]])) elif -m==j: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (0.25, j, i+0.25), (0.25, j-0.5, i+0.5)], [(0.25, j-1, i+0.75), (0, j-1, i+0.75), (0, j-1, i+1)]])) else: b.append(bezier3d([[(0, j, i), (0, j, i+1)]])) return sum(b)
def plot3d(self, color='rainbow'): """ Plots the braid in 3d. The following option is available: - ``color`` -- (default: ``'rainbow'``) the color of the strands. Possible values are: * ``'rainbow'``, uses :meth:`~sage.plot.colors.rainbow` according to the number of strands. * a valid color name for :meth:`~sage.plot.plot3d.bezier3d`. Used for all strands. * a list or a tuple of colors for each individual strand. EXAMPLES:: sage: B = BraidGroup(4, 's') sage: b = B([1, 2, 3, 1, 2, 1]) sage: b.plot3d() sage: b.plot3d(color="red") sage: b.plot3d(color=["red", "blue", "red", "blue"]) """ from sage.plot.plot3d.shapes2 import bezier3d from sage.plot.colors import rainbow b = [] n = self.strands() if isinstance(color, (list, tuple)): if len(color) != n: raise TypeError("color (=%s) must contain exactly %d colors" % (color, n)) col = list(color) elif color == "rainbow": col = rainbow(n) else: col = [color]*n braid = self.Tietze() for i, m in enumerate(braid): for j in range(n): if m==j+1: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (0.25, j, i+0.25), (0.25, j+0.5, i+0.5)], [(0.25, j+1, i+0.75), (0, j+1, i+0.75), (0, j+1, i+1)]], color=col[j])) elif -m==j+1: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (-0.25, j, i+0.25), (-0.25, j+0.5, i+0.5)], [(-0.25, j+1, i+0.75), (0, j+1, i+0.75), (0, j+1, i+1)]], color=col[j])) elif m==j: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (-0.25, j, i+0.25), (-0.25, j-0.5, i+0.5)], [(-0.25, j-1, i+0.75), (0, j-1, i+0.75), (0, j-1, i+1)]], color=col[j])) col[j], col[j-1] = col[j-1], col[j] elif -m==j: b.append(bezier3d([[(0, j, i), (0, j, i+0.25), (0.25, j, i+0.25), (0.25, j-0.5, i+0.5)], [(0.25, j-1, i+0.75), (0, j-1, i+0.75), (0, j-1, i+1)]], color=col[j])) col[j], col[j-1] = col[j-1], col[j] else: b.append(bezier3d([[(0, j, i), (0, j, i+1)]], color=col[j])) return sum(b)
def plot3d(self, z=0, **kwds): """ Returns a 3D plot (Jmol) of the Bezier path. Since a ``BezierPath`` primitive contains only `x,y` coordinates, the path will be drawn in some plane (default is `z=0`). To create a Bezier path with nonzero (and nonidentical) `z` coordinates in the path and control points, use the function :func:`~sage.plot.plot3d.shapes2.bezier3d` instead of :func:`bezier_path`. EXAMPLES:: sage: b = bezier_path([[(0,0),(0,1),(1,0)]]) sage: A = b.plot3d() sage: B = b.plot3d(z=2) sage: A+B :: sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) """ from sage.plot.plot3d.shapes2 import bezier3d options = self._plot3d_options() options.update(kwds) return bezier3d([[(x, y, 0) for x, y in self.path[i]] for i in range(len(self.path))], **options)
def plot3d(self, z=0, **kwds): """ Returns a 3D plot (Jmol) of the Bezier path. Since a ``BezierPath`` primitive contains only `x,y` coordinates, the path will be drawn in some plane (default is `z=0`). To create a Bezier path with nonzero (and nonidentical) `z` coordinates in the path and control points, use the function :func:`~sage.plot.plot3d.shapes2.bezier3d` instead of :func:`bezier_path`. EXAMPLES:: sage: b = bezier_path([[(0,0),(0,1),(1,0)]]) sage: A = b.plot3d() sage: B = b.plot3d(z=2) sage: A + B Graphics3d Object .. PLOT:: b = bezier_path([[(0,0),(0,1),(1,0)]]) A = b.plot3d() B = b.plot3d(z=2) sphinx_plot(A + B) :: sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) Graphics3d Object .. PLOT:: sphinx_plot(bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]])) """ from sage.plot.plot3d.shapes2 import bezier3d options = self._plot3d_options() options.update(kwds) return bezier3d([[(x,y,0) for x,y in self.path[i]] for i in range(len(self.path))], **options)