Help wanted for scripting an "epicycloid" for sketcher

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Help wanted for scripting an "epicycloid" for sketcher

Post by manuelkrause »

Hi people,
can someone point me to the ways how to create a scripted sketch for an epicyloid?
The result should be either point based or even better usable for later FC part design. Spline?
I've currently hand-made the first steps, by constrained geometry, but they're getting slower over each new constraint.

EDIT: on my slow CPU ~3min. at a next angular constraint.

Many thanks in advance!
BR,
Manuel
Attachments
Screenshot_20190105_173502.png
Screenshot_20190105_173502.png (159.78 KiB) Viewed 2005 times
hjh
Posts: 17
Joined: Tue Jan 01, 2019 12:47 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by hjh »

Added a little bit to the requirements.

The question seems to be how to create your own 2d-shape object type given by equations (indicated red below in the screen shot)

https://en.wikipedia.org/wiki/Epicycloid
Epicycloid_Wikipedia_Screenshot_2019-01-05.png
Epicycloid_Wikipedia_Screenshot_2019-01-05.png (83.8 KiB) Viewed 1991 times
The red curve is given by the formula.
epicycloid_formula_wp.png
epicycloid_formula_wp.png (5.45 KiB) Viewed 1987 times
--HJH
Last edited by hjh on Sat Jan 05, 2019 5:43 pm, edited 1 time in total.
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by manuelkrause »

hjh wrote: Sat Jan 05, 2019 5:35 pm Added a little bit to the requirements.

The question seems to be how to create your own 2d-shape object type given by equations (indicated red below in the screen shot)

https://en.wikipedia.org/wiki/Epicycloid

Epicycloid_Wikipedia_Screenshot_2019-01-05.png

--HJH
Many thanks,
but my main question is, how to guide it (the Epicyloid formula) into a python usable formula, to gather coordinates for points etc. I've read the wikipedia etc.

Manuel
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by manuelkrause »

hjh wrote: Sat Jan 05, 2019 5:35 pm Added a little bit to the requirements.

The question seems to be how to create your own 2d-shape object type given by equations (indicated red below in the screen shot)

https://en.wikipedia.org/wiki/Epicycloid

Epicycloid_Wikipedia_Screenshot_2019-01-05.png

The red curve is given by the formula.
epicycloid_formula_wp.png

--HJH
Don't understand me wrong. I just want to get the curves into usable sketch points.
hjh
Posts: 17
Joined: Tue Jan 01, 2019 12:47 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by hjh »

It seems that the issue is to follow the Octahedron example

https://www.freecadweb.org/wiki/Scripted_objects

and create a class Epicycloid.
What makes it more complex is that the new shape is given by a formula and not by discrete points.
Maybe there is an example in the documentation somewhere how to describe an object shape with a formula, not discrete points.
BTW could you please indicate how you produced what is seen on your screen shot?

--HJH
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by manuelkrause »

hjh wrote: Sat Jan 05, 2019 5:54 pm It seems that the issue is to follow the Octahedron example

https://www.freecadweb.org/wiki/Scripted_objects

and create a class Epicycloid.
What makes it more complex is that the new shape is given by a formula and not by discrete points.
Maybe there is an example in the documentation somewhere how to describe an object shape with a formula, not discrete points.
BTW could you please indicate how you produced what is seen on your screen shot?

--HJH
Do you understand a little German? Doesn't matter if not. Main actual math of it I re-derived from wikipedia. The base data info was from http://rx7ch.com/files/wankelmotor_matura_arbeit.pdf (german). Page 16 and following.
For the work for the screenshot I stupidly made all the geometric settings in the sketch. One degree on main circle, two degrees on rolling circle, including some distance always rotated with the rolling circle, leading to the needed resulting curve point.

BR,
Manuel
User avatar
manuelkrause
Posts: 442
Joined: Thu Jul 05, 2018 7:16 pm

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by manuelkrause »

Thank you very much for this collection !
I need to have a closer look at them during next days.

Best regards,
Manuel
User avatar
JoshM
Posts: 456
Joined: Thu Oct 05, 2017 5:34 pm
Location: New Hampshire

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by JoshM »

Oh--that's cool. I tried it out and this should get you going. I tried it with R = 3, 5, and 15, and from wiki link, it looks correct.
Epicycloid_Macro.png
Epicycloid_Macro.png (144.11 KiB) Viewed 1909 times
Epicycloid_Macro2.png
Epicycloid_Macro2.png (165.17 KiB) Viewed 1905 times
Epicycloid_Macro3.png
Epicycloid_Macro3.png (167.67 KiB) Viewed 1905 times

Code: Select all

import FreeCAD
from FreeCAD import Gui
from FreeCAD import Base
from FreeCAD import Vector
import Part
import math
import Sketcher
import os
import Draft

R = 3.0		# Big Radius
r = 1.0		# Little Radius
k = R/r		# Altenate form constant
K = (k + 1)

Num_Theta_Points = 1000
Theta_Step = ((2* math.pi / Num_Theta_Points))

Epicycloid_Points = []	
for t in range(0, (Num_Theta_Points - 1), 1): 
	Theta = (t * Theta_Step)
	
	x = (r * K * math.cos(Theta)) - (r *  math.cos(K * Theta))
	y = (r * K * math.sin(Theta)) - (r *  math.sin(K * Theta))
	epicycloid_point = Base.Vector(x, y, 0.0)
	Epicycloid_Points.append(epicycloid_point)
	
Draft.makeBSpline(Epicycloid_Points)

I placed this in the XY plane, but you should be able to manipulate to your own needs from here I suspect. You can convert to a Sketch in DraftWB, but I don't think that will help you much--this has 3003 degrees of freedom in the Sketcher;)

I looked a bit further, and this isn't correct yet for fractional k values.

Cheers,
Josh
Attachments
Epicycloid.FCMacro
(722 Bytes) Downloaded 61 times
DjangoFreeCAD
Posts: 24
Joined: Mon Dec 31, 2018 6:43 pm
Location: France

Re: Help wanted for scripting an "epicycloid" for sketcher

Post by DjangoFreeCAD »

Here is a Script which draw the Epicycloid in the Sketch

Create a new document and sketch and then launch the macro

You will see how the drawing is made by the movement of a line and a circle
FreeCAD2 Macro.jpg
FreeCAD2 Macro.jpg (32.48 KiB) Viewed 1859 times
FreeCAD Macro.jpg
FreeCAD Macro.jpg (52.15 KiB) Viewed 1859 times
FreeCAD3 Macro.jpg
FreeCAD3 Macro.jpg (45.56 KiB) Viewed 1859 times
Attachments
Epicycloide2.FCMacro
(2.14 KiB) Downloaded 94 times
Post Reply