资源简介
本项目为vs2013工程项目,贝塞尔曲线计算,控制点可以多个,支持二维数据,三维数据,使用c++语言编写,直接打开即可运行。
代码片段和文件信息
#include “BezierCurve.h“
namespace CBezierCurve{
// function to calculate the factorial
float Factrl(int n)
{
static int ntop = 6;
static float a[33] = { 1.0 1.0 2.0 6.0 24.0 120.0 720.0 }; /* fill in the first few values */
int j1;
if (n < 0) printf(“\nNegative factorial in routine FACTRL\n“);
if (n > 32) printf(“\nFactorial value too large in routine FACTRL\n“);
while (ntop < n) { /* use the precalulated value for n = 0....6 */
j1 = ntop++;
a[n] = a[j1] * ntop;
}
return a[n]; /* returns the value n! as a floating point number */
}
// function to calculate the factorial function for Bernstein basis
float Ni(int n int i)
{
float ni;
ni = Factrl(n) / (Factrl(i)*Factrl(n - i));
return ni;
}
// function to calculate the Bernstein basis
float Basis(int n int i float t)
{
float basis;
float ti; /* this is t^i */
float tni; /* this is (1 - t)^i */
/* handle the special cases to avoid domain problem with pow */
if (t == 0. && i == 0)
ti = 1.0;
else
ti = pow(t i);
if (n == i && t == 1.)
tni = 1.0;
else
tni = pow((1 - t) (n - i));
basis = Ni(n i)*ti*tni; /* calculate Bernstein basis function */
return basis;
}
// Bezier curve subroutine
int Bezier(SPoint *sPoint int inPointNum SPoint *sOutPoint int outPointNum)
{
float step;
float t;
/* calculate the points on the Bezier curve */
t = 0;
step = 1.0f / ((float)(outPointNum - 1));
for (int i1 = 0; i1 < outPointNum; i1++) /* main loop */
{
if ((1.0 - t) < 5e-6)
{
t = 1.0;
}
sOutPoint[i1].x = 0.0;
sOutPoint[i1].y = 0.0;
sOutPoint[i1].z = 0.0;
for (int posi = 0; posi < inPointNum; posi++) /* Do xyz components */
{
sOutPoint[i1].x = sOutPoint[i1].x + Basis(inPointNum - 1 posi t)*sPoint[posi].x;
sOutPoint[i1].y = sOutPoint[i1].y + Basis(inPointNum - 1 posi t)*sPoint[posi].y;
sOutPoint[i1].z = sOutPoint[i1].z + Basis(inPointNum - 1 posi t)*sPoint[posi].z;
}
t = t + step;
}
return 0;
}
};
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2121 2017-04-29 14:15 BezierCurve\BezierCurve\BezierCurve.cpp
文件 1413 2017-04-29 14:15 BezierCurve\BezierCurve\BezierCurve.h
文件 4207 2017-04-29 14:13 BezierCurve\BezierCurve\BezierCurve.vcxproj
文件 1164 2017-04-29 14:13 BezierCurve\BezierCurve\BezierCurve.vcxproj.filters
文件 1124 2017-05-02 08:45 BezierCurve\BezierCurve\main.cpp
文件 2097152 2018-05-18 16:10 BezierCurve\BezierCurve.sdf
文件 979 2017-04-28 22:59 BezierCurve\BezierCurve.sln
..A..H. 25088 2018-05-18 16:10 BezierCurve\BezierCurve.v12.suo
目录 0 2017-11-07 10:58 BezierCurve\BezierCurve
目录 0 2018-05-18 16:10 BezierCurve
----------- --------- ---------- ----- ----
2133248 10
- 上一篇:C语言写矩阵库,适合做矩阵运算
- 下一篇:FIR的DSP实现C语言实现
相关资源
- 计算机图形学教程第二版实验生成“
- Curvelet最新工具包2.1.2
- de Casteljau算法绘制Bezier曲线
- opengl实现双三次Bezier曲面
- C语言实现生成贝塞尔曲线(代码)
- C++实战源码-绘制贝塞尔曲线
- 四次Bezier曲线动态生成 VC++代码实现
- CurveLab----Curvelet变换的c++和matlab代码
- Bezier曲线,三次B样条曲线
- MFC bezier曲线
- 用C++和openGL实现贝塞尔曲线的生成
- 基于OpenGl的Bezier曲面的简洁实现
- 大地测量贝塞尔问题的解算
- 绘制bezier曲线
- B样条和贝塞尔曲线的画法
- 在MFC单文档中绘制平面bezier曲线、三
- CurveLab-2.1.3
评论
共有 条评论