Creating surfaces from point data or analytical expression

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
jotter
Posts: 13
Joined: Fri Feb 24, 2017 4:25 pm

Re: Creating surfaces from point data or analytical expression

Post by jotter »

Thank both for clearing that up, I have been dealing with knots as a single list with repeated knots where necessary.
You have to transform your cylindrical coordinates into Cartesian which shouldn't be too complicated. See also: https://en.wikipedia.org/wiki/List_of_c ... oordinates
I know how to transform between the two co-ordinate systems.

My questions relates to the conversion of the b-spline surface into an IGES file. For example, consider a cylinder. I know that if I wanted to recreate a cylinder I would simply revolve a line, this is a simple example that can be extended to any shape defined with cylindrical co-ordinates. My u and v knots will be axial and azimtuhal positions around the cylinder. If I create a b-spline surface in FreeCAD using these knots I will create a plane. How could I then convert this into a IGES file in a Cartesian co-ordinate system? It is not as simple as using the transformations listed above as the IGES file must be in a parametric form.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Creating surfaces from point data or analytical expression

Post by wmayer »

Maybe it's best to come up with a concrete example as it's hard to follow you there.
jotter
Posts: 13
Joined: Fri Feb 24, 2017 4:25 pm

Re: Creating surfaces from point data or analytical expression

Post by jotter »

OK, I'll back to my original question with an example.

Problem
I have a surface in the form rho = f(phi,z) using a cylindrical co-ordinate systems as defined here : https://en.wikipedia.org/wiki/Cylindric ... ate_system . I need to convert this into an IGES or STEP file so that I can import it into the meshing software ANSYS ICEM CFD.

Solution 1
As suggested by Chris_G. I generate a point cloud from my function f above in x,y and z co-ordinates. I can then import this into FreeCAD and use the approximate B-spline surface function in the reverse engineering toolbox.

To test this I have imported a point cloud which corresponds to a unit cylinder and half a unit cylinder in Cartesian space (in case there were any issues with the surface having to be closed). I have attached two figures which show the surfaces which is generated (Fig 1 and Fig 2). Neither of which achieves the desired result. This examples use 15 poles in each direction with cubic splines. I have tried using more poles but this does not improve the situation. Perhaps I need to make use of the option to specify the directions of u and v? The most sensible directions would be the z axis and the unit radial vector. Would it be possible in FreeCAD to specify a radial direction which is a function of the azimuthal angle (phi)?

Solution 2

I could create a B-spline surface in python, define this in FreeCAD and then export this surface to an IGES file.

My first thought on this is to define a spline surface as a function of f(phi,z) and then import into FreeCAD. I am using the following function from SciPy to create my B-splines (this is based on the methods and nomenclature of Dierckx ) :

https://docs.scipy.org/doc/scipy/refere ... pline.html

My knots and coefficients for a unit cylinder would be:
coefficients : [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
knots in the z direction [ 0., 0., 0., 0., 1., 1., 1., 1.]
knots in the array([ 0., 0., 0., 0., 360., 360., 360., 360.])) (when I import these into FreeCAD I normalised them to be zero and 1)

If I create a B-spline using these knots of course I get a xy plane (see Fig 3). Can FreeCAD work in cylindrical co-ordinates? As instead of a plane I need have a cylinder.

Alternatively, I can create a b-spline as z= g(x,y).

coefficients : [ -7.28486197e-16 3.06984542e-15 -2.57586262e-15 4.76655891e-16
2.40824265e-15 -1.05812646e-14 1.13357146e-14 -2.23686939e-15
-1.73698400e-15 8.62344871e-15 -1.21159909e-14 2.00040788e-15
6.70568863e-17 7.43619156e-16 1.30309124e-15 -1.22220084e-16]
knots in x direction [ 0., 0., 0., 0., 1., 1., 1., 1.]
knots in y direction [-0.99794539, -0.99794539, -0.99794539, -0.99794539, 1. , 1. , 1. , 1. ]

At which point my knowledge of B-splines breaks down, and my resultant surface looks like Fig.4 . Not a cylinder. Perhaps this method has some potential if I implement it correctly.
Attachments
Fig_4.png
Fig_4.png (22.73 KiB) Viewed 3513 times
Fig_3.png
Fig_3.png (4.24 KiB) Viewed 3513 times
Fig_2.png
Fig_2.png (36.42 KiB) Viewed 3513 times
Fig_1.png
Fig_1.png (28.2 KiB) Viewed 3513 times
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Creating surfaces from point data or analytical expression

Post by wmayer »

The knot vector only has a minimal impact on the form of a spline. You can make them non-uniform or set a different multiplicity of inner knots to get a sharp corner. But the form is mostly influenced by the control points.
I thought that you already have the control points in cylindrical coordinates and you just had to convert them in Cartesian coordinates.
coefficients : [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
From the SciPy docs I have seen that this is the output of SmoothBivariateSpline? But what is its meaning? I haven't found any information about it.
If I create a B-spline using these knots of course I get a xy plane (see Fig 3). Can FreeCAD work in cylindrical co-ordinates? As instead of a plane I need have a cylinder.
FreeCAD doesn't support cylindrical coordinates and I think that the cad kernel (occ) doesn't support them either.

So, for me it's still not clear where to get the control points from.
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Creating surfaces from point data or analytical expression

Post by ulrich1a »

Depending on what kind of surface should be created, you may have to look at the possibilities of FreeCAD first. The Draft-Workbench has to tool to create a b-spline going through a set of points: https://www.freecadweb.org/wiki/Draft_BSpline
Those curves can be swept along a path to build 3-dimensional surfaces.
Microelly2 is working on a tool to create nurbs-surfaces: http://freecadbuch.de/doku.php?id=story:neddle
FreeCAD can be scripted with python, so you may directly create your surface with FreeCAD-commands. see here: https://www.freecadweb.org/wiki/Topolog ... _scripting

If it is possible to work with tetrahedrons in Ansys, it is possible to create your mesh within the FreeCAD FEM-workbench and write an Abaqus-inp-file.
Ansys can import and export this type of mesh: : http://www.padtinc.com/blog/the-focus/f ... fe-modeler

Ulrich
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Creating surfaces from point data or analytical expression

Post by Chris_G »

Do you have your points ordered into a 2D array ?
In that case, you can try to use functions interpolate() or approximate() of a Part.BSplineSurface :

Code: Select all

bs = Part.BSplineSurface()
print(bs.approximate.__doc__)
print(bs.interpolate.__doc__)
Here is what I get when discretizing a half-cylinder :
cylinder.jpg
cylinder.jpg (21.04 KiB) Viewed 3482 times
jotter
Posts: 13
Joined: Fri Feb 24, 2017 4:25 pm

Re: Creating surfaces from point data or analytical expression

Post by jotter »

ulrich1a wrote:Depending on what kind of surface should be created, you may have to look at the possibilities of FreeCAD first. The Draft-Workbench has to tool to create a b-spline going through a set of points: https://www.freecadweb.org/wiki/Draft_BSpline
Those curves can be swept along a path to build 3-dimensional surfaces.
Microelly2 is working on a tool to create nurbs-surfaces: http://freecadbuch.de/doku.php?id=story:neddle
FreeCAD can be scripted with python, so you may directly create your surface with FreeCAD-commands. see here: https://www.freecadweb.org/wiki/Topolog ... _scripting

If it is possible to work with tetrahedrons in Ansys, it is possible to create your mesh within the FreeCAD FEM-workbench and write an Abaqus-inp-file.
Ansys can import and export this type of mesh: : http://www.padtinc.com/blog/the-focus/f ... fe-modeler

Ulrich
Hello Ulrich, many thanks for your reply.

I am interested in sweeping the surfaces to create a surface. If this creates a B-spline surface this may be a viable option. Ideally, I would like to have analytical functions of both the b-spline and my original function. This way I can compare the curvatures across both surfaces to ensure that, to a given tolerance, I get the curvature distribution I require.

The nurbs-surface looks interesting, I will have to investigate that as well. I am not sure I will be able to create the surface from basic part shapes. I also need my geometry as an IGES or STEP file as all of the meshing is to be in ANSYS, as a volume mesh of the surrounding fluid is required.

Do you have your points ordered into a 2D array ?
In that case, you can try to use functions interpolate() or approximate() of a Part.BSplineSurface :
Chris_G,what does you array look like that you used to create that surface? Forgive me for being stupid, but I don't understand why it would be a 2D array and not simply a list of 1D array of the points.
User avatar
Chris_G
Veteran
Posts: 2579
Joined: Tue Dec 31, 2013 4:10 pm
Location: France
Contact:

Re: Creating surfaces from point data or analytical expression

Post by Chris_G »

Chris_G,what does you array look like that you used to create that surface? Forgive me for being stupid, but I don't understand why it would be a 2D array and not simply a list of 1D array of the points.
This is how interpolate() and approximate() functions of Part.BSplineSurface work.
A BSpline surface is topologically a square, with 2 directions : U and V.
So these functions need to know how each point of the array must be mapped on the surface.
The first row ( array[0] ) will be the first edge, and the last row ( array[-1] ) will be the opposite edge.
For a general unordered point cloud, you'll have to use the Reverse engineering approximate tool.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Creating surfaces from point data or analytical expression

Post by microelly2 »

If you have exact data bspline interpolate is the fasted way to get your nurbs data.
these data are stored in step files.
So when you have your poles you can do almost every thing.

here some examples
http://freecadbuch.de/doku.php?id=story ... _mass_data
a demo script is at the end of the page.
jotter
Posts: 13
Joined: Fri Feb 24, 2017 4:25 pm

Re: Creating surfaces from point data or analytical expression

Post by jotter »

Chris_G wrote: Wed Mar 01, 2017 4:23 pm Do you have your points ordered into a 2D array ?
In that case, you can try to use functions interpolate() or approximate() of a Part.BSplineSurface :

Code: Select all

bs = Part.BSplineSurface()
print(bs.approximate.__doc__)
print(bs.interpolate.__doc__)
Here is what I get when discretizing a half-cylinder :
cylinder.jpg
Hi Chris,

Would be so kind as to provide a script of the process that you have used to create this example? I am struggling to recreate this example by following the documentation you have provided. Apologies for this, coding is not my strong point!

Kind regards

John
Post Reply