Macro Draw Parametric 2D Function/fr: Difference between revisions

From FreeCAD Documentation
m (FuzzyBot moved page Macro drawParametric2Dfunction/fr to Macro Draw Parametric 2D Function/fr without leaving a redirect: Part of translatable page "Macro drawParametric2Dfunction".)
(Updating to match new version of source page)
Line 1: Line 1:
{{Macro/fr|Icon=Text-x-python|Name/fr=Macro DrawParametric2DFunction|Description=Dessin 2-dimensions, et éventuellement paramétrique avec une équation polaire .|Author=T4b}}
{{Macro|Icon=Text-x-python|Name=Macro Draw Parametric 2D Function|Description=Draws 2-dimensional, parametric and optionally polar equations.|Author=T4b}}


[[Image:Macro_drawParametric2Dfunction.png|480px|DrawParametric2DFunction]]
[[Image:Macro_drawParametric2Dfunction.png|480px|DrawParametric2DFunction]]


Possède encore quelques bugs et il manque certaines fonctionnalités. La documentation est dans le docstrings.
==Description==
Draws 2-dimensional, parametric and optionally polar equations.


==Limitations==
==Limitations==

Revision as of 20:30, 26 June 2016

File:Text-x-python Macro Draw Parametric 2D Function

Description
Draws 2-dimensional, parametric and optionally polar equations.

Author: T4b
Author
T4b
Download
None
Links
Macro Version
1.0
Date last modified
None
FreeCAD Version(s)
None
Default shortcut
None
See also
None

DrawParametric2DFunction

Possède encore quelques bugs et il manque certaines fonctionnalités. La documentation est dans le docstrings.

Limitations

Still has some bugs and misses some features. Documentation is in the docstrings.

Use

Type :

#Example usage:
draw2Dfunction(xFunction="0.5*n", yFunction="-0.75*n", n=0, nd=-math.pi, step=50, pol=1)

Script

Macro_drawParametric2DFunction.FCMacro

import FreeCAD, FreeCADGui, Part
import math

def evalFunction(suppliedFunction, n):
	"""This function uses eval to evaluate suppliedFunction.
	
	It does in no way check whether suppliedFunction is evil, thus it is itself evil!
	"""
	return eval(suppliedFunction)

def draw2Dfunction(xFunction="n", yFunction="n", n=-5, nd=10, step=10, z=0, pol=0):
	"""Draws 2-dimensional mathemathical functions
	
	The function is drawn for n's between n and n+nd, in steps of 1/step, on the z-coordinate z.
	Equations for x and y can be given (xFunction and yFunction arguments), they default to n.
	
	If pol=1 then x is interpreted as r and y is interpreted as t.
	"""
	nStart=n
	while math.fabs(n-nd)-1.0/step>0:
		print "n: " + str(n)
		x=evalFunction(xFunction, n)
		y=evalFunction(yFunction, n)
		nNext=n+math.copysign(1,nd-n)/step 
		print "nNext: " + str(nNext)
		xNext=evalFunction(xFunction, nNext)
		yNext=evalFunction(yFunction, nNext)
		if pol==0:
			nextSeg=(x,y,z),(xNext,yNext,z)
		else:
			nextSeg=(x*math.cos(y),x*math.sin(y),z),(xNext*math.cos(yNext),xNext*math.sin(yNext),z)
		print "nextSeg: " + str(nextSeg)
		nomme=Part.makeLine(*nextSeg)
		if n==nStart:
			WWire=Part.Wire([nomme])
		else:
			WWire=Part.Wire([WWire,nomme])
		n=nNext
	Part.show(WWire)
#Example usage:
draw2Dfunction(xFunction="0.5*n", yFunction="-0.75*n", n=0, nd=-math.pi, step=50, pol=1)
Other languages: