Difference between revisions of "Macro Draw 2D Function"

From FreeCAD Documentation
Jump to navigation Jump to search
(languages it)
(Use {{MacroCode}})
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Macro|Name=draw2DFunction|Description=Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane)}}
+
<languages/>
 +
<translate>
 +
<!--T:1-->
 +
{{Macro
 +
|Name=Draw 2D Function
 +
|Icon=Macro_Draw_2D_Function.png
 +
|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
 +
|FCVersion=All
 +
|Download=[https://www.freecadweb.org/wiki/images/3/36/Macro_Draw_2D_Function.png ToolBar Icon]
 +
}}
  
Use it to draw a function described by a "equation" [z=F(x)] (Z-X plane) The example done here generate a parabol.  
+
==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.
 +
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
  
Needs to be defined :
+
==Script== <!--T:3-->
 +
</translate>
  
F=variable used in the function,
+
ToolBar Icon [[Image:Macro_Draw_2D_Function.png]]
 
X=initial value of x,
 
  
Nb= Number of step,
+
'''Macro_Draw_2D_Function.FCMacro'''
 
Z=function express with x
 
  
ZZ=function express with xx
+
{{MacroCode|code=
  
 +
# 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 FreeCAD, FreeCADGui, Part
import math
+
import math
F=800
+
F=800
X=-500
+
X=-500
Nb=10
+
Nb=10
Step=1000/Nb
+
Step=1000/Nb
Y=0
+
Y=0
for I in range(Nb):
+
for I in range(Nb):
XX=X+Step  
+
XX=X+Step  
 
  Z=X*X/(4*F)
 
  Z=X*X/(4*F)
 
  ZZ=XX*XX/(4*F)
 
  ZZ=XX*XX/(4*F)
 
  if I==0:
 
  if I==0:
  print "Le test est vrai !"
+
  print( "Le test est vrai !")
 
  nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
 
  nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
 
  WWire=Part.Wire([nomme])
 
  WWire=Part.Wire([nomme])
 
  else :
 
  else :
  print "Le test est 2 !"
+
  print( "Le test est 2 !")
 
  nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
 
  nomme=Part.makeLine((X,Y,Z),(XX,Y,ZZ))
 
  WWire=Part.Wire([WWire,nomme])
 
  WWire=Part.Wire([WWire,nomme])
 
  X=XX  
 
  X=XX  
 
   
 
   
Part.show(WWire)
+
Part.show(WWire)
  
{{languages | {{es|Macro_draw2DFunction/es}} {{fr|Macro_draw2DFunction/fr}} {{it|Macro_draw2DFunction/it}} }}
+
}}

Latest revision as of 00:32, 8 May 2020

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎italiano • ‎polski • ‎svenska • ‎čeština

Macro Draw 2D Function.png 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
FreeCAD version: All
Download: ToolBar Icon
Author: unknown
Author
unknown
Download
ToolBar Icon
Links
Macro Version
1.0
Date last modified
2011-08-01
FreeCAD Version(s)
All
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

ToolBar Icon Macro Draw 2D Function.png

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)