## cgkit-user

 [cgkit-user] Bezier Curves From: Paul Wellner Bou - 2010-02-02 13:29:08 ```Hello, I am trying to compute 3-dimensional cubic bezier curves out of parameters I have yet (so no interpolation needed). Is this possible with the BezierCurve object in any way? And, if I have the point to interpolate can I say that the curve should be cubic and C2 continues instead of predefining the tangents in every point? Thanks and regards Paul. ```
 Re: [cgkit-user] Bezier Curves From: Matthias Baas - 2010-02-02 22:22:18 ```Hi Paul, Paul Wellner Bou wrote: > I am trying to compute 3-dimensional cubic bezier curves out of > parameters I have yet (so no interpolation needed). Is this possible > with the BezierCurve object in any way? Well, the BezierCurve object represents a set of cubic bezier curves and the control points are defined in 3D. So it seems it fulfills your requirements. (I'm not sure if this really answers your question though...) > And, if I have the point to interpolate can I say that the curve should > be cubic and C2 continues instead of predefining the tangents in every > point? So far, there's no functionality to initialize the curve just from a set of points to be interpolated, so unfortunately, you have to compute appropriate tangents yourself. Cheers, - Matthias - ```
 Re: [cgkit-user] Bezier Curves From: Paul Wellner Bou - 2010-02-03 09:45:06 ```Hi Matthias, thanks for the reply. Actually, I have the four points of the bezier curve I want to draw. After playing a bit more with the BezierCurve I found out that the BezierPoints are not supposed to be any points within the bezier curve but the points where one bezier curve ends and the next one starts. As I have the four points I should be able to draw the complete bezier curve, using the first point and the last point as BezierPoints and the differences between the second and the first, and the last and the third as tangents, right? Should work. Tried it, but the visualisation is not how I expected it, but this may be due to my data. Regards Paul. ```
 Re: [cgkit-user] Bezier Curves From: Matthias Baas - 2010-02-03 21:18:38 ```Hi Paul, Paul Wellner Bou wrote: > Actually, I have the four points of the bezier curve I want to draw. > After playing a bit more with the BezierCurve I found out that the > BezierPoints are not supposed to be any points within the bezier curve > but the points where one bezier curve ends and the next one starts. > > As I have the four points I should be able to draw the complete bezier > curve, using the first point and the last point as BezierPoints and the > differences between the second and the first, and the last and the third > as tangents, right? Yes, that's exactly how it works. If you have two consecutive BezierPoints p1 and p2, then the Bezier curve connecting those points is defined by the four control points p1, p1+outTangent1, p2+inTangent2, p2. > Should work. Tried it, but the visualisation is not how I expected it, > but this may be due to my data. Hm, can you send an example? - Matthias - ```
 Re: [cgkit-user] Bezier Curves From: Paul Wellner Bou - 2010-02-05 15:40:54 ```Hi Matthias, >> Should work. Tried it, but the visualisation is not how I expected it, >> but this may be due to my data. > > Hm, can you send an example? Yes, of course I can. I am trying to visualize a bezier curve with following control points: from cgkit.all import * ap = [[4226765.0, -8321830.0, 15489144.0], [4226764.0, -8321840.0, 15497220.0], [4226762.0, -8321840.0, 15504724.0], [4226761.0, -8321859.0, 15511768.0]] outTangent1 = [ap[1][0]-ap[0][0],ap[1][1]-ap[0][1], ap[1][2]-ap[0][2]] inTangent2 = [ap[2][0]-ap[3][0], ap[2][1]-ap[3][1], ap[2][2]-ap[3][2]] pnts = [BezierPoint(ap[0], vec3(0), outTangent1), BezierPoint(ap[3], inTangent2, vec3(0))] crv = BezierCurve("MyCurve", pnts, False, 0.01, 8, True) I can not increase the subdivisions, 8 is the maximum. If I use more, it hangs with 100% cpu load and never finishes. The visualization I get looks like this: http://purecodes.org/math/beziers/cgkit_opengl_bezier_ints.png Where I expected something like: http://purecodes.org/math/beziers/matplotlib_bezier.png (Latter graph was produced by matplotlib with a bezier drawing implementation I did on my own, by calculating equally spaced subdivisions. Don't consider the scale of the axes, this seems to be something special by the 3d support of matplotlib) It just came to my mind that may be this is due to the axis scaling. I will try further to adjust this in matplotlib or/and with cgkit. Is there a way to include a coordinate system/grid in the cgkit 3d scene? Regards Paul. ```
 Re: [cgkit-user] Bezier Curves From: Matthias Baas - 2010-02-06 11:34:41 ```Hi Paul, >>> Should work. Tried it, but the visualisation is not how I expected it, >>> but this may be due to my data. >> Hm, can you send an example? > > Yes, of course I can. I am trying to visualize a bezier curve with > following control points: > > from cgkit.all import * > > ap = [[4226765.0, -8321830.0, 15489144.0], > [4226764.0, -8321840.0, 15497220.0], > [4226762.0, -8321840.0, 15504724.0], > [4226761.0, -8321859.0, 15511768.0]] Look at the ranges of your coordinates. This curve is pretty much a straight line which is what you get in the viewer tool. As you have already noticed yourself, in matplotlib you only see some variation because it uses different scales for the three axes, so what you see is kind of a "distorted" view of the curve. In the viewer tool, the scale of all 3 axes is always the same, so the variation in x and y is not noticeable (unless you zoom in very closely in which case you might get all sorts of other problems). By the way, if at all possible, I would also recommend shifting the curve so that the values are somewhat centered around the origin. I'd say with such large magnitudes and small variations you might run into numerical problems sooner or later. > I can not increase the subdivisions, 8 is the maximum. If I use more, it > hangs with 100% cpu load and never finishes. What values did you use? It will finish eventually, but it's just that the more subdivision steps you ask for, the more time it takes to compute the curve (and the Bezier curve is still pure Python, so it's not particularly fast). The total number of subdivision steps will be (2**subdiv)-1. > It just came to my mind that may be this is due to the axis scaling. I > will try further to adjust this in matplotlib or/and with cgkit. Is > there a way to include a coordinate system/grid in the cgkit 3d scene? Not yet, unfortunately. As a workaround, you could use drawLine() or drawMarker() to add some guides to your scene. Cheers, - Matthias - ```