AUTHORS:
Bases: sage.plot.plot3d.base.PrimitiveObject
Draw a 3d line joining a sequence of points.
This line has a fixed diameter unaffected by transformations and zooming. It may be smoothed if corner_cutoff < 1.
INPUT:
EXAMPLES:
sage: from sage.plot.plot3d.shapes2 import Line
sage: Line([(i*math.sin(i), i*math.cos(i), i/3) for i in range(30)], arrow_head=True)
Graphics3d Object
Smooth angles less than 90 degrees:
sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=0)
Graphics3d Object
Return the lower and upper corners of a 3-D bounding box for self.
This is used for rendering and self should fit entirely within this box. In this case, we return the highest and lowest values of each coordinate among all points.
TESTS:
sage: from sage.plot.plot3d.shapes2 import Line
sage: L = Line([(i,i^2-1,-2*ln(i)) for i in [10,20,30]])
sage: L.bounding_box()
((10.0, 99.0, -6.802394763324311), (30.0, 899.0, -4.605170185988092))
Figure out where the curve turns too sharply to pretend it is smooth.
INPUT:
Maximum cosine of angle between adjacent line segments before adding a corner
OUTPUT:
List of points at which to start a new line. This always includes the first point, and never the last.
EXAMPLES:
Every point:
sage: from sage.plot.plot3d.shapes2 import Line
sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=1).corners()
[(0, 0, 0), (1, 0, 0), (2, 1, 0)]
Greater than 90 degrees:
sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=0).corners()
[(0, 0, 0), (2, 1, 0)]
No corners:
sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=-1).corners()
(0, 0, 0)
An intermediate value:
sage: Line([(0,0,0),(1,0,0),(2,1,0),(0,1,0)], corner_cutoff=.5).corners()
[(0, 0, 0), (2, 1, 0)]
Return representation of the object suitable for plotting using Jmol.
TESTS:
sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red')
sage: L.jmol_repr(L.default_render_params())[0][:42]
'draw line_1 diameter 1 curve {1.0 0.0 0.0}'
Return complete representation of the line as an object.
TESTS:
sage: from sage.plot.plot3d.shapes2 import Line
sage: L = Line([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red')
sage: L.obj_repr(L.default_render_params())[0][0][0][2][:3]
['v 0.99995 0.00999983 0.0001', 'v 1.00007 0.0102504 -0.0248984', 'v 1.02376 0.010195 -0.00750607']
Return representation of the line suitable for plotting using the Tachyon ray tracer.
TESTS:
sage: L = line3d([(cos(i),sin(i),i^2) for i in srange(0,10,.01)],color='red')
sage: L.tachyon_repr(L.default_render_params())[0]
'FCylinder base 1.0 0.0 0.0 apex 0.999950000417 0.00999983333417 0.0001 rad 0.005 texture...'
Bases: sage.plot.plot3d.base.PrimitiveObject
Create a position in 3-space, represented by a sphere of fixed size.
INPUT:
EXAMPLE:
We normally access this via the point3d function. Note that extra keywords are correctly used:
sage: point3d((4,3,2),size=2,color='red',opacity=.5)
Graphics3d Object
Returns the lower and upper corners of a 3-D bounding box for self.
This is used for rendering and self should fit entirely within this box. In this case, we simply return the center of the point.
TESTS:
sage: P = point3d((-3,2,10),size=7)
sage: P.bounding_box()
((-3.0, 2.0, 10.0), (-3.0, 2.0, 10.0))
Return representation of the object suitable for plotting using Jmol.
TESTS:
sage: P = point3d((1,2,3),size=3,color='purple')
sage: P.jmol_repr(P.default_render_params())
['draw point_1 DIAMETER 3 {1.0 2.0 3.0}\ncolor $point_1 [128,0,128]']
Return complete representation of the point as a sphere.
TESTS:
sage: P = point3d((1,2,3),size=3,color='purple')
sage: P.obj_repr(P.default_render_params())[0][0:2]
['g obj_1', 'usemtl texture...']
Return representation of the point suitable for plotting using the Tachyon ray tracer.
TESTS:
sage: P = point3d((1,2,3),size=3,color='purple')
sage: P.tachyon_repr(P.default_render_params())
'Sphere center 1.0 2.0 3.0 Rad 0.015 texture...'
Draw a 3-dimensional bezier path.
Input is similar to bezier_path, but each point in the path and each control point is required to have 3 coordinates.
INPUT:
detail below.
thickness – (default: 2)
color – a string ("red", "green" etc) or a tuple (r, g, b) with r, g, b numbers between 0 and 1
opacity – (default: 1) if less than 1 then is transparent
aspect_ratio – (default:[1,1,1])
The path is a list of curves, and each curve is a list of points. Each point is a tuple (x,y,z).
The first curve contains the endpoints as the first and last point in the list. All other curves assume a starting point given by the last entry in the preceding list, and take the last point in the list as their opposite endpoint. A curve can have 0, 1 or 2 control points listed between the endpoints. In the input example for path below, the first and second curves have 2 control points, the third has one, and the fourth has no control points:
path = [[p1, c1, c2, p2], [c3, c4, p3], [c5, p4], [p5], ...]
In the case of no control points, a straight line will be drawn between the two endpoints. If one control point is supplied, then the curve at each of the endpoints will be tangent to the line from that endpoint to the control point. Similarly, in the case of two control points, at each endpoint the curve will be tangent to the line connecting that endpoint with the control point immediately after or immediately preceding it in the list.
So in our example above, the curve between p1 and p2 is tangent to the line through p1 and c1 at p1, and tangent to the line through p2 and c2 at p2. Similarly, the curve between p2 and p3 is tangent to line(p2,c3) at p2 and tangent to line(p3,c4) at p3. Curve(p3,p4) is tangent to line(p3,c5) at p3 and tangent to line(p4,c5) at p4. Curve(p4,p5) is a straight line.
EXAMPLES:
sage: path = [[(0,0,0),(.5,.1,.2),(.75,3,-1),(1,1,0)],[(.5,1,.2),(1,.5,0)],[(.7,.2,.5)]]
sage: b = bezier3d(path, color='green')
sage: b
Graphics3d Object
To construct a simple curve, create a list containing a single list:
sage: path = [[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]
sage: curve = bezier3d(path, thickness=5, color='blue')
sage: curve
Graphics3d Object
Draw a frame in 3-D.
Primarily used as a helper function for creating frames for 3-D graphics viewing.
INPUT:
Type line3d.options for a dictionary of the default options for lines, which are also available.
EXAMPLES:
A frame:
sage: from sage.plot.plot3d.shapes2 import frame3d
sage: frame3d([1,3,2],vector([2,5,4]),color='red')
Graphics3d Object
This is usually used for making an actual plot:
sage: y = var('y')
sage: plot3d(sin(x^2+y^2),(x,0,pi),(y,0,pi))
Graphics3d Object
Draw correct labels for a given frame in 3-D.
Primarily used as a helper function for creating frames for 3-D graphics viewing - do not use directly unless you know what you are doing!
INPUT:
Type line3d.options for a dictionary of the default options for lines, which are also available.
EXAMPLES:
We can use it directly:
sage: from sage.plot.plot3d.shapes2 import frame_labels
sage: frame_labels([1,2,3],[4,5,6],[1,2,3],[4,5,6])
Graphics3d Object
This is usually used for making an actual plot:
sage: y = var('y')
sage: P = plot3d(sin(x^2+y^2),(x,0,pi),(y,0,pi))
sage: a,b = P._rescale_for_frame_aspect_ratio_and_zoom(1.0,[1,1,1],1)
sage: F = frame_labels(a,b,*P._box_for_aspect_ratio("automatic",a,b))
sage: F.jmol_repr(F.default_render_params())[0]
[['select atomno = 1', 'color atom [76,76,76]', 'label "0.0"']]
TESTS:
sage: frame_labels([1,2,3],[4,5,6],[1,2,3],[1,3,4])
Traceback (most recent call last):
...
ValueError: Ensure the upper right labels are above and to the right of the lower left labels.
Draw a 3d line joining a sequence of points.
One may specify either a thickness or radius. If a thickness is specified, this line will have a constant diameter regardless of scaling and zooming. If a radius is specified, it will behave as a series of cylinders.
INPUT:
EXAMPLES:
A line in 3-space:
sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)])
Graphics3d Object
The same line but red:
sage: line3d([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)], color='red')
Graphics3d Object
The points of the line provided as a numpy array:
sage: import numpy
sage: line3d(numpy.array([(1,2,3), (1,0,-2), (3,1,4), (2,1,-2)]))
Graphics3d Object
A transparent thick green line and a little blue line:
sage: line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1,
....: color='green') + line3d([(0,1,0), (1,0,2)])
Graphics3d Object
A Dodecahedral complex of 5 tetrahedrons (a more elaborate example from Peter Jipsen):
sage: def tetra(col):
....: return line3d([(0,0,1), (2*sqrt(2.)/3,0,-1./3), (-sqrt(2.)/3, sqrt(6.)/3,-1./3),\
....: (-sqrt(2.)/3,-sqrt(6.)/3,-1./3), (0,0,1), (-sqrt(2.)/3, sqrt(6.)/3,-1./3),\
....: (-sqrt(2.)/3,-sqrt(6.)/3,-1./3), (2*sqrt(2.)/3,0,-1./3)],\
....: color=col, thickness=10, aspect_ratio=[1,1,1])
sage: v = (sqrt(5.)/2-5/6, 5/6*sqrt(3.)-sqrt(15.)/2, sqrt(5.)/3)
sage: t = acos(sqrt(5.)/3)/2
sage: t1 = tetra('blue').rotateZ(t)
sage: t2 = tetra('red').rotateZ(t).rotate(v,2*pi/5)
sage: t3 = tetra('green').rotateZ(t).rotate(v,4*pi/5)
sage: t4 = tetra('yellow').rotateZ(t).rotate(v,6*pi/5)
sage: t5 = tetra('orange').rotateZ(t).rotate(v,8*pi/5)
sage: show(t1+t2+t3+t4+t5, frame=False)
TESTS:
Copies are made of the input list, so the input list does not change:
sage: mypoints = [vector([1,2,3]), vector([4,5,6])]
sage: type(mypoints[0])
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
sage: L = line3d(mypoints)
sage: type(mypoints[0])
<type 'sage.modules.vector_integer_dense.Vector_integer_dense'>
The copies are converted to a list, so we can pass in immutable objects too:
sage: L = line3d(((0,0,0),(1,2,3)))
This function should work for anything than can be turned into a list, such as iterators and such (see trac ticket #10478):
sage: line3d(iter([(0,0,0), (sqrt(3), 2, 4)]))
Graphics3d Object
sage: line3d((x, x^2, x^3) for x in range(5))
Graphics3d Object
sage: from itertools import izip; line3d(izip([2,3,5,7], [11, 13, 17, 19], [-1, -2, -3, -4]))
Graphics3d Object
Plot a point or list of points in 3d space.
INPUT:
EXAMPLES:
sage: sum([point3d((i,i^2,i^3), size=5) for i in range(10)])
Graphics3d Object
We check to make sure this works with vectors and other iterables:
sage: pl = point3d([vector(ZZ,(1, 0, 0)), vector(ZZ,(0, 1, 0)), (-1, -1, 0)])
sage: print point(vector((2,3,4)))
Graphics3d Object
sage: c = polytopes.n_cube(3)
sage: v = c.vertices()[0]; v
A vertex at (-1, -1, -1)
sage: print point(v)
Graphics3d Object
We check to make sure the options work:
sage: point3d((4,3,2),size=20,color='red',opacity=.5)
Graphics3d Object
numpy arrays can be provided as input:
sage: import numpy
sage: point3d(numpy.array([1,2,3]))
Graphics3d Object
sage: point3d(numpy.array([[1,2,3], [4,5,6], [7,8,9]]))
Graphics3d Object
We check that iterators of points are accepted (trac ticket #13890):
sage: point3d(iter([(1,1,2),(2,3,4),(3,5,8)]),size=20,color='red')
Graphics3d Object
TESTS:
sage: point3d([])
Graphics3d Object
Draw a polygon in 3d.
INPUT:
Type polygon3d.options for a dictionary of the default options for polygons. You can change this to change the defaults for all future polygons. Use polygon3d.reset() to reset to the default options.
EXAMPLES:
A simple triangle:
sage: polygon3d([[0,0,0], [1,2,3], [3,0,0]])
Graphics3d Object
Some modern art – a random polygon:
sage: v = [(randrange(-5,5), randrange(-5,5), randrange(-5, 5)) for _ in range(10)]
sage: polygon3d(v)
Graphics3d Object
A bent transparent green triangle:
sage: polygon3d([[1, 2, 3], [0,1,0], [1,0,1], [3,0,0]], color=(0,1,0), alpha=0.7)
Graphics3d Object
Draw a ruler in 3-D, with major and minor ticks.
INPUT:
Type line3d.options for a dictionary of the default options for lines, which are also available.
EXAMPLES:
A ruler:
sage: from sage.plot.plot3d.shapes2 import ruler
sage: R = ruler([1,2,3],vector([2,3,4])); R
Graphics3d Object
A ruler with some options:
sage: R = ruler([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); R
Graphics3d Object
The keyword snap makes the ticks not necessarily coincide with the ruler:
sage: ruler([1,2,3],vector([1,2,4]),snap=True)
Graphics3d Object
The keyword absolute makes a huge ruler in one of the axis directions:
sage: ruler([1,2,3],vector([1,2,4]),absolute=True)
Graphics3d Object
TESTS:
sage: ruler([1,2,3],vector([1,3,4]),absolute=True)
Traceback (most recent call last):
...
ValueError: Absolute rulers only valid for axis-aligned paths
Draw a frame made of 3-D rulers, with major and minor ticks.
INPUT:
Type line3d.options for a dictionary of the default options for lines, which are also available.
EXAMPLES:
A ruler frame:
sage: from sage.plot.plot3d.shapes2 import ruler_frame
sage: F = ruler_frame([1,2,3],vector([2,3,4])); F
Graphics3d Object
A ruler frame with some options:
sage: F = ruler_frame([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); F
Graphics3d Object
Return a plot of a sphere of radius size centered at \((x,y,z)\).
INPUT:
EXAMPLES: A simple sphere:
sage: sphere()
Graphics3d Object
Two spheres touching:
sage: sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1])
Graphics3d Object
Spheres of radii 1 and 2 one stuck into the other:
sage: sphere(color='orange') + sphere(color=(0,0,0.3),
....: center=(0,0,-2),size=2,opacity=0.9)
Graphics3d Object
We draw a transparent sphere on a saddle.
sage: u,v = var('u v')
sage: saddle = plot3d(u^2 - v^2, (u,-2,2), (v,-2,2))
sage: sphere((0,0,1), color='red', opacity=0.5, aspect_ratio=[1,1,1]) + saddle
Graphics3d Object
TESTS:
sage: T = sage.plot.plot3d.texture.Texture('red')
sage: S = sphere(texture=T)
sage: T in S.texture_set()
True
Display 3d text.
INPUT:
Note
There is no way to change the font size or opacity yet.
EXAMPLES:
We write the word Sage in red at position (1,2,3):
sage: text3d("Sage", (1,2,3), color=(0.5,0,0))
Graphics3d Object
We draw a multicolor spiral of numbers:
sage: sum([text3d('%.1f'%n, (cos(n),sin(n),n), color=(n/2,1-n/2,0))
....: for n in [0,0.2,..,8]])
Graphics3d Object
Another example:
sage: text3d("Sage is really neat!!",(2,12,1))
Graphics3d Object
And in 3d in two places:
sage: text3d("Sage is...",(2,12,1), color=(1,0,0)) + text3d("quite powerful!!",(4,10,0), color=(0,0,1))
Graphics3d Object