UG NX二次开发源码分享:矩阵操作的基础算法代码
#include <math.h>
//矩阵复制
void Project_Matrix_Copy(double from_mtx, double to_mtx)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
to_mtx=from_mtx;
}
//矩阵初始化
void Project_Matrix_Identity(double mtx)
{
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j)
mtx=1.0;
else
mtx=0.0;
}
//矩阵相乘
void Project_Matrix_Product(double left_mtx,double right_mtx,double get_mtx)
{
int i,j,k;
double left,right;
Project_Matrix_Copy(left_mtx,left);
Project_Matrix_Copy(right_mtx,right);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
{
get_mtx=0.0;
for(k=0;k<4;k++)
get_mtx+=left*right;
}
}
//转置矩阵
void Project_MatrixGet_Transpose(double mtx,double transpose_mtx)
{
int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
transpose_mtx=mtx;
}
}
}
//从11元组获取变换矩阵
void Project_Matrix_Get_From_Move(double translation,double point,double rotation,double angle,double pos)
{
//Project_Matrix_Get_Rotation(rotation,point,angle,pos);
int i,j;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(i==j)
pos=1.0;
else
pos=0.0;
pos+=translation;
pos+=translation;
pos+=translation;
}
//向量缩放
void Project_Vector_Scale(double a,double scale,double b)
{
b=a*scale;
b=a*scale;
b=a*scale;
}
页:
[1]