123 lines
5.4 KiB
HTML
123 lines
5.4 KiB
HTML
<html><head><title>Macro Draw Parametric 2D Function/de</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro Draw Parametric 2D Function/de</h1></div>
|
|
|
|
<div id="mw-content-text" lang="de" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
|
|
<tr>
|
|
<td class="ctTitle">
|
|
<h3><span class="mw-headline" id="Macro_Draw_Parametric_2D_Function"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Text-x-python.png" class="image"><img alt="Text-x-python.png" src="32px-Text-x-python.png" width="32" height="32" srcset="/wiki/images/2/2c/Text-x-python.png 1.5x" /></a> Macro Draw Parametric 2D Function</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Beschreibung
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">Draws 2-dimensional, parametric and optionally polar equations.
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Autor
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:T4b&action=edit&redlink=1" class="new" title="User:T4b (page does not exist)">T4b</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Link
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/de" title="Macros recipes/de">Liste von Macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/de" title="How to install macros/de">How to install macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/de" title="Customize Toolbars/de">How to customize toolbars</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Version
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-version">1.0
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Datum zuletzt geändert
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2012-08-30
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
|
|
<ul>
|
|
<li class="toclevel-1"><a href="#Macro_Draw_Parametric_2D_Function"><span class="tocnumber">1</span> <span class="toctext">Macro Draw Parametric 2D Function</span></a></li>
|
|
<li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li>
|
|
<li class="toclevel-1 tocsection-2"><a href="#Limitations"><span class="tocnumber">3</span> <span class="toctext">Limitations</span></a></li>
|
|
<li class="toclevel-1 tocsection-3"><a href="#Use"><span class="tocnumber">4</span> <span class="toctext">Use</span></a></li>
|
|
<li class="toclevel-1 tocsection-4"><a href="#Script"><span class="tocnumber">5</span> <span class="toctext">Script</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
</td></tr>
|
|
</table><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_drawParametric2Dfunction.png" class="image" title="DrawParametric2DFunction"><img alt="DrawParametric2DFunction" src="480px-Macro_drawParametric2Dfunction.png" width="480" height="360" srcset="/wiki/images/5/50/Macro_drawParametric2Dfunction.png 1.5x" /></a>
|
|
<h2><span class="mw-headline" id="Description">Description</span></h2>
|
|
<p>Draws 2-dimensional, parametric and optionally polar equations.
|
|
</p>
|
|
<h2><span class="mw-headline" id="Limitations">Limitations</span></h2>
|
|
<p>Still has some bugs and misses some features. Documentation is in the docstrings.
|
|
</p>
|
|
<h2><span class="mw-headline" id="Use">Use</span></h2>
|
|
<p>Type :
|
|
</p>
|
|
<pre>#Example usage:
|
|
draw2Dfunction(xFunction="0.5*n", yFunction="-0.75*n", n=0, nd=-math.pi, step=50, pol=1) </pre>
|
|
<h2><span class="mw-headline" id="Script">Script</span></h2>
|
|
<p><b>Macro_drawParametric2DFunction.FCMacro</b>
|
|
</p>
|
|
<pre>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) </pre>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div><div class="printfooter">
|
|
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Draw_Parametric_2D_Function/de&oldid=240593">http://www.freecadweb.org/wiki/index.php?title=Macro_Draw_Parametric_2D_Function/de&oldid=240593</a>"</div>
|
|
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
<div id="mw-navigation">
|
|
<h2>Navigation menu</h2>
|
|
|
|
</body></html> |