谁有矩阵类,或者有关的程序(我会加分) 自己写吧,要不干脆用matlab 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 matlab提供了一个C++的矩阵类,挺不错的。文档很全。可以在VC里使用。 #ifndef __CTransMat_H_#define __CTransMat_H_class CTransMat:public CObject{public: CTransMat();public: double Mat[3][3];public: //矩阵赋值 void operator =(CTransMat &scrMat); //取得数据 double operator ()(int i,int j); //初始化单位矩阵 void Identity(); //得到位移矩阵 void Movement(double dx,double dy); //得到缩放矩阵 void Scale(double sx,double sy); void Scale(double s); //得到旋转矩阵 void Rotate(double alf); //得到对x轴的镜像矩阵 void MirrorX(); //两个矩阵相乘 //Mat=scrMat*Mat void Multiply(CTransMat &scrMat); //两个矩阵相乘--左乘 //Mat=scrMat*Mat void LeftMultiply(CTransMat &scrMat); //转换一个点 void TransPoint(CSPoint &sp); //转换一个角度 void TransAngle(double &ang); //转换一个长度 void TransLength(double &len); //转换一个缩放系数 void TransScale(double &Scale);};#endif//初始化单位矩阵CTransMat::CTransMat(){ int i,j; for(i=0; i<3; i++) for (j=0; j<3; j++) if(i==j) Mat[i][j]=1; else Mat[i][j]=0;}void CTransMat::Identity(){ int i,j; for(i=0; i<3; i++) for (j=0; j<3; j++) if(i==j) Mat[i][j]=1; else Mat[i][j]=0;}//矩阵赋值void CTransMat::operator =(CTransMat &scrMat){ int i,j; for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=scrMat(i,j);}//取得数据double CTransMat::operator ()(int i,int j){ return Mat[i][j];}//得到位移矩阵void CTransMat::Movement(double dx,double dy){ CTransMat M; M.Mat[2][0]=dx; M.Mat[2][1]=dy; Multiply(M); }//得到缩放矩阵void CTransMat::Scale(double sx,double sy){ CTransMat M; M.Mat[0][0]=sx; M.Mat[1][1]=sy; Multiply(M); }void CTransMat::Scale(double s){ CTransMat M; M.Mat[0][0]=s; M.Mat[1][1]=s; Multiply(M); }//得到旋转矩阵void CTransMat::Rotate(double alf){ CTransMat M; alf*=PI/180; M.Mat[0][0]=M.Mat[1][1]=cos(alf); M.Mat[0][1]=sin(alf); M.Mat[1][0]=-M.Mat[0][1]; Multiply(M); }//得到对x轴的镜像矩阵void CTransMat::MirrorX(){ CTransMat M; M.Identity(); M.Mat[1][1]=-1; Multiply(M); }//两个矩阵相乘//Mat=Mat*scrMatvoid CTransMat::Multiply(CTransMat &scrMat){ int i,j,k; double M[3][3]; for(i=0; i<3; i++) for(j=0; j<3; j++) { M[i][j]=0; for(k=0; k<3; k++) M[i][j]+=Mat[i][k]*scrMat(k,j); } for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=M[i][j]; }//两个矩阵相乘--左乘//Mat=scrMat*Matvoid CTransMat::LeftMultiply(CTransMat &scrMat){ int i,j,k; double M[3][3]; for(i=0; i<3; i++) for(j=0; j<3; j++) { M[i][j]=0; for(k=0; k<3; k++) M[i][j]+=scrMat(i,k)*Mat[k][j]; } for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=M[i][j]; }void CTransMat::TransPoint(CSPoint &sp){ double x,y; x=Mat[0][0]*sp.x+Mat[1][0]*sp.y+Mat[2][0]; y=Mat[0][1]*sp.x+Mat[1][1]*sp.y+Mat[2][1]; sp.x=x; sp.y=y;}void CTransMat::TransAngle(double &ang){ CSPoint p1(0,0),p2; ang*=PI/180; p2.x=100*cos(ang); p2.y=100*sin(ang); TransPoint(p1); TransPoint(p2); ang=atan2(p2.y-p1.y,p2.x-p1.x); ang*=180/PI; if(ang<0) ang=360+ang;}void CTransMat::TransLength(double &len){ CSPoint p1(0,0),p2(len,0); TransPoint(p1); TransPoint(p2); len=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));}void CTransMat::TransScale(double &Scale){ double len1=100,len2; CSPoint p1(0,0),p2(len1,0); TransPoint(p1); TransPoint(p2); len2=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)); Scale =Scale*len2/len1;} 有关; 你们OpenCv都在用1.0版本吗? 困扰我数月的存盘问题,高手请进! 使用InternetOpenUrl时,错误码12006,是什么原因??? 如何在对话框中屏蔽edit控件的enter键? ::AfxMessageBox无显示消息框 关于串口与线程的问题(afxBeginThread)在线等 高分求解,关于点击URL的问题 DrawToHDC在picture控件上画图时画到控件外面去了怎么解决 一般类构造函数问题 访问ODBC数据库(我很着急的,大家救救我吧!!) 在CAsyncSocket中如何发送接收OOB数据
可以在VC里使用。
#define __CTransMat_H_
class CTransMat:public CObject
{
public:
CTransMat();
public:
double Mat[3][3];
public:
//矩阵赋值
void operator =(CTransMat &scrMat);
//取得数据
double operator ()(int i,int j);
//初始化单位矩阵
void Identity();
//得到位移矩阵
void Movement(double dx,double dy);
//得到缩放矩阵
void Scale(double sx,double sy);
void Scale(double s);
//得到旋转矩阵
void Rotate(double alf);
//得到对x轴的镜像矩阵
void MirrorX();
//两个矩阵相乘
//Mat=scrMat*Mat
void Multiply(CTransMat &scrMat);
//两个矩阵相乘--左乘
//Mat=scrMat*Mat
void LeftMultiply(CTransMat &scrMat); //转换一个点
void TransPoint(CSPoint &sp);
//转换一个角度
void TransAngle(double &ang);
//转换一个长度
void TransLength(double &len);
//转换一个缩放系数
void TransScale(double &Scale);};
#endif//初始化单位矩阵
CTransMat::CTransMat()
{
int i,j;
for(i=0; i<3; i++) for (j=0; j<3; j++)
if(i==j) Mat[i][j]=1; else Mat[i][j]=0;
}void CTransMat::Identity()
{
int i,j;
for(i=0; i<3; i++) for (j=0; j<3; j++)
if(i==j) Mat[i][j]=1; else Mat[i][j]=0;
}
//矩阵赋值
void CTransMat::operator =(CTransMat &scrMat)
{
int i,j;
for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=scrMat(i,j);
}
//取得数据
double CTransMat::operator ()(int i,int j)
{
return Mat[i][j];
}//得到位移矩阵
void CTransMat::Movement(double dx,double dy)
{
CTransMat M;
M.Mat[2][0]=dx; M.Mat[2][1]=dy;
Multiply(M);
}
//得到缩放矩阵
void CTransMat::Scale(double sx,double sy)
{
CTransMat M;
M.Mat[0][0]=sx; M.Mat[1][1]=sy;
Multiply(M);
}
void CTransMat::Scale(double s)
{
CTransMat M;
M.Mat[0][0]=s; M.Mat[1][1]=s;
Multiply(M);
}
//得到旋转矩阵
void CTransMat::Rotate(double alf)
{
CTransMat M;
alf*=PI/180;
M.Mat[0][0]=M.Mat[1][1]=cos(alf); M.Mat[0][1]=sin(alf);
M.Mat[1][0]=-M.Mat[0][1];
Multiply(M);
}
//得到对x轴的镜像矩阵
void CTransMat::MirrorX()
{
CTransMat M;
M.Identity();
M.Mat[1][1]=-1;
Multiply(M);
}//两个矩阵相乘
//Mat=Mat*scrMat
void CTransMat::Multiply(CTransMat &scrMat)
{
int i,j,k;
double M[3][3];
for(i=0; i<3; i++) for(j=0; j<3; j++) {
M[i][j]=0;
for(k=0; k<3; k++) M[i][j]+=Mat[i][k]*scrMat(k,j);
}
for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=M[i][j];
}
//两个矩阵相乘--左乘
//Mat=scrMat*Mat
void CTransMat::LeftMultiply(CTransMat &scrMat)
{
int i,j,k;
double M[3][3];
for(i=0; i<3; i++) for(j=0; j<3; j++) {
M[i][j]=0;
for(k=0; k<3; k++) M[i][j]+=scrMat(i,k)*Mat[k][j];
}
for(i=0; i<3; i++) for(j=0; j<3; j++) Mat[i][j]=M[i][j];
}
void CTransMat::TransPoint(CSPoint &sp)
{
double x,y;
x=Mat[0][0]*sp.x+Mat[1][0]*sp.y+Mat[2][0];
y=Mat[0][1]*sp.x+Mat[1][1]*sp.y+Mat[2][1];
sp.x=x; sp.y=y;
}
void CTransMat::TransAngle(double &ang)
{
CSPoint p1(0,0),p2;
ang*=PI/180;
p2.x=100*cos(ang); p2.y=100*sin(ang);
TransPoint(p1); TransPoint(p2);
ang=atan2(p2.y-p1.y,p2.x-p1.x);
ang*=180/PI;
if(ang<0) ang=360+ang;
}
void CTransMat::TransLength(double &len)
{
CSPoint p1(0,0),p2(len,0);
TransPoint(p1); TransPoint(p2);
len=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
}
void CTransMat::TransScale(double &Scale)
{
double len1=100,len2;
CSPoint p1(0,0),p2(len1,0);
TransPoint(p1); TransPoint(p2);
len2=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y));
Scale =Scale*len2/len1;
}