用matlab编的%%%%%plot the wave of spline function%set the environment %clf reset close all %close all figure clear %clear all var clc %clear the screen format long;%set the parameters D = 4; % set the dimension of spline function/////////////////// step = 0.01; %set the step of plot multiplot = 1; %plot m figures(1) or only the m-th figure(0)%build the 1-D spline function m = 1; for x = 0:step:m - step n(1,round(x/step + 1)) = 1; end%plot the 1-D spline function figure(m); x = 0:step:m - step; plot(x,n(m,:)) xlabel('m') ylabel('N1(x)') title('1-D spline function')m = m + 1; %init the next m p(1,:) = [1 0];tic %set the timer%loop the m-D spline function count while(m <= D) %count the m-D for x = 0:step:m - step %count = fix(x/step + 1); count = round(x/step + 1); %convert count to integer temp = count; %count1 = fix(x/step - (1/step - 1)); count1 = round(x/step - (1/step - 1)); %convert count to integer
if count > ( m - 1 ) / step temp2 = 0; else temp2 = n(m-1,count); end if count1 < 1 temp1 = 0; else temp1 = n(m-1,count1); end n(m,temp) = x * temp2/(m-1) + (m-x) * temp1/(m-1); %formula end %sprint the standard value and max value %sprintf('The standard value(p) of %d-D spline function:',m) disp(['The standard value(p) of ' int2str(m) '-D spline function:']) p(m,1) = 0; for t=1:1:m-1 p(m,t+1) = n(m,t/step + 1); end p(m,m+1) = 0; standardvalue = p(m,:) %MAX = sprintf('The Max value(Max) of %d-D spline function:',m) disp(['The Max value(Max) of ' int2str(m) '-D spline function:']) c = m/step/2 + 1; Max = n(m,c)
%%plot the m-th figure; if m==D multiplot = 1; end if multiplot %plot the m-D figure(m); x = 0:step:m - step; plot(x,n(m,:),'r') xlabel('m') ylabel(['N' int2str(m) '(x)']) title([int2str(m) '-D spline function'])
%set the tick of axes-x,axes-y t = 1:1:m; set(gca,'xtick',t) t = 0:0.04:1; set(gca,'ytick',t) grid on
toc %kill the timer after any count end
%next m m=m+1; end%%toc %kill the timer
void CttBLine::DrawBLine( long n, CPoint* pControls, long lStep, CDC* pDC ) { double b0x, b0y, b1x, b1y, b2x, b2y, b3x, b3y; long lNumPoints = ( n - 1 ) * lStep; CPoint* pPoints = new CPoint[ lNumPoints ]; b0x = 2.0 * pControls[0].x - pControls[1].x; b0y = 2.0 * pControls[0].y - pControls[1].y; pControls[n].x = 2.0 * pControls[ n - 1 ].x - pControls[ n - 2 ].x; pControls[n].y = 2.0 * pControls[ n -1 ].y - pControls[ n - 2 ].y; //pControls[n] = pControls[0]; double w = 1.0 / 6.0; double dt = 1.0 / ( lStep -1 ); long lCount = 0; for( long i = 0; i < n - 1; i++ ) { if( i != 0 ) { b0x = pControls[ i - 1 ].x; b0y = pControls[ i - 1 ].y; } b1x = pControls[i].x; b1y = pControls[i].y; b2x = pControls[i+1].x; b2y = pControls[i+1].y; b3x = pControls[i+2].x; b3y = pControls[i+2].y;
double t = 0.0; for( int j = 0; j < lStep; j++ ) { double t2 = t * t; double t3 = t2 * t; double a = - t3 + 3.0 * t2 - 3.0 * t + 1.0; double b = 3.0 * t3 - 6.0 * t2 + 4.0; double c = - 3.0 * t3 + 3.0 * t2 + 3.0 * t + 1.0; double d = t3; pPoints[lCount].x = ( a * b0x + b * b1x + c * b2x + d * b3x ) * w; pPoints[lCount].y = ( a * b0y + b * b1y + c * b2y + d * b3y ) * w; lCount++; t += dt; } //pPoints[ lCount ].x = pControls[ i + 1 ].x; //pPoints[ lCount ].y = pControls[ i + 1 ].y; //lCount++; } pDC->Polyline( pPoints, lCount ); delete[] pPoints; }
提问题时标题要简明扼要地说明问题内容 给我发信息请附带原帖地址
http://www.betajin.com/alphasun/index.htm
http://alphasun.18en.com/ http://shakingtoolkit.9126.com/
DocWizard C++程序文档自动生成工具 | Wave OpenGL | HttpProxy | AjaxParser词法分析
%clf reset
close all %close all figure
clear %clear all var
clc %clear the screen
format long;%set the parameters
D = 4; % set the dimension of spline function///////////////////
step = 0.01; %set the step of plot
multiplot = 1; %plot m figures(1) or only the m-th figure(0)%build the 1-D spline function
m = 1;
for x = 0:step:m - step
n(1,round(x/step + 1)) = 1;
end%plot the 1-D spline function
figure(m);
x = 0:step:m - step;
plot(x,n(m,:))
xlabel('m')
ylabel('N1(x)')
title('1-D spline function')m = m + 1; %init the next m
p(1,:) = [1 0];tic %set the timer%loop the m-D spline function count
while(m <= D)
%count the m-D
for x = 0:step:m - step
%count = fix(x/step + 1);
count = round(x/step + 1); %convert count to integer
temp = count;
%count1 = fix(x/step - (1/step - 1));
count1 = round(x/step - (1/step - 1)); %convert count to integer
if count > ( m - 1 ) / step
temp2 = 0;
else
temp2 = n(m-1,count);
end
if count1 < 1
temp1 = 0;
else
temp1 = n(m-1,count1);
end
n(m,temp) = x * temp2/(m-1) + (m-x) * temp1/(m-1); %formula
end %sprint the standard value and max value
%sprintf('The standard value(p) of %d-D spline function:',m)
disp(['The standard value(p) of ' int2str(m) '-D spline function:'])
p(m,1) = 0;
for t=1:1:m-1
p(m,t+1) = n(m,t/step + 1);
end
p(m,m+1) = 0;
standardvalue = p(m,:)
%MAX = sprintf('The Max value(Max) of %d-D spline function:',m)
disp(['The Max value(Max) of ' int2str(m) '-D spline function:'])
c = m/step/2 + 1;
Max = n(m,c)
%%plot the m-th figure;
if m==D
multiplot = 1;
end
if multiplot
%plot the m-D
figure(m);
x = 0:step:m - step;
plot(x,n(m,:),'r')
xlabel('m')
ylabel(['N' int2str(m) '(x)'])
title([int2str(m) '-D spline function'])
%set the tick of axes-x,axes-y
t = 1:1:m;
set(gca,'xtick',t)
t = 0:0.04:1;
set(gca,'ytick',t)
grid on
toc %kill the timer after any count
end
%next m
m=m+1;
end%%toc %kill the timer
long lStep, CDC* pDC )
{
double b0x, b0y, b1x, b1y, b2x, b2y, b3x, b3y;
long lNumPoints = ( n - 1 ) * lStep;
CPoint* pPoints = new CPoint[ lNumPoints ]; b0x = 2.0 * pControls[0].x - pControls[1].x;
b0y = 2.0 * pControls[0].y - pControls[1].y;
pControls[n].x = 2.0 * pControls[ n - 1 ].x -
pControls[ n - 2 ].x;
pControls[n].y = 2.0 * pControls[ n -1 ].y -
pControls[ n - 2 ].y;
//pControls[n] = pControls[0];
double w = 1.0 / 6.0;
double dt = 1.0 / ( lStep -1 );
long lCount = 0;
for( long i = 0; i < n - 1; i++ )
{
if( i != 0 )
{
b0x = pControls[ i - 1 ].x;
b0y = pControls[ i - 1 ].y;
}
b1x = pControls[i].x;
b1y = pControls[i].y;
b2x = pControls[i+1].x;
b2y = pControls[i+1].y;
b3x = pControls[i+2].x;
b3y = pControls[i+2].y;
double t = 0.0;
for( int j = 0; j < lStep; j++ )
{
double t2 = t * t;
double t3 = t2 * t;
double a = - t3 + 3.0 * t2 - 3.0 * t
+ 1.0;
double b = 3.0 * t3 - 6.0 * t2 + 4.0;
double c = - 3.0 * t3 + 3.0 * t2 +
3.0 * t + 1.0;
double d = t3;
pPoints[lCount].x = ( a * b0x + b * b1x
+ c * b2x +
d * b3x ) * w;
pPoints[lCount].y = ( a * b0y + b * b1y
+ c * b2y +
d * b3y ) * w;
lCount++;
t += dt;
}
//pPoints[ lCount ].x = pControls[ i + 1 ].x;
//pPoints[ lCount ].y = pControls[ i + 1 ].y;
//lCount++;
}
pDC->Polyline( pPoints, lCount );
delete[] pPoints;
}