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

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

Post by manuelkrause »

JoshM wrote: Thu Jan 10, 2019 4:43 pm Yes, fillet on fillet doesn't work. Similarly, in 3d shapes, draft cannot be done on a filleted shape. And, in Sketcher, there are some other limits. I think ChrisB's tutorial on Sketcher may clear up some of that for you.

Not sure now what you need to do with implementing arc, but it should be possible. My personal take is that Sketcher is wonderful for sketching, but it can be a challenge when scripting--generally because the constraint engine settles on the nearest answer that fulfills your constraint, not necessarily the one you want. For example, a small circle, constrained to be tangent to a larger circle could settle either on the inside or the outside of the larger circle. If you're counting on the constraint engine to move things into shape for you, it may or may not. If for example, you know the shape you want, but the whole size can scale up or down, then you can draw a working template, and then use constraint to resize and that will work reliably because you've implicitly fed more information to the constraint engine by aligning elements of your sketch as you want.
Thank you very much for your descriptive explanations! I've already seen some things you wrote about.

The reason of my wish to implement arcs, was only, to get all curve segments tangent and connected.
To make a final 3D shape of it, without complaints at that stage.
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 »

I'm not sure if this helps any or not, but have you looked at scripting a BSpline through your points in Sketcher?

The reason I say I'm unsure if there's merit in this is that I am not sure the reason the Spine curve was incorrect in the macro I posted on here, and this too is a Spine approach.

You had mentioned in that case that there was deviation between the output curves and what you needed, and I didn't have an answer why. I assumed because the points were calculated from the formulas you linked, and because the gross shapes appeared consistent, that this would be what you needed. One thing I've wondered is if the issue is approximation versus interpolation, but then i would assume that if you raised the number of theta point calculations, the opportunity for deviation would decrease, and that's not what I understood you to be seeing.

Any chance you can show where the issue was in that approach?
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 »

JoshM wrote: Thu Jan 10, 2019 8:32 pm I'm not sure if this helps any or not, but have you looked at scripting a BSpline through your points in Sketcher?

The reason I say I'm unsure if there's merit in this is that I am not sure the reason the Spine curve was incorrect in the macro I posted on here, and this too is a Spine approach.

You had mentioned in that case that there was deviation between the output curves and what you needed, and I didn't have an answer why. I assumed because the points were calculated from the formulas you linked, and because the gross shapes appeared consistent, that this would be what you needed. One thing I've wondered is if the issue is approximation versus interpolation, but then i would assume that if you raised the number of theta point calculations, the opportunity for deviation would decrease, and that's not what I understood you to be seeing.

Any chance you can show where the issue was in that approach?
Hi Josh,
again, thank you for your input! Looks like I need to invest more time on this... and/or hope for your patience, until I completely investigated most of this, til a usable result. Refining it can happen later.
First point, regarding your BSpline script in Draft: I think, it's correct, and I only was in error using the wrong (understanding of) the rolling extension. (Maybe also be a wrong use of my little data base, thus getting in confusion about the rolling extension and the excentricity of the rotating piston.) Only thing I wasn't glad about, was the rough segmentation of the resulting draft spline.
But the spline approach seems to be the only way to make the curve usable for PartDesign. Yesterday, really by coincidence, I noticed the Sketcher's ability to create "periodic B-splines". ATM I'm trying to get this curve by manually picking the points of @DjangoFreeCAD's last posted script.
What - doing this Sketcher WB menu command - shows on Console view, is quite promising: In fact it replicates exactly what I wanted (here shown for one added segment):

Code: Select all

>>> App.ActiveDocument.Sketch.addGeometry(Part.Circle(App.Vector(132.482742,-82.362534,0),App.Vector(0,0,1),10),True)
>>> App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Equal',360,401)) 
>>> App.ActiveDocument.Sketch.addConstraint(Sketcher.Constraint('Coincident',401,3,318,2)) 
>>> 
So far, I haven't found the description on how to automate the Sketcher's "periodic B-spline". I'm still trying to get a manual version to later compare it to your Draft curve and my first geometrically made one.

BTW, I've made a weird observation while creating the B-spline: When picking the points of @DjangoFreeCAD's line-based curve, step-by-step, several but not all of the original segment lines do loose their previous end-point's placement. I really hope, I don't need to worry about.

BR, 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 »

Hi Manuel,
Sorry--I'm still learning as I go. I think this will give you a better approximation of what you want. The only real change is that I am making a polygon that goes through all the points generated. Here, increasing the number of calculated points increases the resolution and better approximates the curves you are interested in.

Code: Select all


from FreeCAD import Base
from FreeCAD import Vector
import math
import Draft

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

Num_Theta_Points = 20000
Theta_Step = ((2* math.pi / Num_Theta_Points))
Theta = 0.00000
Epicycloid_Points = []	
for t in range(0, (Num_Theta_Points - 1), 1): 
	Theta += 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)


Part.show(Part.makePolygon(Epicycloid_Points))



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 »

JoshM wrote: Fri Jan 11, 2019 5:17 pm Hi Manuel,
Sorry--I'm still learning as I go. I think this will give you a better approximation of what you want. The only real change is that I am making a polygon that goes through all the points generated. Here, increasing the number of calculated points increases the resolution and better approximates the curves you are interested in.

Code: Select all


from FreeCAD import Base
from FreeCAD import Vector
import math
import Draft

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

Num_Theta_Points = 20000
Theta_Step = ((2* math.pi / Num_Theta_Points))
Theta = 0.00000
Epicycloid_Points = []	
for t in range(0, (Num_Theta_Points - 1), 1): 
	Theta += 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)


Part.show(Part.makePolygon(Epicycloid_Points))



Thank you again! I'm ATM still fiddling with the manual version. I think I still need this for a proof for B-spline working appropriately for a fine curve.
I'm going to look at your code over the weekend.
Unfortunateley the Sketcher's B-spline editor doesn't forgive any failure, e.g. like wrong clicks, wrong mouse buttons when moving/zooming the scene... :-(
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 »

My pleasure. I don't know enough about spline creation to get that working with better resolution. When looking at it, I did notice that the generated Spline was reducing the number of points created, creating larger line segments in the result. I tried it as a Spline interpolation which I thought would force it through each point, but it looks the same. This looks like tessellation of a surface, but tessellation doesn't apply here. The polygon is still a piece-wise linear approximation, but it forces use of all points generated.
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 »

Manuel

Here a new version without animation (put the 2 macro files in the frecad macro directory and click on epitroJCD.FCMacro when in a sketch)
FreeCAD2 Macro.jpg
FreeCAD2 Macro.jpg (55.21 KiB) Viewed 969 times


I got a shape and extrude it

Only with a 60points epitrochoid a the beginning

If it's ok i can give you more explanations
FreeCAD Macro.jpg
FreeCAD Macro.jpg (19.94 KiB) Viewed 969 times
Attachments
EpitroJCD.FCMacro
(2.25 KiB) Downloaded 40 times
BaseF.py
(1.37 KiB) Downloaded 36 times
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 »

JoshM wrote: Fri Jan 11, 2019 6:08 pm My pleasure. I don't know enough about spline creation to get that working with better resolution. When looking at it, I did notice that the generated Spline was reducing the number of points created, creating larger line segments in the result. I tried it as a Spline interpolation which I thought would force it through each point, but it looks the same. This looks like tessellation of a surface, but tessellation doesn't apply here. The polygon is still a piece-wise linear approximation, but it forces use of all points generated.
So far I haven't tested your latest script, that's planned for the next hours. I assume it would increase the accuracy of the B-spline points and prevents points to slip away when selected. Let's see.

With my now finished manual spline edit I come to the same conclusion like you (although I've probably again made a mistake at the closing step :oops: ).
The created spline's segments are way too large. Maybe, the attached screenshots can show this. Here on my display it looks like a polygon. I really need to increase the points taken into account for the spline creation / displaying.

OMG, I haven't thought that this challenge would be so time consuming... But all the help from you people in this thread helped to reduce time to create a usable solution soon.

Many Thanks!

Manually created periodic B-spline (based on 360 points of DjangoFreeCAD's script some days ago)
Manually created periodic B-spline (based on 360 points of DjangoFreeCAD's script some days ago)
Screenshot_20190112_135526.png (10.49 KiB) Viewed 966 times

PartDesign created pad from the B-spline sketch above
PartDesign created pad from the B-spline sketch above
Screenshot_20190112_140435.png (8.95 KiB) Viewed 966 times
Last edited by manuelkrause on Sat Jan 12, 2019 1:44 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 »

DjangoFreeCAD wrote: Sat Jan 12, 2019 1:09 pm Manuel

Here a new version without animation (put the 2 macro files in the frecad macro directory and click on epitroJCD.FCMacro when in a sketch)

FreeCAD2 Macro.jpg



I got a shape and extrude it

Only with a 60points epitrochoid a the beginning

If it's ok i can give you more explanationsFreeCAD Macro.jpg
Many thanks to yoo too, @DjangoFreeCAD!

I'll try your new scripts at once. They look promising!
(oh, oh, my "green peaks" from my manual B-spline haven't been symmetrical over the curve, another indication that I made a mistake within the creation. :oops: )

Am going to report back soon!
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 »

DjangoFreeCAD wrote: Sat Jan 12, 2019 1:09 pm Manuel

Here a new version without animation (put the 2 macro files in the frecad macro directory and click on epitroJCD.FCMacro when in a sketch)

FreeCAD2 Macro.jpg

I got a shape and extrude it

Only with a 60points epitrochoid a the beginning

If it's ok i can give you more explanationsFreeCAD Macro.jpg
O.k. it works well and it works fast!!!
And I also like the francais flavour in it. :-) Thanks, that I had some years of French at school :-) .

I've modified the script a little (measuerements, 360 steps) like in my previous tests.
But I'm not confident with it, regarding the 3240 degrees of freedom (!) remaining in the sketch.

What kind of B-spline do you use? Can eventually using the "periodic B-spline" help to fix this?

Again many thanks!
Best regards, Manuel

PD pad from an Epicycloid with rolling extension, actual scripts from DjangoFreeCAD
PD pad from an Epicycloid with rolling extension, actual scripts from DjangoFreeCAD
Screenshot_20190112_150554.png (10.02 KiB) Viewed 954 times
Post Reply