Catalogue
上一篇博客是读Plot3D网格,这一篇差不多。根据NACA翼型生成程序给出的点坐标,拉伸为三维机翼。
只要了解正则表达式的语法就OK。
###翼型数据格式
NACA系列翼型由这个程序生成。
NACA翼型生成程序
生成的翼型数据并不直接就是下图的样子,用excel什么的稍微格式化一下就好了。
生成的网格大概这个样子:
###Node代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| var fs = require('fs');
var data = fs.readFileSync('naca_airfoil.txt', 'utf8');
var outStream = fs.WriteStream('wing.xyz'); var dataArray = data.split(/\r\n/);
var grid = { X: [], Y: [], Z: [] },
airfoil = { x: [], z: [] };
(function(){ var x, z; for (var i = 0, length = dataArray.length; i < length; i++) { x = parseFloat( dataArray[i].split(/\s+/)[0] ); z = parseFloat( dataArray[i].split(/\s+/)[1] ); airfoil.x.push(x); airfoil.z.push(z); }; })();
var WINGSPAN = 4.0, JMAX = 41;
var IMAX=airfoil.x.length; for(var j=0; j<JMAX; j++){ for(var i=0; i<IMAX; i++){ grid.X.push(airfoil.x[i]); grid.Z.push(airfoil.z[i]); grid.Y.push(WINGSPAN/(JMAX-1)*j); } }
outStream.write('1\r\n'+IMAX+'\t'+JMAX+'\t1\r\n'); for(var i=0; i<IMAX*JMAX; i++){ outStream.write(grid.X[i]+'\t'); } outStream.write('\r\n'); for(var i=0; i<IMAX*JMAX; i++){ outStream.write(grid.Y[i]+'\t'); } outStream.write('\r\n'); for(var i=0; i<IMAX*JMAX; i++){ outStream.write(grid.Z[i]+'\t'); }
outStream.end();
console.log('NACA arifoil wing mesh generation finished.');
|