当前位置:网站首页>Expérience 10 génération de courbes bezier - amélioration expérimentale - génération de courbes B - spline par point de contrôle
Expérience 10 génération de courbes bezier - amélioration expérimentale - génération de courbes B - spline par point de contrôle
2022-06-11 21:26:00 【Espace graphique】
Ce code est basé sur les points de contrôle connus( 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 )Pour générer trois foisBSpline.
#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;
//Premier paragrapheNumSubSegment + 1Un point, Après le deuxième paragraphe, chaque paragraphe est libellé comme suit: NumSubSegmentUn point, Parce que le point de départ après le deuxième paragraphe est la fin du paragraphe précédent
int numCurvePoint = (GnumSegment + 1) + GnumSegment * (numCtrPt - 4);
GbsCurvePt.resize(numCurvePoint);
// Le premier paragraphe commence par 0, Après le deuxième paragraphe, lire: 1, Voir ci - dessus pour les raisons
for (int i = 0; i < (numCtrPt - 3); i++)
{
for (int j = 0; j < 2; j++)
{
F0[j] = (GctrlPt[i][j] + 4 * GctrlPt[1 + i][j] + GctrlPt[2 + i][j]) / 6.0f;
F1[j] = (-3 * GctrlPt[i][j] + 3 * GctrlPt[2 + i][j]) / 6.0f;
F2[j] = (3 * GctrlPt[i][j] - 6 * GctrlPt[1 + i][j] + 3 * GctrlPt[2 + i][j]) / 6.0f;
F3[j] = (-GctrlPt[i][j] + 3 * GctrlPt[1 + i][j] - 3 * GctrlPt[2 + i][j] + GctrlPt[3 + i][j]) / 6.0f;
}
t = (i == 0) ? 0 : dt;// Le paramètre de départ du premier segment est 0, Après le deuxième paragraphe, lire: dt,Pour les mêmes raisons
for (int j = (i == 0) ? 0 : 1; j < GnumSegment + 1; j++)
{
for (int k = 0; k < 2; k++)
{
GbsCurvePt[j + GnumSegment * i][k] = F0[k] + F1[k] * t + F2[k] * t*t + F3[k] * t*t*t;
}
t += dt;
}
}
}
void ControlPoint(const vector<Point>& vpt)
{
glPointSize(3);
glBegin(GL_POINTS);
for (unsigned int i = 0; i < vpt.size(); i++)
{
glVertex2f(vpt[i].x, vpt[i].y);
}
glEnd();
}
void PolylineGL(const vector<Point>& vpt)
{
glBegin(GL_LINE_STRIP);
for (unsigned int i = 0; i < vpt.size(); i++)
{
glVertex2f(vpt[i].x, vpt[i].y);
}
glEnd();
}
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
ControlPoint(GctrlPt);
glColor3f(0.0f, 1.0f, 0.0f);
PolylineGL(GctrlPt);
if (GctrlPt.size() >= 4)
{
glColor3f(1.0f, 1.0f, 1.0f);
CalcBSPoints();
PolylineGL(GbsCurvePt);
}
glFlush();
}
void Init()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
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 } };
Point pt;
for (int i = 0; i < 9; i++)
{
Point pt = Point(points[i][0], points[i][1]);
GctrlPt.push_back(pt);
}
}
void myReshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-30.0, 30.0, -30.0*(GLfloat)h / (GLfloat)w, 30.0*(GLfloat)h / (GLfloat)w, 0.0, 100.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(640, 480);
glutCreateWindow("B-Spline Curve");
Init();
glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutMainLoop();
return 0;
}
边栏推荐
- Cs144 lab0 lab1 record
- apache 本地多端口配置
- String copy function
- Diary at 16:29:41 on June 9, 2022
- Jenkins+allure integrated report construction
- Why microservices are needed
- As a senior abap consultant, which SAP technology can be selected as the main direction in the next step?
- JVM|类加载器;双亲委派机制
- 关于斜率优化
- Realize the same length of tablayout subscript and text, and change the selected font size
猜你喜欢

Jenkins+allure integrated report construction

LeetCode-98-验证二叉搜索树
![BZOJ3189 : [Coci2011] Slika](/img/46/c3aa54b7b3e7dfba75a7413dfd5b68.png)
BZOJ3189 : [Coci2011] Slika

Live broadcast with practice | 30 minutes to build WordPress website with Alibaba cloud container service and container network file system

Online excel file parsing and conversion to JSON format

Deriving Kalman filter from probability theory

Online excel file parsing and conversion to JSON format

Part II data link layer

SQL的语法

How to Load Data from CSV (Data Preparation Part)
随机推荐
Network security Kali penetration learning introduction to web penetration using MSF penetration to attack win7 host and execute commands remotely
How to Load Data from CSV (Data Preparation Part)
作为一名 ABAP 资深顾问,下一步可以选择哪一门 SAP 技术作为主攻方向?
LeetCode-76-最小覆盖子串
实现 TabLayout 下标与文字等长,选中字体大小改变
Deriving Kalman filter from probability theory
Chain storage structure of linear table
LabVIEW Arduino电子称重系统(项目篇—1)
js对返回的数据的各种数据类型进行非空判断。
BUG -- coredump使用
关于gorm的preload方法笔记说明
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
【C语言进阶】整型在内存中的存储
ASCII码对照表
Go语言条件语句
Redis data type (string)
俩月没发过博客了,发一篇证明自己的账号还活着
Bug -- coredump usage
Codeforces Round #744 (Div. 3) 解题报告
【生活思考】文字与语音