本代码根据已知控制点( 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 ),( 10, 5, 0 )来生成三次B样条曲线。
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;
struct Point
{
float c[2];
float& x = c[0];
float& y = c[1];
Point() {
x = 0, y = 0; }
Point(float x0, float y0) {
x = x0, y = y0; }
Point(const Point& pt) {
x = pt.x, y = pt.y; }
float& operator[](const int i) {
return c[i]; }
};
vector<Point> GctrlPt, GbsCurvePt;
int GnumSegment = 10;
void CalcBSPoints()
{
int numCtrPt = GctrlPt.size();
float F0[2], F1[2], F2[2], F3[2];
float t = 0;
float dt = 1 / (float)GnumSegment;
//第一段NumSubSegment + 1个点,第二段之后每段为NumSubSegment个点,因为第二段之后的起点为前一段的终点
int numCurvePoint = (GnumSegment + 1) + GnumSegment * (numCtrPt - 4

本文展示了如何使用控制点(10,5,0), (5,10,0), (-5,15,0), ... 和 (10,5,0) 生成三次B样条曲线,并通过代码实例讲解了计算和绘制过程。
最低0.47元/天 解锁文章
1227

被折叠的 条评论
为什么被折叠?



