B-Spline from Airfoil

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
pbhuter84
Posts: 5
Joined: Sat Dec 31, 2022 7:26 pm

B-Spline from Airfoil

Post by pbhuter84 »

I have a set of NACA airfoil coordinates that I am importing into FreeCAD. However, when I convert the points to a wire and subsequently work through the process to create an actual wing, I end up with some 200+ individual faces. I am thinking (and please, correct me if I am wrong) that if I use a B-spline, I will end up with a single face. However, creating a B-spline from the individual points is not as easy as I had originally thought. I was attempting to create a spline by clicking each individual point, but with so many points it was not a very effective process. I also tried converting the points to a sketch and then converting the sketch into splines, but that still resulted in 200+ individual splines. Does anyone have experience with this? Or have suggestions on how I can do this more efficiently? I did try converting the input airfoil to an SVG, but the conversion process still resulted in multiple faces.
Bance
Veteran
Posts: 4186
Joined: Wed Feb 11, 2015 3:00 pm
Location: London

Re: B-Spline from Airfoil

Post by Bance »

Try airplane design from Addon manager...
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: B-Spline from Airfoil

Post by Roy_043 »

There are also these macros that can be installed from the Addon Manager as well:
Macro AeroFoil
Macro Airfoil Import & Scale
Macro ImportAirfoil
pbhuter84
Posts: 5
Joined: Sat Dec 31, 2022 7:26 pm

Re: B-Spline from Airfoil

Post by pbhuter84 »

Bance wrote: Sat Dec 31, 2022 7:48 pm Try airplane design from Addon manager...
Thanks, I had previously installed this add-on, but I get a "No module named 'App.xfoil' error:
Untitled.png
Untitled.png (50.64 KiB) Viewed 923 times
Any idea about what is causing this? I have also installed the Plot and Curved Shapes, as specified.
User avatar
looo
Veteran
Posts: 3941
Joined: Mon Nov 11, 2013 5:29 pm

Re: B-Spline from Airfoil

Post by looo »

there is also this attempt for this specific task:
https://vimeo.com/user881402
https://github.com/looooo/freecad.airfoil
pbhuter84
Posts: 5
Joined: Sat Dec 31, 2022 7:26 pm

Re: B-Spline from Airfoil

Post by pbhuter84 »

Roy_043 wrote: Sat Dec 31, 2022 7:54 pm There are also these macros that can be installed from the Addon Manager as well:
Macro AeroFoil
Macro Airfoil Import & Scale
Macro ImportAirfoil
I installed the Import & Scale, but I keep getting an 'invalid .dat file' error. I tried using the .dat file downloaded from AirfoilTools (original), but also a couple of variants with the header removed and with the points all in order. Some of the original is:
NASA SC(2)-0402 AIRFOIL
103. 103.

0.000000 0.000000
0.002000 0.001350
0.005000 0.002050
0.010000 0.002800
0.020000 0.003750
0.030000 0.004450
0.040000 0.005000
0.050000 0.005500
0.060000 0.005900
0.070000 0.006250
0.080000 0.006600
User avatar
Roy_043
Veteran
Posts: 8450
Joined: Thu Dec 27, 2018 12:28 pm

Re: B-Spline from Airfoil

Post by Roy_043 »

I get the same error although the imported geometry seems correct.

I can't get Macro_AeroFoil to work. Some installation files seem to be missing.

The code for Macro_ImportAirfoil in the Wiki is incomplete, but the full code is available here:
https://raw.githubusercontent.com/VAZMF ... il.FCMacro
With this code I was able to import https://m-selig.ae.illinois.edu/ads/coord/sc20402.dat
pbhuter84
Posts: 5
Joined: Sat Dec 31, 2022 7:26 pm

Re: B-Spline from Airfoil

Post by pbhuter84 »

Roy_043 wrote: Sat Dec 31, 2022 11:54 pm I get the same error although the imported geometry seems correct.

I can't get Macro_AeroFoil to work. Some installation files seem to be missing.

The code for Macro_ImportAirfoil in the Wiki is incomplete, but the full code is available here:
https://raw.githubusercontent.com/VAZMF ... il.FCMacro
With this code I was able to import https://m-selig.ae.illinois.edu/ads/coord/sc20402.dat
Thank you very much! I discovered that the .dat file didn't close the shape, so I made a small edit to put the last points of the top and bottom at the midpoint between the original points. FreeCAD threw an error, but there was no problem with the import, and I was able to create a single-surface loft between two copies of the spline.
User avatar
grandcross
Posts: 350
Joined: Sun Oct 11, 2015 3:08 pm
Contact:

Re: B-Spline from Airfoil

Post by grandcross »

Code I use for generating symmetric airfoils in the Rocket Workbench. If you're creating asymmetric foils, I strongly advise splitting the outline in sections (top and bottom is often sufficient), otherwise it may have difficulties fitting the curves

Code: Select all

    def _airfoilY(self, x, maxThickness):
        # NACA symmetrical airfoil https://en.wikipedia.org/wiki/NACA_airfoil
        # y = 5 * maxThickness * ((0.2969 * math.sqrt(x)) - (0.1260 * x) - (0.3516 * x * x) + (0.2843 * x * x * x) - (0.1015 * x * x * x * x))

        # Apply Horner's rule
        y = 5 * maxThickness * (0.2969 * math.sqrt(x) + x * (-0.1260 +  x * (-0.3516 + x * (0.2843 - x * 0.1015))))
        return y

    def _airfoilCurve(self, foreX, chord, thickness, height, resolution):
        points = []
        points1 = []
        for i in range(0, resolution):
            
            x = float(i) / float(resolution)
            y = self._airfoilY(x, thickness)
            points.append(FreeCAD.Vector(foreX - (x * chord), y, height))
            points1.append(FreeCAD.Vector(foreX - (x * chord), -y, height))

        points.append(FreeCAD.Vector(foreX - chord, 0.0, height))
        points1.append(FreeCAD.Vector(foreX - chord, 0.0, height))

        # Creating separate splines for each side of the airfoil adds extra reference
        # points for lofting, reducing geometry errors
        splines = []
        splines.append(self._makeSpline(points).toShape())
        splines.append(self._makeSpline(points1).toShape())

        return splines 

    def _makeSpline(self, points):
        spline = Part.BSplineCurve()
        spline.buildFromPoles(points)
        return spline
pbhuter84
Posts: 5
Joined: Sat Dec 31, 2022 7:26 pm

Re: B-Spline from Airfoil

Post by pbhuter84 »

I found this on GitHub, which required a little playing with, but I was able to generate complete propellers and run OpenFOAM on them:

https://github.com/nelinnemann/of-cases ... eller/Mesh
Post Reply