From 35ff437164212441209e18d2f56903e591f2ef61 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 22 Jun 2007 11:11:19 +0000 Subject: Added polar coordinates. Added "Use" tab to dialog. (bzr r3085) --- share/extensions/funcplot.py | 91 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 21 deletions(-) (limited to 'share/extensions/funcplot.py') diff --git a/share/extensions/funcplot.py b/share/extensions/funcplot.py index e478a4b30..482df634a 100644 --- a/share/extensions/funcplot.py +++ b/share/extensions/funcplot.py @@ -1,5 +1,6 @@ #!/usr/bin/env python ''' +Copyright (C) 2007 Tavmjong Bah, tavmjong@free.fr Copyright (C) 2006 Georg Wiora, xorx@quarkbox.de Copyright (C) 2006 Johan Engelen, johan@shouraizou.nl Copyright (C) 2005 Aaron Spike, aaron@ekips.org @@ -21,6 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Changes: * This program is a modified version of wavy.py by Aaron Spike. * 22-Dec-2006: Wiora : Added axis and isotropic scaling + * 21-Jun-2007: Tavmjong: Added polar coordinates ''' import inkex, simplepath, simplestyle @@ -28,8 +30,8 @@ from math import * from random import * def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bottom, - fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, isoscale = True, drawaxis = True): - + fx = "sin(x)", fpx = "cos(x)", fponum = True, times2pi = False, polar = False, isoscale = True, drawaxis = True): + if times2pi == True: xstart = 2 * pi * xstart xend = 2 * pi * xend @@ -38,12 +40,18 @@ def drawfunction(xstart, xend, ybottom, ytop, samples, width, height, left, bott scalex = width / (xend - xstart) xoff = left coordx = lambda x: (x - xstart) * scalex + xoff #convert x-value to coordinate + if polar : # Set scale so that left side of rectangle is -1, right side is +1. + # (We can't use xscale for both range and scale.) + centerx = left + width/2.0 + polar_scalex = width/2.0 + coordx = lambda x: x * polar_scalex + centerx #convert x-value to coordinate + scaley = height / (ytop - ybottom) yoff = bottom coordy = lambda y: (ybottom - y) * scaley + yoff #convert y-value to coordinate - + # Check for isotropic scaling and use smaller of the two scales, correct ranges - if isoscale: + if isoscale and not polar: if scaley