<html><head><title>Macro Draw Parametric 2D Function/cs</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/cs</h1></div> <div id="mw-content-text" lang="cs" 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="Vykresli_2D_funkci_parametrick.C3.A1"><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> Vykresli 2D funkci parametrická</span></h3> </td></tr> <tr> <th class="ctOdd">Description </th></tr> <tr> <td class="ctEven left macro-description">Vykreslí 2-dimenzionální, parametrickou a volitelně polární rovnici. </td></tr> <tr> <th class="ctOdd">Author </th></tr> <tr> <td class="ctEven macro-author"><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">Links </th></tr> <tr> <td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/cs" title="Macros recipes/cs">Makro návody</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/cs" title="How to install macros/cs">How to install macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/cs" title="Customize Toolbars/cs">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">Date last modification </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="#Vykresli_2D_funkci_parametrick.C3.A1"><span class="tocnumber">1</span> <span class="toctext">Vykresli 2D funkci parametrická</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>Zatím má nějaké chyby a chybí některé vlastnosti. Dokumentace je v komenářích zdrojoového kódu. </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/cs&oldid=240591">http://www.freecadweb.org/wiki/index.php?title=Macro_Draw_Parametric_2D_Function/cs&oldid=240591</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>