# How do I extrude a 2D Bezier curve representation into a 3D solid using Python? Where P is the control point, w is weight.

I plan to extrude this 2d representation into 3d. I have a discrete 2D representation (array which has [n_points, 2, 1] for each sample) of an airfoil that has to be extruded to form a wing along the z axis which has parameters like Span and variation on chord length. In theory, this seems easy, however, in code, I can't find any basis on how to implement it.

I have not found anything regarding this which doesn't use high utility libraries. Any leads or explanations will be highly appreciated.

• What exactly is it that you are struggling with? Seems quite straightforward to me: Evaluate the curve at certain coordinates and connect the data points with triangles. Since I guess this is a homework question, I suggest studying the material from the course first. Telling us a bit more about what particular problems you are facing with this task will help us to guide you in the right direction. Apr 26, 2021 at 15:36
• @wychmaster I have updated the question. This is for my undergrad project. I am making a Generative Neural network architecture that outputs an extruded form of the 2d discrete representation ie a 3d model representation of the same. This is why I can't use a high utility library like blender or pygimli since they cant be part of model architecture. Apr 27, 2021 at 17:06
• Sorry, for returning so late, but I am currently very busy. If you have discrete points in 2d I am still not seeing what your exact problem is. To keep it simple, let's assume you have a rectangular wing. Your 2d coordinates are x and y. Now create two copies of those coordinates and add a z coordinate. The first profile gets z=0 and the second z=l, where l is the wingspan. Now connect the points with triangles to get a surface. I might be able to give you a full answer if this isn't enough, but it might take a while. Apr 30, 2021 at 9:15
• @wychmaster What exactly do you mean by triangles? As in triangular tesselation? Because I am trying to make a perfect boundary representation one. May 1, 2021 at 19:42
• Let's say you have two times the same airfoil with just different z coordinates. We name the first one A and the second one B. Then you can create 2*N triangles from it, where N is the number of airfoil raster points, the first two triangles would be (A, A, B) and (B, B, A). Then just add just 1 to all indices for the next ones. The last triangles would be (A[N], A, B[N]) and (B[N], B, A). (Note that I started indexing with 1 and not with 0) May 6, 2021 at 7:40

You can't create a solid by extruding a single curve or set of curves. Even if they are closed. Think about a circle on on the XY plane. If you extrude the circle along the Z axis you have an uncapped cylinder.

Let's walk it back a bit though. If you have a single Bezier curve and extrude it you create a Bezier surface. You can quickly get your head around a Bezier surface if you understand a Bezier curve.

https://en.wikipedia.org/wiki/B%C3%A9zier_surface

You can think of the Bezier surface as a blend through a set of curves. To extrude the curve you simply duplicate your original curve, and set the control points Z value to your extrusion distance. The original curve and new extruded curve create the control points for your surface.

I actually have a Bezier surface example I wrote in Python. The only dependencies are Numpy and Matplotlib. It also uses the Bernstein Basis function imported from another file in the repository. You can play with the control points to see how modifying them effects the resulting surface. There's no error checking so you'll have to know what you're doing.

https://github.com/jrz371/IntroToNurbsPython/blob/master/BezierSurface.py

As for parameterizing the span and chord length you'll have to derive those yourself. I'm unfamiliar with your requirements. Understanding the Bezier curves and surfaces thoroughly should help you resolve that.

Some of the comment suggest evaluating the curve and creating triangles. This is a bad approach. Tessellating a Bezier surface causes you to lose a lot of information. The Bezier surface is smooth whereas a set of triangles is not. For drawing a Bezier surface they are ultimately tessellated for the display, but they are kept in the original Bezier representation for modification.

Bezier curves are also not the best representation for curves and surfaces. BSplines and NURBS are able to represent more complex surfaces and curves. Understanding Beziers is fundamental prerequisite before tackling those.

Good luck!