狮猿社CATIA

CAA:如何通过两个向量生成轴系

2020-10-27  本文已影响0人  锦囊喵

以下代码来自 用例CAAMthBase ,属于 CAAMathematics.edu 框架,路径如下:

Windows InstallRootDirectory\CAAMathematics.edu\CAAMthBase.m
Unix InstallRootDirectory/CAAMathematics.edu/CAAMthBase.m/


CATMathPoint    O, A(20. ,10. ,0.) ; // Default constructor, O is (0.,0.,0.)
    
CATMathVector u(10., 20. ,0.);
u.Normalize();                     // Normalize u;
    
// H: Orthogonal projection of A on the line (O,u): 
// Use the operators 
// A-O is a vector, (A-O)*u the dot product
//
CATMathVector OA = A - O ;
CATMathPoint  H  = O + ( OA*u ) * u;
 
// Computes the normal of the two vectors (A-O) and u: ^ is the cross product
CATMathVector n  = OA ^ u;      
    
//
// Another way to project to get H: 
// use the Project method of the CATMathLine class. 
//
CATMathLine  line(O,u);
CATMathPoint projection;
line.Project( A , projection );
     
// Returns the distance between the two computed points. 
//If non nul, it is an error.
        
if ( H.SquareDistanceTo( projection ) != 0.  ) return (1);
    
// Outputs the coordinates of the projected points
double aCoord[3];
H.GetCoord( aCoord );
cout << "coordinates of the projected point : " 
        << aCoord[0] << "\t" 
        << aCoord[1] << "\t"
        << aCoord[2] << endl;

注意 这一句:

CATMathPoint  H  = O + ( OA*u ) * u;
假设 向量OA、u有夹角,且不为90度,则OA,OAu,(OAu)*u三个向量成一个坐标系的三个轴向量
上一篇下一篇

猜你喜欢

热点阅读