+ add Epitrochoid example
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5154 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
d6f12c823c
commit
e119c9572f
|
@ -82,6 +82,7 @@ SET(PartDesign_Scripts
|
|||
Scripts/__init__.py
|
||||
Scripts/Gear.py
|
||||
Scripts/DistanceBolt.py
|
||||
Scripts/Epitrochoid.py
|
||||
Scripts/RadialCopy.py
|
||||
Scripts/Parallelepiped.py
|
||||
Scripts/Spring.py
|
||||
|
|
65
src/Mod/PartDesign/Scripts/Epitrochoid.py
Normal file
65
src/Mod/PartDesign/Scripts/Epitrochoid.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
|
||||
from __future__ import division # allows floating point division from integers
|
||||
import FreeCAD, Part, math
|
||||
from FreeCAD import Base
|
||||
|
||||
class Epitrochoid:
|
||||
def __init__(self, obj):
|
||||
''' Add the properties: Radius1, Radius2, Distance, Segments '''
|
||||
obj.addProperty("App::PropertyLength","Radius1","Epitrochoid","Interior radius").Radius1=60.0
|
||||
obj.addProperty("App::PropertyLength","Radius2","Epitrochoid","Exterior radius").Radius2=20.0
|
||||
obj.addProperty("App::PropertyLength","Distance","Epitrochoid","Distance").Distance=10.0
|
||||
obj.addProperty("App::PropertyInteger","Segments","Epitrochoid","Number of the line segments").Segments=72
|
||||
obj.Proxy = self
|
||||
|
||||
def onChanged(self, fp, prop):
|
||||
if prop == "Radius1" or prop == "Radius2" or prop == "Distance" or prop == "Segments": #if one of these is changed
|
||||
self.execute(fp)
|
||||
|
||||
def execute(self, fp): #main part of script
|
||||
steps=fp.Segments #get value from property
|
||||
dang=math.radians(360/steps)
|
||||
r2=fp.Radius2
|
||||
r1=fp.Radius1
|
||||
f1 = r1 + r2
|
||||
f2 = f1 / r2
|
||||
d=fp.Distance
|
||||
ang=0
|
||||
z=0
|
||||
|
||||
if r2 == 0:
|
||||
raise Exception("Exterior radius must not be zero")
|
||||
|
||||
for i in range(steps):
|
||||
if i==0:
|
||||
x1=f1*math.cos(ang)-d*math.cos(f2*ang) #coords for line startpoint
|
||||
y1=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
ang=dang
|
||||
x2=f1*math.cos(ang)-d*math.cos(f2*ang) #coords for line endpoint
|
||||
y2=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
seg=Part.makeLine((x1,y1,z),(x2,y2,z))
|
||||
wire=Part.Wire([seg])
|
||||
x1=x2
|
||||
y1=y2
|
||||
else:
|
||||
x2=f1*math.cos(ang)-d*math.cos(f2*ang)
|
||||
y2=f1*math.sin(ang)-d*math.sin(f2*ang)
|
||||
seg=Part.makeLine((x1,y1,z),(x2,y2,z))
|
||||
wire=Part.Wire([wire,seg])
|
||||
x1=x2
|
||||
y1=y2
|
||||
ang=ang+dang #increment angle
|
||||
fp.Shape = wire #result shape
|
||||
|
||||
def makeEpitrochoid():
|
||||
doc = FreeCAD.activeDocument()
|
||||
if doc == None:
|
||||
doc = FreeCAD.newDocument()
|
||||
epitrochoid=doc.addObject("Part::FeaturePython","Epitrochoid") #add object to document
|
||||
epitrochoid.Label = "Epitrochoid"
|
||||
Epitrochoid(epitrochoid)
|
||||
epitrochoid.ViewObject.Proxy=0
|
||||
doc.recompute()
|
||||
|
||||
if __name__ == "__main__": #feature will be generated after macro execution
|
||||
makeEpitrochoid()
|
|
@ -4,6 +4,7 @@ data_DATA = \
|
|||
__init__.py \
|
||||
Gear.py \
|
||||
DistanceBolt.py \
|
||||
Epitrochoid.py \
|
||||
RadialCopy.py \
|
||||
Parallelepiped.py \
|
||||
Spring.py
|
||||
|
|
Loading…
Reference in New Issue
Block a user