Adaptive refinement code for 3d surface plotting#

AUTHOR:

  • Tom Boothby – Algorithm design, code

  • Joshua Kantor – Algorithm design

  • Marshall Hampton – Docstrings and doctests

Todo

  • Parametrizations (cylindrical, spherical)

  • Massive optimization

class sage.plot.plot3d.tri_plot.PlotBlock(left, left_c, top, top_c, right, right_c, bottom, bottom_c)#

Bases: object

A container class to hold information about spatial blocks.

class sage.plot.plot3d.tri_plot.SmoothTriangle(a, b, c, da, db, dc, color=0)#

Bases: Triangle

A class for smoothed triangles.

get_normals()#

Returns the normals to vertices a, b, and c.

str()#

Returns a string representation of the SmoothTriangle of the form

a b c color da db dc

where a, b, and c are the triangle corner coordinates, da, db, dc are normals at each corner, and color is the color.

class sage.plot.plot3d.tri_plot.Triangle(a, b, c, color=0)#

Bases: object

A graphical triangle class.

get_vertices()#

Returns a tuple of vertex coordinates of the triangle.

set_color(color)#

This method will reset the color of the triangle.

str()#

Returns a string representation of an instance of the Triangle class of the form

a b c color

where a, b, and c are corner coordinates and color is the color.

class sage.plot.plot3d.tri_plot.TriangleFactory#

Bases: object

get_colors(list)#

Parameters: list: an iterable collection of values which can be cast into colors – typically an RGB triple, or an RGBA 4-tuple

Returns: a list of single parameters which can be passed into the set_color method of the Triangle or SmoothTriangle objects generated by this factory.

smooth_triangle(a, b, c, da, db, dc, color=None)#

Parameters:

  • a, b, c : triples (x,y,z) representing corners on a triangle in 3-space

  • da, db, dc : triples (dx,dy,dz) representing the normal vector at each point a,b,c

Returns: a SmoothTriangle object with the specified coordinates and normals

triangle(a, b, c, color=None)#

Parameters: a, b, c : triples (x,y,z) representing corners on a triangle in 3-space

Returns: a Triangle object with the specified coordinates

class sage.plot.plot3d.tri_plot.TrianglePlot(triangle_factory, f, min_x__max_x, min_y__max_y, g=None, min_depth=4, max_depth=8, num_colors=None, max_bend=0.3)#

Bases: object

Recursively plots a function of two variables by building squares of 4 triangles, checking at every stage whether or not each square should be split into four more squares. This way, more planar areas get fewer triangles, and areas with higher curvature get more triangles.

extrema(list)#

If the num_colors option has been set, this expands the TrianglePlot’s _min and _max attributes to include the minimum and maximum of the argument list.

interface(n, p, p_c, q, q_c)#

Takes a pair of lists of points, and compares the (n)th coordinate, and “zips” the lists together into one. The “centers”, supplied in p_c and q_c are matched up such that the lists describe triangles whose sides are “perfectly” aligned. This algorithm assumes that p and q start and end at the same point, and are sorted smallest to largest.

plot_block(min_x, mid_x, max_x, min_y, mid_y, max_y, sw_z, nw_z, se_z, ne_z, mid_z, depth)#

Recursive triangulation function for plotting.

First six inputs are scalars, next 5 are 2-dimensional lists, and the depth argument keeps track of the depth of recursion.

str()#

Return a string listing the objects in the instance of the TrianglePlot class.

triangulate(p, c)#

Pass in a list of edge points (p) and center points (c). Triangles will be rendered between consecutive edge points and the center point with the same index number as the earlier edge point.

sage.plot.plot3d.tri_plot.crossunit(u, v)#

This function computes triangle normal unit vectors by taking the cross-products of the midpoint-to-corner vectors. It always goes around clockwise so we’re guaranteed to have a positive value near 1 when neighboring triangles are parallel. However – crossunit doesn’t really return a unit vector. It returns the length of the vector to avoid numerical instability when the length is nearly zero – rather than divide by nearly zero, we multiply the other side of the inequality by nearly zero – in general, this should work a bit better because of the density of floating-point numbers near zero.