Changeset 7864:25a5e79d10a7


Ignore:
Timestamp:
12/18/07 22:30:51 (5 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

3d plotting -- some work: (1) fast_float_function started; (2) improved documentation; (3) make line(...) 3d-aware.

Location:
sage
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • sage/calculus/calculus.py

    r7525 r7864  
    592592                    param = A[0] 
    593593                f = lambda x: self(x) 
     594                #f = self.fast_float_function() 
    594595            else: 
    595596                A = self.variables() 
     
    27672768        return self.parent()(self._maxima_().partfrac(var)) 
    27682769 
    2769  
    2770  
     2770    ################################################################### 
     2771    # Fast Evaluation 
     2772    ################################################################### 
     2773    def fast_float_function(self): 
     2774        return self._fast_float_() 
     2775 
     2776    def _fast_float_(self): 
     2777        return   lambda x: float(self(x)) 
     2778         
    27712779 
    27722780class Symbolic_object(SymbolicExpression): 
     
    29102918                if isinstance(self._obj, int): 
    29112919                    return True 
     2920 
     2921    def _fast_float_(self): 
     2922        z = float(self) 
     2923        return lambda x: z 
    29122924 
    29132925    def _recursive_sub(self, kwds): 
     
    37303742        return hash(self._name) 
    37313743 
     3744    def _fast_float_(self): 
     3745        return lambda x: x 
     3746 
    37323747    def _recursive_sub(self, kwds): 
    37333748        # do the replacement if needed 
     
    43494364        return float(f._approx_(float(g))) 
    43504365 
     4366    def _fast_float_(self): 
     4367        f = self._operands[0]._fast_float_() 
     4368        g = self._operands[1]._fast_float_() 
     4369        return lambda x: f(g(x)) 
     4370 
    43514371    def __complex__(self): 
    43524372        """ 
     
    47394759        return SymbolicComposition(self, SR(x)) 
    47404760 
     4761    def _fast_float_(self): 
     4762        return math.sin 
     4763 
    47414764sin = Function_sin() 
    47424765_syms['sin'] = sin 
     
    47614784                return math.cos(x) 
    47624785        return SymbolicComposition(self, SR(x)) 
     4786 
     4787    def _fast_float_(self): 
     4788        return math.cos 
    47634789 
    47644790    
  • sage/plot/all.py

    r7861 r7864  
    99from animate import Animation as animate 
    1010 
    11 from plot3dmatplotlib import (Graphics3d, point3d, line3d, plot3d) 
     11# This needs to be deprecated.  It's crap and pointless.  
     12#from plot3dmatplotlib import (Graphics3d, point3d, line3d, plot3d) 
    1213 
    1314from plot3dsoya_wrap import plot3dsoya 
  • sage/plot/plot.py

    r7394 r7864  
    14711471        return to_float_list(xdata), to_float_list(ydata) 
    14721472 
     1473    def _graphic3d(self, *args, **kwds): 
     1474        """ 
     1475        Return 3d version of this graphics primitive. 
     1476 
     1477        We call this if the user tries to create a graphic but gives 
     1478        points (etc) in 3-space instead of in the plane. 
     1479        """ 
     1480        raise NotImplementedError, "3d plotting of this primitive not yet implemented" 
     1481 
    14731482class GraphicPrimitiveFactory_arrow(GraphicPrimitiveFactory): 
    14741483    def __call__(self, minpoint, maxpoint, **kwds): 
     
    16121621        done = False 
    16131622        if not isinstance(points, (list,tuple)) or \ 
    1614            (isinstance(points,(list,tuple)) and len(points) == 2): 
     1623           (isinstance(points,(list,tuple)) and len(points) <= 3 and not 
     1624            isinstance(points[0], (list,tuple))): 
    16151625            try: 
    1616                 xdata = [float(points[0])] 
    1617                 ydata = [float(points[1])] 
    1618                 done = True 
     1626                points = [[float(z) for z in points]] 
    16191627            except TypeError: 
    16201628                pass 
     
    16251633                ydata = [] 
    16261634                for z in points: 
     1635                    if len(z) == 3: 
     1636                        return self._graphic3d()(points, coerce=coerce, **kwds) 
    16271637                    xdata.append(float(z[0])) 
    16281638                    ydata.append(float(z[1])) 
    16291639            else: 
    1630                 xdata = [z[0] for z in points] 
    1631                 ydata = [z[1] for z in points] 
     1640                for z in points: 
     1641                    if len(z) == 3: 
     1642                        return self._graphic3d()(points, coerce=coerce, **kwds) 
     1643                    xdata.append(z[0]) 
     1644                    ydata.append(z[1]) 
    16321645 
    16331646        return self._from_xdata_ydata(xdata, ydata, True, options=options) 
     
    19471960            pass 
    19481961        return g 
     1962 
     1963    def _graphic3d(self): 
     1964        from sage.plot.plot3d.shapes2 import line3d 
     1965        return line3d 
    19491966 
    19501967# unique line instance 
  • sage/plot/plot3d/all.py

    r7732 r7864  
    1 from shapes import Box, ColorCube, Cone, Cylinder, Line, Arrow, Sphere, Torus, Text as Text3D 
     1from shapes import Box, ColorCube, Cone, Cylinder, Arrow, Sphere, Torus, Text as Text3D 
    22from parametric_surface import ParametricSurface, MobiusStrip 
    33from plot3d import plot3d, axes as axes3d 
  • sage/plot/plot3d/base.pyx

    r7863 r7864  
    216216        """ 
    217217        INPUT: 
     218            viewer -- string (default: 'jmol') which viewing system to use. 
     219                      'jmol': an embedded non-OpenGL 3d java applet 
     220                      'tachyon': an embedded ray tracer  
     221                      'java3d': a popup OpenGL 3d java applet 
     222            filename -- string (default: 'shape'); file to save the image to 
     223            verbosity -- display information about rendering the figure 
    218224            figsize -- (default: 4); x or pair [x,y] for numbers, e.g., [4,4]; controls 
    219                        the size of the output figure 
    220              
     225                       the size of the output figure.  E.g., with jmol the number of 
     226                       pixels in each direction is 100 times figsize[0]. 
     227            **kwds -- other options, which make sense for particular rendering engines            
    221228        """ 
    222229        if not isinstance(figsize, (list,tuple)): 
  • sage/plot/plot3d/plot3d.py

    r7861 r7864  
    6868    """ 
    6969    # Check if f has a fast float evaluation 
    70     try: 
    71         f = f.fast_float_function() 
    72     except AttributeError: 
    73         # Nope -- no prob. 
    74         pass 
     70    #try: 
     71    #    f = f.fast_float_function() 
     72    #except AttributeError: 
     73    #    # Nope -- no prob. 
     74    #    pass 
    7575     
    7676    if texture is None: 
  • sage/plot/plot3d/shapes.pyx

    r7861 r7864  
    180180             
    181181 
    182 def Line(start, end, radius, **kwds): 
     182def LineSegment(start, end, thickness=1, radius=None, **kwds): 
    183183    """ 
    184     Create a cylindar from start to end with radius radius. 
     184    Create a line segment, which is drawn as a cylinder from start to 
     185    end with radius radius. 
    185186     
    186187    EXAMPLES:  
    187         sage: from sage.plot.plot3d.shapes import Line, Sphere 
     188        sage: from sage.plot.plot3d.shapes import LineSegment, Sphere 
    188189        sage: P = (0,0,0.1) 
    189190        sage: Q = (0.5,0.6,0.7) 
    190191        sage: S = Sphere(.2, color='red').translate(P) + \ 
    191192                  Sphere(.2, color='blue').translate(Q) + \ 
    192                   Line(P, Q, .05, color='black') 
     193                  LineSegment(P, Q, .05, color='black') 
    193194        sage: S.show() 
    194195        sage: S = Sphere(.1, color='red').translate(P) + \ 
    195196                  Sphere(.1, color='blue').translate(Q) + \ 
    196                   Line(P, Q, .15, color='black') 
     197                  LineSegment(P, Q, .15, color='black') 
    197198        sage: S.show() 
    198199         
     
    200201        -- Robert Bradshaw 
    201202    """ 
     203    if radius is None: 
     204        radius = thickness/50.0 
    202205    start = vector(RDF, start, sparse=False) 
    203206    end = vector(RDF, end, sparse=False) 
     
    212215        theta = -acos(diff[2]/height) 
    213216        return cyl.rotate(axis, theta).translate(start) 
    214          
     217 
    215218def Arrow(start, end, radius, head_radius=None, head_len=None, **kwds): 
    216219    if head_radius == None: 
Note: See TracChangeset for help on using the changeset viewer.