B-spline Curve in Computer Graphics Program
B-spline curve in computer graphics (using C programming) is like a flexible string that you can shape smoothly. It’s made by connecting special points, and it lets you change parts of the string without affecting the whole thing. This is super useful for making detailed 3D models, animations, and designs that look really smooth and cool.
Difference between Bezier Curve and B-spline Curve
Bezier Curve | B-spline Curve | |
Control | Defined by a set of control points, including endpoints and optional “handles” that control the tangents at the endpoints. | Defined by a set of control points, including endpoints and optional “handles” that control the tangents at the endpoints. |
Local vs Global Control | Offers global control, where modifying a control point affects the entire curve. | Provides local control, enabling modification of specific segments without affecting the entire curve. |
Smoothness | Provides less flexibility in achieving high smoothness between curves due to its limited influence on neighboring segments. | Can achieve higher smoothness by adjusting the knot vector and using higher-degree curves. |
Degree | Degree is fixed and determined by the number of control points. | Degree is variable and can be chosen independently of the number of control points. |
Interpolation vs Approximation | Primarily used for interpolation, passing through its control points. | Used for both interpolation and approximation, offering more flexibility in fitting curves to control points. |
Complexity and Precision | Simple to understand, but can lack precision and ease of modifying complex curves. | Complex to understand due to basis functions and knot vectors, but offers higher precision and adaptability. |
Editing | Editing control points may require adjustments to achieve desired changes. | Easier to edit due to local control, allowing targeted adjustments. |
Applications | Commonly used in graphic design software and fonts. | Widely used in 3D modeling, CAD, and animation due to its ability to create complex and smooth shapes. |
B-spline Curve in Computer Graphics Program in C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | //B-spline Curve in Computer Graphics #include <stdio.h> #include <graphics.h> #include<dos.h> #include<conio.h> #define MAX_POINTS 10 #define MAX_SEGMENTS (MAX_POINTS - 3) #define STEPS 100 int points[MAX_POINTS][2] = { {100, 300}, {150, 100}, {300, 50}, {400, 200}, {500, 300}, {500, 400}, {700, 500}, {800, 400}, {890, 300}, {950, 200} }; float basis(int i, int k, float t) { if (k == 1) { if (t >= points[i][0] && t < points[i + 1][0]) return 1.0; return 0.0; } float denom1 = points[i + k - 1][0] - points[i][0]; float denom2 = points[i + k][0] - points[i + 1][0]; float term1 = 0.0, term2 = 0.0; if (denom1 != 0) term1 = ((t - points[i][0]) / denom1) * basis(i, k - 1, t); if (denom2 != 0) term2 = ((points[i + k][0] - t) / denom2) * basis(i + 1, k - 1, t); return term1 + term2; } void BSplineCurve() { float t; int i, x, y; for (t = points[2][0]; t <= points[MAX_POINTS - 3][0]; t += 0.01) { x = 0; y = 0; for (i = 0; i < MAX_POINTS; i++) { float b = basis(i, 3, t); x += points[i][0] * b; y += points[i][1] * b; } putpixel(x, y, WHITE); } } int main() { int gd = DETECT, gm; initgraph(&gd, &gm,"c:\\turboc3\\bgi"); BSplineCurve(); getch(); closegraph(); return 0; } |
Output