管路軸測圖程序開發(fā)之?dāng)?shù)學(xué)函數(shù)
管路軸測圖程序中主要用到了兩個數(shù)學(xué)函數(shù),用向量來計算真是太方便啦!
- 將直角坐標(biāo)系下的一個向量轉(zhuǎn)換為由任意三個向量組成的坐標(biāo)系下的值;
- 計算一個向量與三個坐標(biāo)軸的向量哪個更垂直;
我將這兩個函數(shù)做成靜態(tài)成員函數(shù),方便調(diào)用,頭文件定義如下:
1: //------------------------------------------------------------------------------
2: // Copyright (c) 2012 eryar All Rights Reserved.
3: //
4: // File : IsoMath.h
5: // Author : eryar@163.com
6: // Date : 2012-3-2 21:53
7: // Version : 1.0v
8: //
9: // Description :
10: //
11: //==============================================================================
12:
13: #ifndef _ISOMATH_H_
14: #define _ISOMATH_H_
15:
16: #include <CMATH>
17:
18: #include "IsoVector.h"
19:
20: const double EPSILON = 1e-6;
21:
22: class CIsoMath
23: {
24: public:
25: CIsoMath();
26: virtual ~CIsoMath();
27:
28: // Transform coordinate from orthogonal coordinates to arbitrary coordinates
29: static void TransformCoordinate(const CIsoVector& a, const CIsoVector& xAxis, const CIsoVector& yAxis, const CIsoVector& zAxis, CIsoVector& b);
30:
31: // Compute a vVec vector which is the most vertical to uVec vector;
32: static void ComputeAxis(const CIsoVector& uVec, const CIsoVector& xAxis, const CIsoVector& yAxis, const CIsoVector& zAxis, CIsoVector& vVec);
33: };
34:
35: #endif // _ISOMATH_H_
經(jīng)過試驗,效果很滿意,對向量,線性代數(shù)的作用當(dāng)刮目相看。摘圖如下:
如圖所示為兩個法蘭和一段直管的軸測圖投影效果,其中,模型數(shù)據(jù)是我測試假設(shè)的。
TransformCoordinate函數(shù)的作用是將管路部件的模型坐標(biāo)轉(zhuǎn)換為由紅色x, y, z標(biāo)識的三個向量組成的坐標(biāo)系中的坐標(biāo);
ComputeAxis函數(shù)的作用是用來計算在紅色x, y, z表示的坐標(biāo)系中,平面一個向量與哪個軸更垂直,即點乘的值最小。其目的是用來計算法蘭的另一邊的方向;
當(dāng)改變視向時,投影后的圖形也會相應(yīng)改變,說明計算結(jié)果還是比較可靠的。如下圖所示:
到此為止,程序結(jié)構(gòu)已經(jīng)確定下來。其它代碼量為處理各管路部件的模型數(shù)據(jù)與其符號數(shù)據(jù)的轉(zhuǎn)換。
通過編程,使我對向量、矩陣的概念有了理性的認(rèn)識。通過與角度運算對比,向量真是又快精度又高。