From MATLAB to SolidWorks, via Illustrator

It's easy enough to create equation-driven 2D shapes in MATLAB. It turns out that it's also fairly easy to export such shapes into Solidworks and use them to create pretty nice-looking parts in SolidWorks. In this example, I illustrate how to draw a formula-driven wing shape in MATLAB, export it as a PDF, simplify the outline in Adobe Illustrator, and then import it in Solidworks to create a wing-shaped extrusion.

Step 1: draw an airfoil profile in MATLAB and export as PDF

An equation for an airfoil can be found on Wikipedia: http://en.wikipedia.org/wiki/NACA_airfoil

I wrote a quick function to draw this equation in a MATLAB figure, and, if desired, export it as a PDF. (Find the code listed at the very bottom of this post.)

Step 2: import the PDF in Adobe Illustrator to simplify nodes

The Matlab function produces the shape by drawing lines between however many points you specify. In my case, I used 100 points, which gives a nice, smooth outline of the foil. Having that many points in Solidworks, however, is a pain. As a quick fix, I used the pen tool in Illustrator to outline the shape with a simplified Beltier curve. I placed a guide line along the long axis of the profile, drew the outline of the upper half, and then mirrored it down to get the full profile. This operation results in overlapping nodes at the two sides, which need to be joined. (Grab one of them with the 'A' tool, move it exactly over the other one, and press 'Ctrl'-'J'. A single point will result.) After going through this step, we're down to 10 points, shown below overlaid on the original 100-point outline:

nonenone

Step 3: export illustration as DXF

For the next step, the illustration was exported from Illustrator as an AutoCAD interchange file (DXF).

Step 4: import DXF into Solidworks

  • Create new SolidWorks part.
  • Choose your plane.
  • Go to "Insert", "DXF, DWG.."

Below are a few screen shots of the import process. Click on an image to open a bigger version.







sketch imported into SolidWorks

The part below is based on the profile above:



extruded profile

Appendix: MATLAB function to draw or PDF export an airfoil shape

  1. function airfoil_NACA00xx(c,t,res,pf)
  2. %
  3. % AIRFOIL_NACA00XX Plot a NACA 4-digit airfoil
  4. %
  5. % Function to plot a NACA 00xx airfoil
  6. % Source: Wikipedia: NACA airfoil
  7. %
  8. % Usage:
  9. %
  10. % airfoil_NACA00xx(c,t,resolution,pf)
  11. %
  12. % c chord length
  13. % t maximum thickness as a fraction of the chord
  14. % (100*t gives last two digits of NACA 4-digit denomination)
  15. % res number of points used for plotting the profile outline
  16. % pf flag for PDF output. If set to 1, a PDF file of the profile
  17. % with 1pt line thickness will be saved in the current directory.
  18. % The script will prompt you for a file name.
  19. %
  20. % Armin Hinterwirth Feb.2011
  21.  
  22. if nargin<4
  23. pf = 0; % default: no pdf file output
  24. fprintf('\nPDF output flag is 0. No PDF will be produced.\n\n');
  25. end
  26. if nargin < 3
  27. res=100; % resolution, i.e. number of points
  28. end
  29. if nargin < 2
  30. error('Not enough input arguments.');
  31. end
  32.  
  33. % prepare chord vector:
  34. x = linspace(0,c,res);
  35.  
  36. % NACA 00xx airfoil formula (4 digit, symmetrical foil)
  37. % source: Wikipedia - NACA airfoil)
  38. %
  39.  
  40. y = t ./ 0.2 .* c .* ( 0.2969 .* sqrt(x/c) - 0.1260 .* (x / c) - ...
  41. 0.3537*(x/c).^2 + 0.2843 * (x/c).^3 - 0.1015*(x/c).^4 );
  42.  
  43. % c is chord length
  44. % x is position along chord from 0 to c
  45. % y is half-thickness at given value of x
  46. % t is maximum thickness as a fraction of the chord
  47. % (100*t gives last two digits of NACA 4-digit denomination)
  48.  
  49. figure('color', [1 1 1], ...
  50. 'NumberTitle', 'off', ...
  51. 'Name', 'NACA airfoil');
  52.  
  53. patch(x,y,'k');
  54. hold on;
  55. patch(x,-y,'k');
  56. hold off;
  57. grid on;
  58. axis equal;
  59. xlabel('chord length');
  60. ylabel('y');
  61. set(gca, 'XLim', [min(x)-0.05*max(x) max(x)+0.05*max(x)]);
  62.  
  63. fprintf('Figure 1 shows a NACA foil profile with the following parameters:\n');
  64. fprintf('Chord length: %d\n', c);
  65. fprintf('Max. Thickness: %d%%\n', t*100);
  66. fprintf('Outline resolution: %d points\n\n', res);
  67.  
  68. % print to PDF only if pf equals 1:
  69. if pf == 1
  70. fprintf('\nPDF export enabled.\n\n');
  71.  
  72. fh = figure('color', [1 1 1], ...
  73. 'visible', 'off', ...
  74. 'PaperPosition', [0.5 0.5 10 7.5], ...
  75. 'PaperSize', [11 8.5]);
  76. plot(x,y,'k');
  77. hold on;
  78. plot(x,-y,'k');
  79. set(gca, 'Position', [0 0 1 1]);
  80. hold off;
  81. axis equal;
  82. box off;
  83. axis off;
  84.  
  85. fstr1 = input('Enter file name, \nor type abort to exit without saving: ', 's');
  86. fname = [fstr1 '.pdf'];
  87.  
  88. if strcmp(fstr1,'abort')==1
  89. fprintf('\nAborted. File not saved.\n')
  90. else
  91. if exist(fname, 'file')==2
  92. fprintf('\nFile %s already exists.\n', fname);
  93. s=input('Overwrite? (y/n)? ','s');
  94. if strcmp(s,'y')==1
  95. print(fh, '-dpdf', fname);
  96. fprintf('\nPDF saved as: %s \n', fname);
  97. else
  98. fprintf('\nFile not saved.\n')
  99. end
  100. else
  101. print(fh, '-dpdf', fname);
  102. fprintf('\nPDF saved as: %s \n\n', fname);
  103. end
  104. end
  105. end % if
  106.  
  107. end % of it all