Macro Draw 2D Function: Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(Vertical {{Macro}}; fixed icon)
Line 2: Line 2:
<translate>
<translate>
<!--T:1-->
<!--T:1-->
{{Macro
{{Macro|Icon=Text-x-python|Name=Draw 2D Function|Description=Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane)|Author=unknown|Version=1.0|Date=2011-08-01}}
|Name=Draw 2D Function
|Description=Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane)
|Author=unknown
|Version=1.0
|Date=2011-08-01
}}


==Description== <!--T:2-->
==Description== <!--T:2-->
Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane) The example done here generate a parabol.<br />
Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane) The example done here generate a parabol.
Has no dialog. Needs to be defined :<br />
Has no dialog. Needs to be defined:
F = variable used in the function,<br />
:F = variable used in the function,
X = initial value of x,<br />
:X = initial value of x,
Nb = Number of step,<br />
:Nb = Number of step,
Z = function express with x <br />
:Z = function express with x
ZZ = function express with xx<br />
:ZZ = function express with xx


==Script== <!--T:3-->
==Script== <!--T:3-->

Revision as of 21:24, 3 December 2018

Generic macro icon. Create your personal icon with the same name of the macro Draw 2D Function

Description
Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane)

Macro version: 1.0
Last modified: 2011-08-01
Author: unknown
Author
unknown
Download
None
Links
Macro Version
1.0
Date last modified
2011-08-01
FreeCAD Version(s)
None
Default shortcut
None
See also
None

Description

Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane) The example done here generate a parabol. Has no dialog. Needs to be defined:

F = variable used in the function,
X = initial value of x,
Nb = Number of step,
Z = function express with x
ZZ = function express with xx

Script

Macro_Draw_2D_Function.FCMacro

# F = variable used in the function,
# X = initial value of x,
# Nb = Number of step,
# Z = function express with x
# ZZ = function express with xx

import FreeCAD, FreeCADGui, Part
import math
F=800
X=-500
Nb=10
Step=1000/Nb
Y=0
for I in range(Nb):
	XX=X+Step 
 	Z=X*X/(4*F)
 	ZZ=XX*XX/(4*F)
 	if I==0:
 		print "Le test est vrai !"
 		nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
 		WWire=Part.Wire([nomme])
 	else :
 		print "Le test est 2 !"
 		nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))		
 		WWire=Part.Wire([WWire,nomme])
 	X=XX 
 
Part.show(WWire)