private double a_wl; //【输入】起飞翼载 #endregion Fields #region Constructors public CAircraft() { this.a_m = 100000; this.a_initM = 100000; this.a_twRatio = 0.6; this.a_wl = 500; this.a_H = 0; this.a_Ma = 0; this.a_V = 0; this.a_alpha = 0; this.a_sigma = 0; this.a_f = 0.3; this.a_l = 0; this.a_tLevel = 0; this.a_engNum = 0; this.a_engine1 = new CExcelData(); this.a_gasCharac = new CExcelData(); }
//计算Z1值和Z2值 public bool CalZs(CExcelData ced, double x, double y, out double zOut1, out double zOut2) { zOut1 = -1; zOut2 = -1; int colXLen = ced.ColX.Count; int colYLen = ced.ColY.Count; //传入数据非法 if (x < ced.ColX[0] || y < ced.ColY[0] || x > ced.ColX[colXLen - 1] || y > ced.ColY[colYLen - 1]) { return false; } else { bool xSign = false; bool ySign = false; int xOnLine = 0; int yOnLine = 0; //x值是否在表格中 while (xOnLine < colXLen) { if (Math.Abs(x - ced.ColX[xOnLine]) < NEGSIGN) { xSign = true; break; } xOnLine++; } //y值是否在表格中 while (yOnLine < colYLen) { if (Math.Abs(y - ced.ColY[yOnLine]) < NEGSIGN) { ySign = true; break; } yOnLine++; } if (xSign) { //表中有数据 if (ySign) { zOut1 = ced.ColZ1[xOnLine, yOnLine]; zOut2 = ced.ColZ2[xOnLine, yOnLine]; return true; } //在已有的折线中插值 else { int preY = 0; int curY = 0; while (curY < colYLen) { if (y < ced.ColY[curY]) { break; } curY++; } preY = curY - 1; double preYV = ced.ColY[preY]; double curYV = ced.ColY[curY]; double preZ1V = ced.ColZ1[xOnLine, preY]; double curZ1V = ced.ColZ1[xOnLine, curY]; double a1 = (curZ1V - preZ1V) / (curYV - preYV); double b1 = curZ1V - a1 * curYV; zOut1 = a1 * y + b1; double preZ2V = ced.ColZ2[xOnLine, preY]; double curZ2V = ced.ColZ2[xOnLine, curY]; double a2 = (curZ2V - preZ2V) / (curYV - preYV); double b2 = curZ2V - a2 * curYV; zOut2 = a2 * y + b2; return true; } } else { //在两条折线中插值 if (ySign) { int preX = 0; int curX = 0; while (curX < colXLen) { if (x < ced.ColX[curX]) { break; } curX++; } preX = curX - 1; double preXV = ced.ColX[preX]; double curXV = ced.ColX[curX]; double xRatio = (x - preXV) / (curXV - preXV); double preZ1V = ced.ColZ1[preX, yOnLine]; double curZ1V = ced.ColZ1[curX, yOnLine]; zOut1 = preZ1V + xRatio * (curZ1V - preZ1V); double preZ2V = ced.ColZ2[preX, yOnLine]; double curZ2V = ced.ColZ2[curX, yOnLine]; zOut2 = preZ2V + xRatio * (curZ2V - preZ2V); return true; } else { //找到x的位置 int preX = 0; int curX = 0; while (curX < colXLen) { if (x < ced.ColX[curX]) { break; } curX++; } preX = curX - 1; //找到y的位置 int preY = 0; int curY = 0; while (curY < colYLen) { if (y < ced.ColY[curY]) { break; } curY++; } preY = curY - 1; //计算z1 double xVpre = ced.ColX[preX]; double xVCur = ced.ColX[curX]; double xRatio = (x - xVpre) / (xVCur - xVpre); double zVpre1 = ced.ColZ1[preX, preY]; double zVpre2 = ced.ColZ1[curX, preY]; double zPre = zVpre1 + (zVpre2 - zVpre1) * xRatio; double zVcur1 = ced.ColZ1[preX, curY]; double zVcur2 = ced.ColZ1[curX, curY]; double zCur = zVcur1 + (zVcur2 - zVcur1) * xRatio; double preYV = ced.ColY[preY]; double curYV = ced.ColY[curY]; double a1 = (zCur - zPre) / (curYV - preYV); double b1 = zPre - preYV * a1; zOut1 = a1 * y + b1; //计算z2 double z2Vpre1 = ced.ColZ2[preX, preY]; double z2Vpre2 = ced.ColZ2[curX, preY]; double zPre2 = z2Vpre1 + (z2Vpre2 - z2Vpre1) * xRatio; double z2Vcur1 = ced.ColZ2[preX, curY]; double z2Vcur2 = ced.ColZ2[curX, curY]; double zCur2 = z2Vcur1 + (z2Vcur2 - z2Vcur1) * xRatio; double a2 = (zCur2 - zPre2) / (curYV - preYV); double b2 = zPre2 - a2 * preYV; zOut2 = a2 * y + b2; return true; } } } }
//读取xlsx文件 public CExcelData ImportXlsxFile(string filePath) { CExcelData ced = new CExcelData(); //打开文件 try { using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { hssfworkbook = new XSSFWorkbook(file); } } catch (Exception e) { throw e; } //读数据 try { ISheet sheet = hssfworkbook.GetSheetAt(0); System.Collections.IEnumerator rowsOri = sheet.GetRowEnumerator(); System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); //添加x的数据 rows.MoveNext(); rows.MoveNext(); IRow row = (XSSFRow)rows.Current; ced.ColX.Add(double.Parse(row.GetCell(0).ToString())); int rowTotal = 0; do { row = (XSSFRow)rows.Current; if (row.GetCell(0).ToString() != "") { double xValue = double.Parse(row.GetCell(0).ToString()); bool sign = false; double curMax = ced.ColX[ced.ColX.Count - 1]; if (xValue > curMax) sign = true; if (sign) { ced.ColX.Add(xValue); } rowTotal++; } } while (rows.MoveNext()); //MessageBox.Show(rowTotal.ToString()); //添加y、z的数据 int rowNum = ced.ColX.Count; int colNum = rowTotal / rowNum; //MessageBox.Show(rowNum + "---" + colNum); ced.ColZ1 = new double[rowNum, colNum]; ced.ColZ2 = new double[rowNum, colNum]; rowsOri.MoveNext(); IRow rowZ = (XSSFRow)rowsOri.Current; for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { rowsOri.MoveNext(); rowZ = (XSSFRow)rowsOri.Current; ced.ColZ1[i, j] = double.Parse(rowZ.GetCell(2).ToString()); ced.ColZ2[i, j] = double.Parse(rowZ.GetCell(3).ToString()); if (0 == i) { ced.ColY.Add(double.Parse(rowZ.GetCell(1).ToString())); } } } } catch (System.Exception ex) { //MessageBox.Show(ex.ToString()); throw ex; } return ced; }
//读取xls文件 public CExcelData ImportXlsFile(string filePath) { //打开文件 try { using (FileStream fs = File.OpenRead(filePath)) { hssfworkbook = new HSSFWorkbook(fs); } } catch (Exception e) { throw e; } //读数据 ISheet sheet = hssfworkbook.GetSheetAt(0); CExcelData ced = new CExcelData(); //MessageBox.Show(sheet.LastRowNum.ToString()); //读x的数据 IRow row = sheet.GetRow(1); ced.ColX.Add(double.Parse(row.GetCell(0).ToString())); int rowTotal = sheet.LastRowNum - 1; for (int i = 2; i <= rowTotal; i++) { row = sheet.GetRow(i); double xValue = double.Parse(row.GetCell(0).ToString()); double curMax = ced.ColX[ced.ColX.Count - 1]; if (xValue > curMax) { ced.ColX.Add(xValue); } } //读y、z的数据 int rowNum = ced.ColX.Count; int colNum = rowTotal / rowNum; ced.ColZ1 = new double[rowNum, colNum]; ced.ColZ2 = new double[rowNum, colNum]; for (int i = 0; i < rowNum; i++) { for (int j = 0; j < colNum; j++) { int curPos = i * colNum + j + 1; row = sheet.GetRow(curPos); ced.ColZ1[i, j] = double.Parse(row.GetCell(2).ToString()); ced.ColZ2[i, j] = double.Parse(row.GetCell(3).ToString()); if (0 == i) { ced.ColY.Add(double.Parse(row.GetCell(1).ToString())); } } } return ced; }