Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (layerNum == 0)
            {
                MessageBox.Show("请先输入截面几何性质数据", "error");
            }
            //
            //圆形截面
            //
            else if (shape == "圆形截面")
            {
                Form5 inputm = new Form5(this.Location.X + 50, this.Location.Y + 50);
                inputm.ShowDialog();

                //b——截面宽                                  y——截面形心位置(以第一个截面上面为坐标原点)
                //h——截面高                                  Yc——整个等效截面图的形心
                //E——截面弹性模量                            Sq——形心坐标与面积的积的和
                //S——截面面积                                S1——总面积
                //I——截面抗弯截面系数
                //输入变量
                double[] h = new double[layerNum];
                //中间变量
                double [] Mi  = new double [layerNum], EI = new double[layerNum];
                double    EIz = 0;
                //输出变量
                double[] I = new double[layerNum];
                double[,] P = new double[layerNum, 2];
                double[,] Q = new double[layerNum, 2];

                //排序
                double t = 0;
                for (int j = 0; j < layerNum - 1; j++)
                {
                    for (int i = 0; i < layerNum - 1; i++)
                    {
                        if (layersHeight[i] > layersHeight[i + 1])
                        {
                            t = layersHeight[i]; layersHeight[i] = layersHeight[i + 1]; layersHeight[i + 1] = t;
                            t = layersE[i]; layersE[i] = layersE[i + 1]; layersE[i + 1] = t;
                        }
                    }
                }
                //计算等截面抗弯界面系数
                I[0] = 3.1415926 / 64 * (layersHeight[0] * layersHeight[0] * layersHeight[0] * layersHeight[0]);
                for (int i = 1; i < layerNum; i++)
                {
                    I[i] = 3.1415926 / 64 * (Math.Pow(layersHeight[i], 4) - Math.Pow(layersHeight[i - 1], 4));
                }
                //计算每个截面的EI
                for (int i = 0; i < layerNum; i++)
                {
                    EI[i] = layersE[i] * I[i];
                    EIz   = EIz + EI[i];
                }
                //计算每个截面的Mi
                for (int k = 0; k < layerNum; k++)
                {
                    Mi[k] = layersM / EIz * EI[k];
                }

                //正应力计算
                for (int i = 0; i < layerNum; i++)
                {
                    P[i, 0] = Mi[i] * layersHeight[i] / 2 / I[i] / 1000000;
                    P[i, 1] = -Mi[i] * layersHeight[i] / 2 / I[i] / 1000000;
                }
                Q[0, 0] = 0;
                Q[0, 1] = 0;
                for (int i = 1; i < layerNum; i++)
                {
                    Q[i, 0] = Mi[i] * layersHeight[i - 1] / 2 / I[i] / 1000000;
                    Q[i, 1] = -Mi[i] * layersHeight[i - 1] / 2 / I[i] / 1000000;
                }
                //输出图形
                int      temp2 = 0;
                int      temp3 = 0;
                Graphics pic1  = panel1.CreateGraphics();
                pic1.Clear(Color.White);
                for (ii = 0; ii < layerNum; ii++)
                {
                    int temp = (int)(150 * layersHeight[layerNum - ii - 1] / layersHeight[layerNum - 1]);
                    temp2 = 85 - temp / 2;
                    temp3 = 100 - temp / 2;
                    switch (ii % 5)
                    {
                    case 0:
                        pic1.FillEllipse(Brushes.DarkGray, temp2, temp3, temp, temp); break;

                    case 1:
                        pic1.FillEllipse(Brushes.LimeGreen, temp2, temp3, temp, temp); break;

                    case 2:
                        pic1.FillEllipse(Brushes.Blue, temp2, temp3, temp, temp); break;

                    case 3:
                        pic1.FillEllipse(Brushes.Orchid, temp2, temp3, temp, temp); break;

                    case 4:
                        pic1.FillEllipse(Brushes.MediumPurple, temp2, temp3, temp, temp); break;

                    default:
                        break;
                    }
                }
                Pen p = new Pen(Color.Red, 2);
                p.DashPattern = new float[] { 2, 1 };
                pic1.DrawLine(p, 5, 100, 165, 100);



                //绘图
                {
                    double t1;
                    t1 = Math.Abs(P[0, 0]);
                    for (int i = 0; i < Form1.layerNum; i++)
                    {
                        if (Math.Abs(P[i, 0]) > t1)
                        {
                            t1 = Math.Abs(P[i, 0]);
                        }
                    }

                    double   k    = 100;
                    Graphics pic3 = panel7.CreateGraphics();
                    pic3.Clear(Color.White);
                    Pen p1 = new Pen(Color.Black, 2);
                    Pen p4 = new Pen(Color.Black, 1);
                    //坐标轴
                    pic3.DrawLine(p1, 82, 5, 82, 195);
                    pic3.DrawLine(p4, 5, 100, 165, 100);

                    //折线图
                    Pen p2 = new Pen(Color.Blue, 3);

                    //填充颜色
                    k = 100;
                    for (int i = 0; i < Form1.layerNum; i++)
                    {
                        Point[] sbx = new Point[] {
                            new Point(82, (int)(k)),
                            new Point((int)(82 + Q[i, 1] / t1 * 75), (int)(k)),
                            new Point((int)(82 + P[i, 1] / t1 * 75), (int)(k = 100 - 90 * layersHeight[i] / layersHeight[layerNum - 1])),
                            new Point(82, (int)(k)),
                        };
                        pic3.FillPolygon(Brushes.Aquamarine, sbx);
                    }

                    //填充颜色
                    k = 100;
                    for (int i = 0; i < Form1.layerNum; i++)
                    {
                        Point[] sbx = new Point[] {
                            new Point(82, (int)(k)),
                            new Point((int)(82 + Q[i, 0] / t1 * 75), (int)(k)),
                            new Point((int)(82 + P[i, 0] / t1 * 75), (int)(k = 100 + 90 * layersHeight[i] / layersHeight[layerNum - 1])),
                            new Point(82, (int)(k)),
                        };
                        pic3.FillPolygon(Brushes.Aquamarine, sbx);
                    }
                    //折线
                    k = 100;
                    for (int i = 0; i < layerNum; i++)
                    {
                        pic3.DrawLine(p2, (int)(82 + Q[i, 1] / t1 * 75), (int)(k), (int)(82 + P[i, 1] / t1 * 75), (int)(k = 100 - 90 * layersHeight[i] / layersHeight[layerNum - 1]));
                    }
                    k = 100;
                    for (int i = 0; i < layerNum; i++)
                    {
                        pic3.DrawLine(p2, (int)(82 + Q[i, 0] / t1 * 75), (int)(k), (int)(82 + P[i, 0] / t1 * 75), (int)(k = 100 + 90 * layersHeight[i] / layersHeight[layerNum - 1]));
                    }
                    Pen p5 = new Pen(Color.Black, 2);
                    p5.DashPattern = new float[] { 2, 2 };
                    k = 100 - 90 * layersHeight[0] / layersHeight[layerNum - 1];
                    for (int i = 0; i < layerNum - 1; i++)
                    {
                        pic3.DrawLine(p5, (int)(82 + P[i, 1] / t1 * 75), (int)(k), (int)(82 + Q[i + 1, 1] / t1 * 75), (int)(k));
                        k = 100 - 90 * layersHeight[i + 1] / layersHeight[layerNum - 1];
                    }
                    k = 100 + 90 * layersHeight[0] / layersHeight[layerNum - 1];
                    for (int i = 0; i < layerNum - 1; i++)
                    {
                        pic3.DrawLine(p5, (int)(82 + P[i, 0] / t1 * 75), (int)(k), (int)(82 + Q[i + 1, 0] / t1 * 75), (int)(k));
                        k = 100 + 90 * layersHeight[i + 1] / layersHeight[layerNum - 1];
                    }
                    pic3.DrawLine(p5, (int)(82 + P[layerNum - 1, 1] / t1 * 75), 10, 82, 10);
                    pic3.DrawLine(p5, (int)(82 - P[layerNum - 1, 1] / t1 * 75), 190, 82, 190);


                    Font   font    = new Font("宋体", 9f);
                    PointF pointF  = new PointF(82, 10);
                    PointF pointF1 = new PointF(105, 10);
                    PointF pointF2 = new PointF(135, 10);

                    pic3.DrawString("Yc=", font, Brushes.Black, pointF);
                    pic3.DrawString(Math.Round(layersHeight[layerNum - 1] / 2, 3).ToString(), font, Brushes.Black, pointF1);
                    pic3.DrawString("(m)", font, Brushes.Black, pointF2);

                    /*
                     *
                     * p1.DashPattern = new float[] { 2, 2 };
                     * k = 10 + 180 * Form1.layersHeight[0] / layersHeight[layerNum - 1];
                     * for (int i = 0; i < Form1.layerNum - 1; i++)
                     * {
                     *  pic3.DrawLine(p1, (int)(82 + P[i, 1] / t * 75), (int)(k), (int)(82 + P[i + 1, 0] / t * 75), (int)(k));
                     *  k = k + 180 * Form1.layersHeight[i] / layersHeight[layerNum - 1];
                     * }
                     * pic3.DrawLine(p1, (int)(82 + P[0, 0] / t * 75), 10, 82, 10);
                     * pic3.DrawLine(p1, (int)(82 + P[layerNum - 1, 1] / t * 75), 190, 82, 190);
                     * //填充颜色
                     * k = 10;
                     * for (int i = 0; i < Form1.layerNum; i++)
                     * {
                     *  Point[] sbx = new Point[]{
                     * new Point((int)(82 + P[i, 0] / t * 75),(int)(k)),
                     * new Point( (int)(82 + P[i, 1] / t * 75), (int)(k = k + 180 *layersHeight[i] / layersHeight[layerNum -1])),
                     * new Point(82,  (int)(k)),
                     * new Point(82, (int)(k - 180 *layersHeight[i] /layersHeight[layerNum -1]))
                     *                    };
                     *  pic3.FillPolygon(Brushes.Aquamarine, sbx);
                     * }*/
                }



                //输出正应力值
                Form4 WindowsForShow = new Form4(P, this.Location.X, this.Location.Y, I);
                WindowsForShow.Show();
            }



            //矩形截面
            else
            {
                Form5 inputm = new Form5(this.Location.X + 50, this.Location.Y + 50);
                inputm.ShowDialog();
                int posOfEm = 0;
                for (int i = 1; i < layerNum; i++)
                {
                    if (layersE[i] >= layersE[posOfEm])
                    {
                        posOfEm = i;
                    }
                }
                //b——截面宽                                  y——截面形心位置(以第一个截面上面为坐标原点)
                //h——截面高                                  Yc——整个等效截面图的形心
                //E——截面弹性模量                            Sq——形心坐标与面积的积的和
                //S——截面面积                                S1——总面积
                //I——截面抗弯截面系数
                //输入变量
                double[] b = new double[layerNum];
                //中间变量
                double[] S = new double[layerNum], y = new double[layerNum];
                double   Sq = 0, S1 = 0;
                //输出变量
                double[] I = new double[layerNum];
                double[,] P = new double[layerNum, 2];
                double Ic = 0;

                //计算等效截面宽
                for (int i = 0; i < layerNum; i++)
                {
                    b[i] = layerWidth * layersE[i] / layersE[posOfEm];
                }
                //计算每个截面的形心位置
                y[0] = 0.5 * layersHeight[0];
                for (int j = 1; j < layerNum; j++)
                {
                    y[j] = 0.5 * layersHeight[j] + y[j - 1] + 0.5 * layersHeight[j - 1];
                }
                //计算每个截面的面积
                for (int k = 0; k < layerNum; k++)
                {
                    S[k] = b[k] * layersHeight[k];
                    Sq   = Sq + S[k];
                    S1   = S1 + S[k] * y[k];
                }
                //计算中性面y坐标
                Yc = S1 / Sq;
                //计算每个截面的抗弯界面系数
                for (int i = 0; i < layerNum; i++)
                {
                    I[i] = b[i] * layersHeight[i] * layersHeight[i] * layersHeight[i] / 12 + S[i] * (y[i] - Yc) * (y[i] - Yc);
                    Ic   = Ic + I[i];
                }
                //正应力计算
                for (int i = 0; i < layerNum; i++)
                {
                    P[i, 0] = layersE[i] / layersE[posOfEm] * layersM * (y[i] - 0.5 * layersHeight[i] - Yc) / Ic / 1000000;
                    P[i, 1] = layersE[i] / layersE[posOfEm] * layersM * (y[i] + 0.5 * layersHeight[i] - Yc) / Ic / 1000000;
                }
                //输出图形



                int      temp2 = 0;
                Graphics pic1  = panel1.CreateGraphics();
                pic1.Clear(Color.White);
                for (ii = 0; ii < layerNum; ii++)
                {
                    int       temp = (int)(180 * layersHeight[ii] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2));
                    Rectangle rct  = new Rectangle(10, 10 + temp2, 150, temp);
                    temp2 += temp;
                    switch (ii % 5)
                    {
                    case 0:
                        pic1.FillRectangle(Brushes.DarkGray, rct); break;

                    case 1:
                        pic1.FillRectangle(Brushes.LimeGreen, rct); break;

                    case 2:
                        pic1.FillRectangle(Brushes.Blue, rct); break;

                    case 3:
                        pic1.FillRectangle(Brushes.Orchid, rct); break;

                    case 4:
                        pic1.FillRectangle(Brushes.MediumPurple, rct); break;

                    default:
                        break;
                    }
                }
                Graphics pic2 = panel2.CreateGraphics();
                pic2.Clear(Color.White);
                temp2 = 0;
                for (ii = 0; ii < layerNum; ii++)
                {
                    int       temp = (int)(180 * layersHeight[ii] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2));
                    Rectangle rct  = new Rectangle(82 - (int)(75 * layersE[ii] / layersE[posOfEm]), 10 + temp2, (int)(150 * layersE[ii] / layersE[posOfEm]), temp);
                    temp2 += temp;
                    switch (ii % 5)
                    {
                    case 0:
                        pic2.FillRectangle(Brushes.DarkGray, rct); break;

                    case 1:
                        pic2.FillRectangle(Brushes.LimeGreen, rct); break;

                    case 2:
                        pic2.FillRectangle(Brushes.Blue, rct); break;

                    case 3:
                        pic2.FillRectangle(Brushes.Orchid, rct); break;

                    case 4:
                        pic2.FillRectangle(Brushes.MediumPurple, rct); break;

                    default:
                        break;
                    }
                }
                Pen p = new Pen(Color.Red, 2);
                p.DashPattern = new float[] { 2, 1 };
                pic2.DrawLine(p, 5, (int)(180 * Yc / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)) + 10, 165, (int)(180 * Yc / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)) + 10);
                //输出正应力值
                Form4 WindowsForShow = new Form4(P, this.Location.X, this.Location.Y, I);
                WindowsForShow.Show();


                //绘图
                { double t;
                  t = Math.Abs(P[0, 0]);
                  for (int i = 0; i < Form1.layerNum; i++)
                  {
                      for (int j = 0; j < 2; j++)
                      {
                          if (Math.Abs(P[i, j]) > t)
                          {
                              t = Math.Abs(P[i, j]);
                          }
                      }
                  }

                  double   k    = 10;
                  Graphics pic3 = panel7.CreateGraphics();
                  pic3.Clear(Color.White);
                  Pen p1 = new Pen(Color.Black, 2);
                  Pen p4 = new Pen(Color.Black, 1);
                  //坐标轴
                  pic3.DrawLine(p1, 82, 5, 82, 195);
                  pic3.DrawLine(p4, 5, (int)(180 * Yc / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)) + 10, 165, (int)(180 * Yc / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)) + 10);

                  //折线图
                  Pen p2 = new Pen(Color.Blue, 3);
                  for (int i = 0; i < Form1.layerNum; i++)
                  {
                      pic3.DrawLine(p2, (int)(82 + P[i, 0] / t * 75), (int)(k), (int)(82 + P[i, 1] / t * 75), (int)(k = (k + 180 * Form1.layersHeight[i] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2))));
                  }


                  p1.DashPattern = new float[] { 2, 2 };
                  k = 10 + 180 * Form1.layersHeight[0] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2);
                  for (int i = 0; i < Form1.layerNum - 1; i++)
                  {
                      pic3.DrawLine(p1, (int)(82 + P[i, 1] / t * 75), (int)(k), (int)(82 + P[i + 1, 0] / t * 75), (int)(k));
                      k = k + 180 * Form1.layersHeight[i] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2);
                  }
                  pic3.DrawLine(p1, (int)(82 + P[0, 0] / t * 75), 10, 82, 10);
                  pic3.DrawLine(p1, (int)(82 + P[layerNum - 1, 1] / t * 75), 190, 82, 190);
                  //填充颜色
                  k = 10;
                  for (int i = 0; i < Form1.layerNum; i++)
                  {
                      Point[] sbx = new Point[] {
                          new Point((int)(82 + P[i, 0] / t * 75), (int)(k)),
                          new Point((int)(82 + P[i, 1] / t * 75), (int)(k = (k + 180 * layersHeight[i] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)))),
                          new Point(82, (int)(k)),
                          new Point(82, (int)(k - 180 * layersHeight[i] / (y[layerNum - 1] + layersHeight[layerNum - 1] / 2)))
                      };
                      pic3.FillPolygon(Brushes.Aquamarine, sbx);



                      //形心轴位置



                      Font   font    = new Font("宋体", 9f);
                      PointF pointF  = new PointF(82, 10);
                      PointF pointF1 = new PointF(105, 10);
                      PointF pointF2 = new PointF(135, 10);

                      pic3.DrawString("Yc=", font, Brushes.Black, pointF);
                      pic3.DrawString(Math.Round(Yc, 3).ToString(), font, Brushes.Black, pointF1);
                      pic3.DrawString("(m)", font, Brushes.Black, pointF2);
                  }
                }

                /* Form6 WindowsForShow1 = new Form6(P, this.Location.X + 50, this.Location.Y + 200);
                 * WindowsForShow1.Show();*/
            }
        }
Exemplo n.º 2
0
Arquivo: Form1.cs Projeto: kanke/cal
 private void callToolStripMenuItem_Click(object sender, EventArgs e)
 {
     this.Hide();
     Form4 frm = new Form4();
     frm.ShowDialog();
     this.Show();
 }