弯管参数计算及编程实现

2023-05-16

 

船舶软件建立三维管道模型后,需要自动生成管子加工信息,这样就提高了设计效率。其中弯管参数主要是下料长度,弯角和转角。

下料长度是由各管段实长,即管子中心线长度,减去弯管部分切线长再加上弯管部分。实长就是向量的模。

弯角用向量的点乘来求解,即余弦定理。

转角用向量的叉乘来求解,比用两个角的精度要高。因为向量叉乘运算时的数字运算比三角函数精度高点。

因为都是矢量代数运算,所以需要一个矢量类,类定义如下:


   1:  //------------------------------------------------------------------------------  

   2:  //    Copyright (c) 2011 eryar All Rights Reserved.  

   3:  //  

   4:  //        File    :    Vector.h  

   5:  //        Author    :    eryar@163.com  

   6:  //        Date    :    2011-12-2 21:34  

   7:  //        Version    :    1.0v  

   8:  //  

   9:  //    Description    :      

  10:  //  

  11:  //==============================================================================  

  12:     

  13:  #ifndef _VECTOR_H_  

  14:  #define _VECTOR_H_  

  15:     

  16:  #pragma once  

  17:     

  18:  #include <cmath>  

  19:  #include <string>  

  20:  #include <iostream>  

  21:  using namespace std;  

  22:     

  23:  class CVector    

  24:  {  

  25:  public:  

  26:      CVector();  

  27:      CVector(const CVector& v);  

  28:      CVector(double x, double y, double z);  

  29:      virtual ~CVector();  

  30:     

  31:      // Overload operators  

  32:      CVector& operator =  (const CVector& v);  

  33:      bool     operator == (const CVector& v) const;  

  34:      bool     operator != (const CVector& v) const;  

  35:      CVector  operator +  (const CVector& v) const;  

  36:      CVector  operator -  (const CVector& v) const;  

  37:      CVector  operator *  (double k) const;  

  38:      // 向量点乘  

  39:      double   operator *  (const CVector& v) const;  

  40:     

  41:      // 向量叉乘  

  42:      CVector CrossProduct(const CVector& v);  

  43:     

  44:      // 求向量的模  

  45:      double Magnitude(void) const;  

  46:     

  47:      //   

  48:      void    Show(void) const;  

  49:     

  50:  private:  

  51:      double  m_x;  

  52:      double  m_y;  

  53:      double  m_z;  

  54:  };  

  55:     

  56:  #endif // _VECTOR_H_  

求解转角代码如下:


   1:  //------------------------------------------------------------------------------  

   2:  //    Copyright (c) 2011 eryar All Rights Reserved.  

   3:  //  

   4:  //        File    :    Main.cpp  

   5:  //        Author    :    eryar@163.com  

   6:  //        Date    :    2011-12-2 21:33  

   7:  //        Version    :    1.0v  

   8:  //  

   9:  //    Description    :      

  10:  //  

  11:  //==============================================================================  

  12:     

  13:  #include "Vector.h"  

  14:     

  15:  int main(int argc, char* argv[])  

  16:  {  

  17:      // One Pipe piece  

  18:      CVector aVector(287, 0, 0);  

  19:      CVector bVector(313, 204, 165);  

  20:      CVector cVector(0, 746, 0);  

  21:     

  22:      // Another pipe piece  

  23:  //     CVector aVector(150, 0, 0);  

  24:  //     CVector bVector(50, 150, 150);  

  25:  //     CVector cVector(50, 250, 0);  

  26:     

  27:      CVector alpha;  

  28:      CVector beta;  

  29:      double  phi = 0;  

  30:     

  31:      aVector.Show();  

  32:      bVector.Show();  

  33:      cVector.Show();  

  34:     

  35:      alpha   = aVector.CrossProduct(bVector);  

  36:      beta    = bVector.CrossProduct(cVector);  

  37:     

  38:      phi = (alpha * beta) / (alpha.Magnitude() * beta.Magnitude());  

  39:      cout<<"Rotate : "<<acos(phi) * 180 / 3.1416<<endl;  

  40:     

  41:      return 0;  

  42:  }  
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

弯管参数计算及编程实现 的相关文章

随机推荐