From: <md...@us...> - 2007-11-06 15:48:47
|
Revision: 4123 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4123&view=rev Author: mdboom Date: 2007-11-06 07:48:22 -0800 (Tue, 06 Nov 2007) Log Message: ----------- Mistake in last commit. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-11-06 15:37:44 UTC (rev 4122) +++ branches/transforms/lib/matplotlib/path.py 2007-11-06 15:48:22 UTC (rev 4123) @@ -86,9 +86,11 @@ resulting path will be compressed, with MOVETO codes inserted in the correct places to jump over the masked regions. """ - mask = ma.getmask(vertices) - if not mask: - vertices = ma.asarray(vertices, npy.float_) + mask = ma.nomask + if ma.isMaskedArray(vertices): + mask = ma.getmask(vertices) + else: + vertices = npy.asarray(vertices, npy.float_) if codes is None: if len(vertices) == 0: @@ -121,8 +123,6 @@ codes = ma.masked_array(codes, mask=mask1d).compressed() codes = npy.asarray(codes, self.code_type) - vertices = npy.asarray(vertices, npy.float_) - assert vertices.ndim == 2 assert vertices.shape[1] == 2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-11-06 15:50:55
|
Revision: 4124 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4124&view=rev Author: mdboom Date: 2007-11-06 07:50:51 -0800 (Tue, 06 Nov 2007) Log Message: ----------- Update docstring to reflect reality. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-11-06 15:48:22 UTC (rev 4123) +++ branches/transforms/lib/matplotlib/path.py 2007-11-06 15:50:51 UTC (rev 4124) @@ -70,9 +70,11 @@ """ Create a new path with the given vertices and codes. - vertices is an Nx2 numpy float array. + vertices is an Nx2 numpy float array, masked array or Python + sequence. - codes is an N-length numpy array of type Path.code_type. + codes is an N-length numpy array or Python sequence of type + Path.code_type. See the docstring of Path for a description of the various codes. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-12-10 15:00:11
|
Revision: 4680 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4680&view=rev Author: mdboom Date: 2007-12-10 06:59:49 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Use an 8-spline approximation of an ellipse instead of a 4-spline one. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-12-10 14:50:40 UTC (rev 4679) +++ branches/transforms/lib/matplotlib/path.py 2007-12-10 14:59:49 UTC (rev 4680) @@ -15,8 +15,6 @@ path_in_path, path_intersects_path, convert_path_to_polygons from matplotlib.cbook import simple_linear_interpolation -KAPPA = 4.0 * (npy.sqrt(2) - 1) / 3.0 - class Path(object): """ Path represents a series of possibly disconnected, possibly @@ -350,33 +348,58 @@ def unit_circle(cls): """ Returns a Path of the unit circle. The circle is approximated - using cubic Bezier curves. + using cubic Bezier curves. This uses 8 splines around the + circle using the approach presented here: + + Lancaster, Don. Approximating a Circle or an Ellipse Using Four + Bezier Cubic Splines. + + http://www.tinaja.com/glib/ellipse4.pdf """ if cls._unit_circle is None: - offset = KAPPA + MAGIC = 0.2652031 + SQRT2 = npy.sqrt(0.5) + MAGIC45 = npy.sqrt((MAGIC*MAGIC) / 2.0) + vertices = npy.array( - [[-1.0, 0.0], + [[0.0, -1.0], - [-1.0, offset], - [-offset, 1.0], - [0.0, 1.0], + [MAGIC, -1.0], + [SQRT2-MAGIC45, -SQRT2-MAGIC45], + [SQRT2, -SQRT2], - [offset, 1.0], - [1.0, offset], - [1.0, 0.0], + [SQRT2+MAGIC45, -SQRT2+MAGIC45], + [1.0, -MAGIC], + [1.0, 0.0], - [1.0, -offset], - [offset, -1.0], - [0.0, -1.0], + [1.0, MAGIC], + [SQRT2+MAGIC45, SQRT2-MAGIC45], + [SQRT2, SQRT2], - [-offset, -1.0], - [-1.0, -offset], - [-1.0, 0.0], + [SQRT2-MAGIC45, SQRT2+MAGIC45], + [MAGIC, 1.0], + [0.0, 1.0], - [-1.0, 0.0]], + [-MAGIC, 1.0], + [-SQRT2+MAGIC45, SQRT2+MAGIC45], + [-SQRT2, SQRT2], + + [-SQRT2-MAGIC45, SQRT2-MAGIC45], + [-1.0, MAGIC], + [-1.0, 0.0], + + [-1.0, -MAGIC], + [-SQRT2-MAGIC45, -SQRT2+MAGIC45], + [-SQRT2, -SQRT2], + + [-SQRT2+MAGIC45, -SQRT2-MAGIC45], + [-MAGIC, -1.0], + [0.0, -1.0], + + [0.0, -1.0]], npy.float_) - codes = cls.CURVE4 * npy.ones(14) + codes = cls.CURVE4 * npy.ones(26) codes[0] = cls.MOVETO codes[-1] = cls.CLOSEPOLY This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-12-10 15:22:11
|
Revision: 4683 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4683&view=rev Author: mdboom Date: 2007-12-10 07:21:58 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Fix variable name. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-12-10 15:03:33 UTC (rev 4682) +++ branches/transforms/lib/matplotlib/path.py 2007-12-10 15:21:58 UTC (rev 4683) @@ -358,41 +358,41 @@ """ if cls._unit_circle is None: MAGIC = 0.2652031 - SQRT2 = npy.sqrt(0.5) + SQRTHALF = npy.sqrt(0.5) MAGIC45 = npy.sqrt((MAGIC*MAGIC) / 2.0) vertices = npy.array( [[0.0, -1.0], [MAGIC, -1.0], - [SQRT2-MAGIC45, -SQRT2-MAGIC45], - [SQRT2, -SQRT2], + [SQRTHALF-MAGIC45, -SQRTHALF-MAGIC45], + [SQRTHALF, -SQRTHALF], - [SQRT2+MAGIC45, -SQRT2+MAGIC45], + [SQRTHALF+MAGIC45, -SQRTHALF+MAGIC45], [1.0, -MAGIC], [1.0, 0.0], [1.0, MAGIC], - [SQRT2+MAGIC45, SQRT2-MAGIC45], - [SQRT2, SQRT2], + [SQRTHALF+MAGIC45, SQRTHALF-MAGIC45], + [SQRTHALF, SQRTHALF], - [SQRT2-MAGIC45, SQRT2+MAGIC45], + [SQRTHALF-MAGIC45, SQRTHALF+MAGIC45], [MAGIC, 1.0], [0.0, 1.0], [-MAGIC, 1.0], - [-SQRT2+MAGIC45, SQRT2+MAGIC45], - [-SQRT2, SQRT2], + [-SQRTHALF+MAGIC45, SQRTHALF+MAGIC45], + [-SQRTHALF, SQRTHALF], - [-SQRT2-MAGIC45, SQRT2-MAGIC45], + [-SQRTHALF-MAGIC45, SQRTHALF-MAGIC45], [-1.0, MAGIC], [-1.0, 0.0], [-1.0, -MAGIC], - [-SQRT2-MAGIC45, -SQRT2+MAGIC45], - [-SQRT2, -SQRT2], + [-SQRTHALF-MAGIC45, -SQRTHALF+MAGIC45], + [-SQRTHALF, -SQRTHALF], - [-SQRT2+MAGIC45, -SQRT2-MAGIC45], + [-SQRTHALF+MAGIC45, -SQRTHALF-MAGIC45], [-MAGIC, -1.0], [0.0, -1.0], This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-12-10 19:46:04
|
Revision: 4693 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4693&view=rev Author: mdboom Date: 2007-12-10 11:46:00 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Numpify arc/wedge approximation. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-12-10 16:27:25 UTC (rev 4692) +++ branches/transforms/lib/matplotlib/path.py 2007-12-10 19:46:00 UTC (rev 4693) @@ -408,10 +408,14 @@ unit_circle = classmethod(unit_circle) #@classmethod - def arc(cls, theta1, theta2, is_wedge=False): + def arc(cls, theta1, theta2, is_wedge=False, n=None): """ Returns an arc on the unit circle from angle theta1 to angle theta2 (in degrees). + + If n is provided, it is the number of spline segments to make. + If n is not provided, the number of spline segments is determined + based on the delta between theta1 and theta2. """ # From Masionobe, L. 2003. "Drawing an elliptical arc using # polylines, quadratic or cubic Bezier curves". @@ -422,7 +426,7 @@ theta1 *= math.pi / 180.0 theta2 *= math.pi / 180.0 - twopi = math.pi * 2.0 + twopi = math.pi * 2.0 halfpi = math.pi * 0.5 eta1 = math.atan2(math.sin(theta1), math.cos(theta1)) @@ -432,7 +436,8 @@ eta2 += twopi # number of curve segments to make - n = int(2 ** math.ceil((eta2 - eta1) / halfpi)) + if n is None: + n = int(2 ** math.ceil((eta2 - eta1) / halfpi)) deta = (eta2 - eta1) / n etaB = eta1 @@ -450,7 +455,9 @@ codes = Path.CURVE4 * npy.ones((length, ), Path.code_type) vertices[1] = [xB, yB] codes[0:2] = [Path.MOVETO, Path.LINETO] + codes[-2:] = [Path.LINETO, Path.CLOSEPOLY] vertex_offset = 2 + end = length - 2 else: length = n * 3 + 1 vertices = npy.zeros((length, 2), npy.float_) @@ -458,32 +465,31 @@ vertices[0] = [xB, yB] codes[0] = Path.MOVETO vertex_offset = 1 + end = length t = math.tan(0.5 * deta) alpha = math.sin(deta) * (math.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0 - for i in xrange(n): - xA = xB - yA = yB - xA_dot = xB_dot - yA_dot = yB_dot + steps = npy.linspace(eta1, eta2, n + 1, True) + cos_eta = npy.cos(steps) + sin_eta = npy.sin(steps) - etaB += deta - cos_etaB = math.cos(etaB) - sin_etaB = math.sin(etaB) - xB = cos_etaB - yB = sin_etaB - xB_dot = -sin_etaB - yB_dot = cos_etaB + xA = cos_eta[:-1] + yA = sin_eta[:-1] + xA_dot = -yA + yA_dot = xA - offset = i*3 + vertex_offset - vertices[offset:offset+3] = [ - [xA + alpha * xA_dot, yA + alpha * yA_dot], - [xB - alpha * xB_dot, yB - alpha * yB_dot], - [xB, yB]] + xB = cos_eta[1:] + yB = sin_eta[1:] + xB_dot = -yB + yB_dot = xB - if is_wedge: - codes[-2:] = [Path.LINETO, Path.CLOSEPOLY] + vertices[vertex_offset :end:3, 0] = xA + alpha * xA_dot + vertices[vertex_offset :end:3, 1] = yA + alpha * yA_dot + vertices[vertex_offset+1:end:3, 0] = xB - alpha * xB_dot + vertices[vertex_offset+1:end:3, 1] = yB - alpha * yB_dot + vertices[vertex_offset+2:end:3, 0] = xB + vertices[vertex_offset+2:end:3, 1] = yB return Path(vertices, codes) arc = classmethod(arc) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-12-10 19:53:14
|
Revision: 4694 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4694&view=rev Author: mdboom Date: 2007-12-10 11:53:12 -0800 (Mon, 10 Dec 2007) Log Message: ----------- Simplify even more Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-12-10 19:46:00 UTC (rev 4693) +++ branches/transforms/lib/matplotlib/path.py 2007-12-10 19:53:12 UTC (rev 4694) @@ -440,20 +440,28 @@ n = int(2 ** math.ceil((eta2 - eta1) / halfpi)) deta = (eta2 - eta1) / n - etaB = eta1 + t = math.tan(0.5 * deta) + alpha = math.sin(deta) * (math.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0 - cos_etaB = math.cos(etaB) - sin_etaB = math.sin(etaB) - xB = cos_etaB - yB = sin_etaB - xB_dot = -sin_etaB - yB_dot = cos_etaB + steps = npy.linspace(eta1, eta2, n + 1, True) + cos_eta = npy.cos(steps) + sin_eta = npy.sin(steps) + xA = cos_eta[:-1] + yA = sin_eta[:-1] + xA_dot = -yA + yA_dot = xA + + xB = cos_eta[1:] + yB = sin_eta[1:] + xB_dot = -yB + yB_dot = xB + if is_wedge: length = n * 3 + 4 vertices = npy.zeros((length, 2), npy.float_) codes = Path.CURVE4 * npy.ones((length, ), Path.code_type) - vertices[1] = [xB, yB] + vertices[1] = [xA[0], yA[0]] codes[0:2] = [Path.MOVETO, Path.LINETO] codes[-2:] = [Path.LINETO, Path.CLOSEPOLY] vertex_offset = 2 @@ -462,28 +470,11 @@ length = n * 3 + 1 vertices = npy.zeros((length, 2), npy.float_) codes = Path.CURVE4 * npy.ones((length, ), Path.code_type) - vertices[0] = [xB, yB] + vertices[0] = [xA[0], yA[0]] codes[0] = Path.MOVETO vertex_offset = 1 end = length - t = math.tan(0.5 * deta) - alpha = math.sin(deta) * (math.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0 - - steps = npy.linspace(eta1, eta2, n + 1, True) - cos_eta = npy.cos(steps) - sin_eta = npy.sin(steps) - - xA = cos_eta[:-1] - yA = sin_eta[:-1] - xA_dot = -yA - yA_dot = xA - - xB = cos_eta[1:] - yB = sin_eta[1:] - xB_dot = -yB - yB_dot = xB - vertices[vertex_offset :end:3, 0] = xA + alpha * xA_dot vertices[vertex_offset :end:3, 1] = yA + alpha * yA_dot vertices[vertex_offset+1:end:3, 0] = xB - alpha * xB_dot This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <md...@us...> - 2007-12-13 18:13:01
|
Revision: 4723 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=4723&view=rev Author: mdboom Date: 2007-12-13 10:12:51 -0800 (Thu, 13 Dec 2007) Log Message: ----------- Use numpy for math. Modified Paths: -------------- branches/transforms/lib/matplotlib/path.py Modified: branches/transforms/lib/matplotlib/path.py =================================================================== --- branches/transforms/lib/matplotlib/path.py 2007-12-13 18:12:11 UTC (rev 4722) +++ branches/transforms/lib/matplotlib/path.py 2007-12-13 18:12:51 UTC (rev 4723) @@ -423,25 +423,25 @@ # http://www.spaceroots.org/documents/ellipse/index.html # degrees to radians - theta1 *= math.pi / 180.0 - theta2 *= math.pi / 180.0 + theta1 *= npy.pi / 180.0 + theta2 *= npy.pi / 180.0 - twopi = math.pi * 2.0 - halfpi = math.pi * 0.5 + twopi = npy.pi * 2.0 + halfpi = npy.pi * 0.5 - eta1 = math.atan2(math.sin(theta1), math.cos(theta1)) - eta2 = math.atan2(math.sin(theta2), math.cos(theta2)) - eta2 -= twopi * math.floor((eta2 - eta1) / twopi) - if (theta2 - theta1 > math.pi) and (eta2 - eta1 < math.pi): + eta1 = npy.arctan2(npy.sin(theta1), npy.cos(theta1)) + eta2 = npy.arctan2(npy.sin(theta2), npy.cos(theta2)) + eta2 -= twopi * npy.floor((eta2 - eta1) / twopi) + if (theta2 - theta1 > npy.pi) and (eta2 - eta1 < npy.pi): eta2 += twopi # number of curve segments to make if n is None: - n = int(2 ** math.ceil((eta2 - eta1) / halfpi)) + n = int(2 ** npy.ceil((eta2 - eta1) / halfpi)) deta = (eta2 - eta1) / n - t = math.tan(0.5 * deta) - alpha = math.sin(deta) * (math.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0 + t = npy.tan(0.5 * deta) + alpha = npy.sin(deta) * (npy.sqrt(4.0 + 3.0 * t * t) - 1) / 3.0 steps = npy.linspace(eta1, eta2, n + 1, True) cos_eta = npy.cos(steps) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |