B样条的Matlab的程序是什么呀

B样条的Matlab的程序是什么呀,第1张

去这里看看!!http://wenku.baidu.com/view/dc4d1c40a8956bec0975e3b2.html

MATLAB中样条函数命令

B样条函数

splst显示生成B样条函数的M文件

spmak生成B样条函数

spcrv生成均匀划分的B样条函数

spapi插值生成B样条函数

spap2用最小二乘法拟合生成B样条函数

spaps对生成的B样条曲线进行光滑处理

spcol生成B样条函数的配置矩阵

三次样条函数

函 数描述

csapi 插值生成三次样条函数

csape 生成给定约束条件下的三次样条函数

csaps 平滑生成三次样条函数

cscvn 生成一条内插参数的三次样条曲线

getcurve 动态生成三次样条曲线

分段多项式样条函

pplst 显示关于生成分段多项式样条曲线的M文件

ppmak 生成分段多项式样条函数

ppual 计算在给定点处的分段多项式样条函数值

有理样条函数

rpmak 生成有理样条函数

rsmak 生成有理样条函数

*** 作样条函数

fnval 计算在给定点处的样条函数值

fmbrk 返回样条函数的某一部分(如断点或系数等)

fncmb 对样条函数进行算术运算

fn2fm 把一种形式的样条函数转化成另一种形式的样条函数

voidCGraph151View::seekPoint(intk)//表示k阶2{3CPoint *interim//存储B样数组指针4CDC *pDC =GetDC()5CGraph151Doc *pDoc = GetDocument()//6intj = pDoc->Length-17intlength=1.0/0.001//B样曲线的点的个数8interim =newCPoint[length]//保存B样曲线点9intindex_length=0//记录interim数组下一个下标10//画控制点图11pDC->MoveTo(pDoc->m_point[0])12for(intn=0n<pDoc->Lengthn++)13{14pDC->LineTo(pDoc->m_point[n])15pDC->MoveTo(pDoc->m_point[n])16}17///结束1819for(floatt=pDoc->T[0]t<pDoc->T[pDoc->T_Length-1]t +=0.001)20{21inti22chushihua()//还原m_point 和 im_point点数组使与初始化相同23for(intr=1r<kr++)24{25guodian()//更新一下m_point点数组 的数据26for( i=ri<=ji++)27{28floatpara129floatpara23031if( (pDoc->T[i+k-r] - pDoc->T[i]) !=0.0)32{33para1 = (t - pDoc->T[i]) / (pDoc->T[i+k-r] - pDoc->T[i])34para2 = (pDoc->T[i+k-r] - t) /(pDoc->T[i+k-r] - pDoc->T[i])35}36else37{38para1=0.039para2=0.040}4142intx =int( (para1 * pDoc->m_point[i].x) + (para2 * pDoc->m_point[i-1].x) )43inty =int( (para1 * pDoc->m_point[i].y) + (para2 * pDoc->m_point[i-1].y) )44pDoc->im_point[i].SetPoint(x,y)45}4647}4849interim[index_length++].SetPoint( pDoc->im_point[3].x,pDoc->im_point[3].y)//存储计算出的点50}5152//画图 B样曲线53CPen pen(PS_SOLID,1,RGB(255,0,0))54pDC->SelectObject(pen)55pDC->MoveTo(interim[0])56for(intn=0n<lengthn++)57{58pDC->LineTo(interim[n])59pDC->MoveTo(interim[n])60}61//B样曲线画图结束62}

#include <stdlib.h>

#include <GL/glut.h>

#pragma comment(lib,"glut32.lib")

//

#if 0

// the points of the curve - these are the same as the bezier curve

// points demonstrated in the bezier curve example.

float Points[4][3] = {

{ 10,10,0 },

{ 5,10,2 },

{ -5,0,0 },

{-10,5,-2}

}

#define NUM_POINTS 4

// The following sets of 4 indices are the curves that need to

// be drawn to create a clamped cubic b-spline. In total there

// are 5 curve segments to draw.

//

// 0 0 0 1

//0 0 1 2

// 0 1 2 3

//1 2 3 3

// 2 3 3 3

//

// Remember this when trying to understand knot vectors!!

//

#else

float Points[9][3] = {

{ 10,5,0 },

{ 5,10,0 },

{ -5,15,0 },

{ -10,-5,0 },

{ 4,-4,0 },

{ 10,5,0 },

{ 5,10,0 },

{ -5,15,0 },

{ -10,-5,0 }

}

#define NUM_POINTS 9

//若绘制过首尾控制点的曲线

// 0 0 0 1

// 0 0 1 2

// 0 1 2 3

// 1 2 3 4

// 2 3 4 5

// 3 4 5 6

// 4 5 6 6

// 5 6 6 6

//

// Remember this when trying to understand knot vectors!!

//

//若绘制首尾相接的平滑曲线 ,即为当前绘制

// 0 1 2 3

// 1 2 3 4

// 2 3 4 5

// 3 4 5 6

#endif

// the level of detail for the curve

unsigned int LOD=20

#define NUM_SEGMENTS (NUM_POINTS-3)

//

float* GetPoint(int i)

{

// return 1st point

if (i<0)

{

return Points[0]

}

if (i<NUM_POINTS)

{

return Points[i]

}

// return last point

return Points[NUM_POINTS-1]

}

//------------------------------------------------------------ OnKeyPress()

void myIdle(void)

{

glutPostRedisplay()

}

//------------------------------------------------------------ OnDraw()

void OnDraw()

{

// clear the screen &depth buffer

glClear(GL_COLOR_BUFFER_BIT)

// clear the previous transform

glLoadIdentity()

// set the camera position

// gluLookAt( 1,10,30,// eye pos

// 0,0,0, // aim point

// 0,1,0)// up direction

// glColor3f(0.5,0.2,0)

glPointSize(3)

//

// // draw curve hull

glColor3f(0.3,0,0.5)

glBegin(GL_LINE_STRIP)

for(int i=0i!=NUM_POINTS++i)

{

glVertex3fv( Points[i] )

}

glEnd()

glColor3f(0,1,0)

// begin drawing our curve

glBegin(GL_LINE_STRIP)

for(int start_cv=0,j=0j<NUM_SEGMENTSj++,start_cv++)

{

// for each section of curve, draw LOD number of divisions

for(int i=0i!=LOD++i)

{

// use the parametric time value 0 to 1 for this curve

// segment.

float t = (float)i/LOD

// the t value inverted

float it = 1.0f-t

// calculate blending functions for cubic bspline

float b0 = it*it*it/6.0f

float b1 = (3*t*t*t - 6*t*t +4)/6.0f

float b2 = (-3*t*t*t +3*t*t + 3*t + 1)/6.0f

float b3 = t*t*t/6.0f

// calculate the x,y and z of the curve point

float x = b0 * GetPoint( start_cv + 0 )[0] +

b1 * GetPoint( start_cv + 1 )[0] +

b2 * GetPoint( start_cv + 2 )[0] +

b3 * GetPoint( start_cv + 3 )[0]

float y = b0 * GetPoint( start_cv + 0 )[1] +

b1 * GetPoint( start_cv + 1 )[1] +

b2 * GetPoint( start_cv + 2 )[1] +

b3 * GetPoint( start_cv + 3 )[1]

float z = b0 * GetPoint( start_cv + 0 )[2] +

b1 * GetPoint( start_cv + 1 )[2] +

b2 * GetPoint( start_cv + 2 )[2] +

b3 * GetPoint( start_cv + 3 )[2]

// specify the point

glVertex2f( x,y )

}

}

// we need to specify the last point on the curve

//glVertex3fv( Points[NUM_POINTS-1] )

glEnd()

// draw CV's

glBegin(GL_POINTS)

for(int i=0i!=NUM_POINTS++i)

{

glVertex3fv( Points[i] )

}

glEnd()

// currently we've been drawing to the back buffer, we need

// to swap the back buffer with the front one to make the image visible

glutSwapBuffers()

}

//------------------------------------------------------------ OnInit()

void OnInit()

{

//glClearColor(1,1,1,0)

}

//------------------------------------------------------------ OnExit()

void OnExit()

{

}

//------------------------------------------------------------ OnReshape()

void OnReshape(int w, int h)

{

// prevents division by zero when minimising window

if (h==0)

{

h=1

}

// set the drawable region of the window

glViewport(0,0,w,h)

// set up the projection matrix

glMatrixMode(GL_PROJECTION)

glLoadIdentity()

// just use a perspective projection

//gluPerspective(45,(float)w/h,0.1,100)

if(w<=h)

{

glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w,20.0*(GLfloat)h/(GLfloat)w,0.0,100.0)

}

else

{

glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w,20.0*(GLfloat)h/(GLfloat)w,0.0,100.0)

}

// go back to modelview matrix so we can move the objects about

glMatrixMode(GL_MODELVIEW)

glLoadIdentity()

}

//------------------------------------------------------------ main()

int main(int argc,char** argv)

{

// initialise glut

glutInit(&argc,argv)

// request a depth buffer, RGBA display mode, and we want double buffering

glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE)

// set the initial window size

glutInitWindowSize(640,480)

// create the window

glutCreateWindow("Clamped B-Spline Curve")

// run our custom initialisation

OnInit()

// set the function to use to draw our scene

glutDisplayFunc(OnDraw)

<a href="http://www.jsykyy.com/" target="_blank">涂料加盟</a>

// set the function to handle changes in screen size

glutReshapeFunc(OnReshape)

glutIdleFunc(&myIdle)

// set the function to be called when we exit

atexit(OnExit)

// this function runs a while loop to keep the program running.

glutMainLoop()

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/11137823.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-13
下一篇2023-05-13

发表评论

登录后才能评论

评论列表(0条)

    保存