📄 dlgrms.cpp
字号:
// dlgRMS.cpp : implementation file
//
#include "stdafx.h"
#include "GA.h"
#include "dlgRMS.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define data 500
#define Draw 1000
/////////////////////////////////////////////////////////////////////////////
// CdlgRMS dialog
extern int space,meshnumber;
extern float x[data],y[data],z[data],tknotdata[Draw];
extern int countY,begincountY;
extern float DrawB2x[Draw],DrawB2y[Draw],DrawB2z[Draw];
float xrms,yrms,zrms;
int section;
/////////////////////////////////////////////////////////////////////////////
CdlgRMS::CdlgRMS(CWnd* pParent /*=NULL*/)
: CDialog(CdlgRMS::IDD, pParent)
{
//{{AFX_DATA_INIT(CdlgRMS)
m_rms = 0.0f;
m_section = 0;
//}}AFX_DATA_INIT
}
void CdlgRMS::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CdlgRMS)
DDX_Text(pDX, IDC_EDIT1, m_rms);
DDX_Text(pDX, IDC_EDIT2, m_section);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CdlgRMS, CDialog)
//{{AFX_MSG_MAP(CdlgRMS)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CdlgRMS message handlers
void CdlgRMS::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
yrms = m_rms;
section = m_section;
RMSf();
UpdateData(false);
CDialog::OnOK();
}
void CdlgRMS::RMSf()
{
int n = 1;
int counttimes = 0;
float sum = 0;
float sum1 = 0;
float t,tknot[31],nbasis3[50],xcurve,ycurve,zcurve;
countY = 0;
begincountY = 0;
while ( n <= space) {
if (y[n+space*(section-1)] == 0){
if (countY == 0) begincountY = begincountY+1;
}
else {countY = countY + 1;}
n = n+1;
}
for (int i=1; i<=countY;i++){
if (yrms == y[i+space*(section-1)]){
n = i;
xrms = x[i+space*(section-1)];
zrms = z[i+space*(section-1)];
}
}
for (i=1; i<=countY-1;i++){
sum = sum +
sqrt((x[i+1+space*(section-1)] - x[i+space*(section-1)])*(x[i+1+space*(section-1)] - x[i+space*(section-1)])
+ (y[i+1+space*(section-1)] - y[i+space*(section-1)])*(y[i+1+space*(section-1)] - y[i+space*(section-1)])
+ (z[i+1+space*(section-1)] - z[i+space*(section-1)])*(z[i+1+space*(section-1)] - z[i+space*(section-1)]));
}
for (i=1; i<=n-1;i++){
sum1 = sum1 +
sqrt((x[i+1+space*(section-1)] - x[i+space*(section-1)])*(x[i+1+space*(section-1)] - x[i+space*(section-1)])
+ (y[i+1+space*(section-1)] - y[i+space*(section-1)])*(y[i+1+space*(section-1)] - y[i+space*(section-1)])
+ (z[i+1+space*(section-1)] - z[i+space*(section-1)])*(z[i+1+space*(section-1)] - z[i+space*(section-1)]));
}
t = sum1 / sum;
n = 0;
for (i=1; i<=30;i++){
tknot[i] = tknotdata[i+30*(section-1)];
}
for (i=1;i<=30;i++){
if (tknot[i] == 1) break;
else if (tknot[i] < 1 && tknot[i] > 0) n = n + 1;
}
bbasis3(4,t,n+1,tknot,nbasis3);
ycurve = 0;zcurve = 0;
for (i=1;i<=meshnumber;i++){
xcurve = ycurve + nbasis3[i]*DrawB2x[i+space*(section-1)];
ycurve = ycurve + nbasis3[i]*DrawB2y[i+space*(section-1)];
zcurve = zcurve + nbasis3[i]*DrawB2z[i+space*(section-1)];
}
sum = sqrt((xrms - xcurve)*(xrms - xcurve) + (yrms - ycurve)*(yrms - ycurve) + (zrms - zcurve)*(zrms - zcurve));
char a[8];
sprintf(a,"%7.4f",sum);
MessageBox(a,"RMS Error",MB_OK);
}
void CdlgRMS::bbasis3(int c, float t, int npts, float *xv, float *nbasis)
{
float temp0[51];
float b1,b2;
int nplusc;
int i,k;
nplusc=npts+c;
// -------------------------------------------------------------------*
// zero the temporary arrays
// -------------------------------------------------------------------*
for(i=1;i<=nplusc;i++){
temp0[i]=0.;
}
// -------------------------------------------------------------------*
// calculate the first order basis function nbasis(i,1)
// -------------------------------------------------------------------*
for(i=1;i<=nplusc-1;i++){
if(t>=xv[i] && t<xv[i+1] ) temp0[i]=1.0;
else temp0[i]=0.0;
}
// -------------------------------------------------------------------*
// calculate the higher order basis functions
// calculate basis fuction
//--------------------------------------------------------------------*
for(k=2;k<=c;k++){
for(i=1;i<=nplusc-k;i++){
if( temp0[i]!=0.0)
b1=(t-xv[i])*temp0[i] / (xv[i+k-1]-xv[i]);
else
b1=0.0;
if( temp0[i+1]!=0.0)
b2=( xv[i+k]-t )*temp0[i+1] / (xv[i+k]-xv[i+1]);
else
b2=0.0;
temp0[i]=b1+b2;
} //i
} //k
if( t==xv[nplusc] ) temp0[npts]=1.0;
for(i=1;i<=npts;i++) nbasis[i]=temp0[i];
if( t==xv[nplusc] ) nbasis[npts]=1.0;
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -