📄 mathmetric.cpp
字号:
// MathMetric.cpp: implementation of the MathMetric class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BiShe.h"
#include "MathMetric.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/**********************************************************
函数名:foo
功能:定义此函主要是为了让模板具现化
入口参数:无
出口参数:无
说明:该函数必须调用类中所有的公共函数甚至是么有函数,否则
在编译过程中将出错
**********************************************************/
MathMetric::MathMetric()
{
}
/**********************************************************
函数名:foo
功能:定义此函主要是为了让模板具现化
入口参数:无
出口参数:无
说明:该函数必须调用类中所有的公共函数甚至是么有函数,否则
在编译过程中将出错
**********************************************************/
MathMetric::MathMetric(double*data,unsigned int line,unsigned int clum)
{
this->line=line;
this->clum=clum;
this->data=(double*)malloc(sizeof(double)*line*clum);
if(!this->data)
return;
memcpy((void*)this->data,(void*)data,sizeof(double)*line*clum);
}
/**********************************************************
函数名:foo
功能:定义此函主要是为了让模板具现化
入口参数:无
出口参数:无
说明:该函数必须调用类中所有的公共函数甚至是么有函数,否则
在编译过程中将出错
**********************************************************/
MathMetric::~MathMetric()
{
free(data);
}
/**********************************************************
函数名:foo
功能:定义此函主要是为了让模板具现化
入口参数:无
出口参数:无
说明:该函数必须调用类中所有的公共函数甚至是么有函数,否则
在编译过程中将出错
**********************************************************/
/*void foo()
{
MathMetric aa;
aa.multiple(NULL,1,1,NULL,1,1);
aa.devide(NULL,1,1,NULL,1,1);
aa.add(NULL,1,1,NULL,1,1);
aa.sub(NULL,1,1,NULL,1,1);
aa.Inverse(NULL,1);
}*/
/**********************************************************
函数名:Rotate
功能:以图片中心为原点旋转X度
入口参数:doAngle:旋转度数
出口参数:无
说明:函数中计算f1,f2是因为旋转是以图片中心进行的,但实际的算法
却是以图片的左上角为原点进行,所以这样处理以后需要将图片
平移(f2,f1)
**********************************************************/
double* MathMetric::add(double* metric1,unsigned int dim1,unsigned int dim2,double* metric2,unsigned int dim3,unsigned int dim4)
{
double* temp;
double* result;
if((dim1!=dim3)&&(dim2!=dim4))
{
AfxMessageBox("两矩阵维数不匹配!!!不能相加");
return NULL;
}
result=(double*)malloc(dim1*dim2*sizeof(double));
ASSERT(result);
temp=result;
memset(result,0,dim1*dim2*sizeof(double));
for(unsigned int i=0;i<dim1*dim2;i++)
{
*result++=*metric1+++*metric2++;
}
return temp;
}
/**********************************************************
函数名:Rotate
功能:以图片中心为原点旋转X度
入口参数:doAngle:旋转度数
出口参数:无
说明:函数中计算f1,f2是因为旋转是以图片中心进行的,但实际的算法
却是以图片的左上角为原点进行,所以这样处理以后需要将图片
平移(f2,f1)
**********************************************************/
double* MathMetric::sub(double* metric1,unsigned int dim1,unsigned int dim2,double* metric2,unsigned int dim3,unsigned int dim4)
{
double* temp;
double* result;
if((dim1!=dim3)&&(dim2!=dim4))
{
AfxMessageBox("两矩阵维数不匹配!!!");
return NULL;
}
result=(double*)malloc(dim1*dim2*sizeof(double));
ASSERT(result);
temp=result;
memset(result,0,dim1*dim2*sizeof(double));
for(unsigned int i=0;i<dim1*dim2;i++)
*result++=*metric1++-*metric2++;
return temp;
}
/**********************************************************
函数名:Rotate
功能:以图片中心为原点旋转X度
入口参数:doAngle:旋转度数
出口参数:无
说明:函数中计算f1,f2是因为旋转是以图片中心进行的,但实际的算法
却是以图片的左上角为原点进行,所以这样处理以后需要将图片
平移(f2,f1)
**********************************************************/
double* MathMetric::multiple(double* metric1,unsigned int dim1,unsigned int dim2,double* metric2,unsigned int dim3,unsigned int dim4)
{
double* temp;
double* result;
if(dim2!=dim3)
{
AfxMessageBox("两矩阵维数不匹配!!!");
return NULL;
}
result=(double*)malloc(dim1*dim4*sizeof(double));
ASSERT(result);
temp=result;
memset(result,0,dim1*dim4*sizeof(double));
for(unsigned int j=0;j<dim1;j++)
for(unsigned int k=0;k<dim4;k++)
{
for(unsigned int i=0;i<dim2;i++)
{
*result+=(metric1[j*dim2+i]*metric2[i*dim4+k]);
}
result++;
}
return temp;
}
/**********************************************************
函数名:devide
功能:以图片中心为原点旋转X度
入口参数:doAngle:旋转度数
出口参数:无
说明:函数中计算f1,f2是因为旋转是以图片中心进行的,但实际的算法
却是以图片的左上角为原点进行,所以这样处理以后需要将图片
平移(f2,f1)
**********************************************************/
double* MathMetric::devide(double* metric1,unsigned int dim1,unsigned int dim2,double* metric2,unsigned int dim3,unsigned int dim4)
{
if((dim1!=dim3)&&(dim2!=dim4))
{
AfxMessageBox("两矩阵维数不匹配!!!");
}
double* result=(double*)malloc(dim1*dim4*sizeof(double));
ASSERT(result);
memset(result,0,dim1*dim4*sizeof(double));
return result;
}
/**********************************************************
函数名:reverse
功能:求矩阵的转置矩阵
入口参数:无
出口参数:成功返回true,失败返回false
说明:仅有方正才有转置矩阵
**********************************************************/
bool MathMetric::reverse(double *data, unsigned int line, unsigned int colum)
{
unsigned int i;
unsigned int n;
unsigned temp;
unsigned temp1;
i=0;
n=0;
temp=0;
temp1=0;
if(line!=colum)
return false;
for(i=0;i<line;i++)
for(n=i+1;n<colum;n++)
{
temp=i*colum+n;
temp1=n*colum+i;
data[temp]+=data[temp1];
data[temp1]=data[temp]-data[temp1];
data[temp]-=data[temp1];
}
return true;
}
/**********************************************************
函数名:inverse
功能:求矩阵的逆
入口参数:a:矩阵的无素数组的指针,其按行按列存放在一维数组中
n:矩阵的维数
出口参数:如果矩阵有逆则返回真,否则返回假
说明:只有方阵才有其逆矩阵
**********************************************************/
bool MathMetric::inverse(double* a,int n)
{
int *is,*js,i,j,k,l,u,v;
double d,p;
is=(int*)malloc(n*sizeof(int));
js=(int*)malloc(n*sizeof(int));
for (k=0; k<=n-1; k++)
{ d=0.0;
for (i=k; i<=n-1; i++)
for (j=k; j<=n-1; j++)
{
l=i*n+j;
p=fabs(a[l]);
if (p>d)
{
d=p;
is[k]=i;
js[k]=j;
}
}
if (d+1.0==1.0)
{
free(is);
free(js);
AfxMessageBox("该矩阵无逆阵。\n");
return(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -