PDA

View Full Version : convert four interconnected bezier curves into bezier surface patch

pat1il
07-06-2015, 09:24 PM
I have four 3d cubic bezier curves that are interconnected. One bezier curve interconnects with the next one, and finally the last one interconnects with the first. However it does not conform to a standard bezier patch.

I have the control points for the curves but they are not set up properly? for a bezier patch. Does anyone know how I can convert these four interconnected bezier curves into a standard format for a bezier patch?

I have tried a lot of ideas but cannot seem to get it right. Any sample code would be greatly appreciated, since my math skills are limited.

GClements
07-06-2015, 09:36 PM
Does anyone know how I can convert these four interconnected bezier curves into a standard format for a bezier patch?

Four Bézier curves connected at their endpoints gives you 12 control points. A patch needs 16, so you need four more, one for each corner.

Probably the best way to generate these is to choose the extra point so that the four points form a planar parallelogram. So if the corner point is P and the adjacent tangent points are U and V, the interior control point C is
C = P + (U - P) + (V - P) = U + V - P

The reason for this is that if you have a rectangular grid of patches, where each corner point is the midpoint of the adjacent tangent points in each direction, choosing the remaining point like this ensures C1 continuity across the edges.

pat1il
07-07-2015, 04:43 PM
I am having trouble understanding. Can you help me one more time.

I have:

EP0, CP0, CP1, EP1 First curve with two end points and two control points.
EP1, CP2, CP3, EP2 Next curve with shared end point from first curve.
EP2, CP4, CP5, EP3 etc.
EP3, CP6, CP7, EP0

If I understand you correctly, I can calculate another control point by CP8 = (CP0+CP7 - EP0) and similarily for the other three (CP9,CP10,CP11). However I need to rearrange my 4x4 matrix somehow to reflect these new control points and am not sure how the resulting matrix should look.

Could you please verify that I understand your proposal properly and how I should rearrange my 4x4 matrix.
Thanks.
Pat

GClements
07-07-2015, 05:00 PM
I have:

EP0, CP0, CP1, EP1 First curve with two end points and two control points.
EP1, CP2, CP3, EP2 Next curve with shared end point from first curve.
EP2, CP4, CP5, EP3 etc.
EP3, CP6, CP7, EP0

If I understand you correctly, I can calculate another control point by CP8 = (CP0+CP7 - EP0) and similarily for the other three (CP9,CP10,CP11).
Yes.

However I need to rearrange my 4x4 matrix somehow to reflect these new control points and am not sure how the resulting matrix should look.

EP0 CP0 CP1 EP1
CP7 IP0 IP1 CP2
CP6 IP3 IP2 CP3
EP3 CP5 CP4 EP2

Where
IP0 = CP0 + CP7 - EP0
IP1 = CP1 + CP2 - EP1
IP2 = CP3 + CP4 - EP2
IP3 = CP5 + CP6 - EP3

IOW, the four curves form the boundary of the array, while the extra points fill in the centre cells.

Also, you may find that you need to transpose or flip the above array depending upon which side of the patch is supposed to be the "front" and which is the "back". Rotation (i.e. which endpoint goes in the top-left corner) doesn't matter.

pat1il
07-07-2015, 05:13 PM
Am I correct to assume that the matrix should look like this:

EP0, CP0, CP1, EP1
CP2, IP0, IP1, CP3
CP4, IP2, IP3, CP5
EP2 CP6, CP7, EP3

???

GClements
07-07-2015, 08:55 PM
Am I correct to assume that the matrix should look like this:
No. See the part of my previous post that's formatted as "code".

The four curves should form the four edges of the "matrix". I assume that you're referring to the order in which glMap2() wants the data; if you're using a tessellation shader, you can store the points however you want, but the operations naturally operate on rows and columns if you lay them out as I described.

In your reply, the left-hand edge is "EP0 CP2 CP4 EP2", but that isn't one of your curves. Similarly for the right-hand and bottom edges; only the top edge is correct.

pat1il
07-08-2015, 08:33 AM
Thank you so much. You have been a great help. My surfaces from bezier curves look correct.
Thanks again.