# Bezier Patches

I am programming a bezier patch program. There’s no real point to it, more a proof of concept than anything else, but a problem keeps cropping up. At the far end of the quad strip, a fan of triangles keeps appearing. The code for the patch in its totality is below, please excuse the formatting errors due to autowrap:

struct Vector
{
float x, y, z;
};

Vector point (Vector a, Vector b, Vector c, float u)
{
Vector temp;

``````if (u &gt; 1 | | u &lt; 0) return Vector(       0.0f, 0.0f, 0.0f);

temp.x = (a.x * powf(u, 2)) + (2*b.x * u) - (2*b.x * powf(u, 2)) + c.x - (2*c.x * u) + (c.x * powf(u, 2));

temp.y = (a.y * powf(u, 2)) + (2*b.y * u) - (2*b.y * powf(u, 2)) + c.y - (2*c.y * u) + (c.y * powf(u, 2));

temp.z = (a.z * powf(u, 2)) + (2*b.z * u) - (2*b.z * powf(u, 2)) + c.z - (2*c.z * u) + (c.z * powf(u, 2));

return temp;
``````

}

void Bezier(BPatch patch, int divs)
{
int v, t;
float u, x;

``````Vector		temp;

Vector *last;	//, *curr;
last = new Vector[divs+1];

for (v=0; v &lt;= divs;v++)
{
u = ((float)v)/((float)divs);
``````

temp = point (patch.anchors, patch.anchors, patch.anchors, u);

temp = point (patch.anchors, patch.anchors, patch.anchors, u);

temp = point (patch.anchors, patch.anchors, patch.anchors, u);

``````	for (t=0; t &lt;= divs;t++)
{
x = ((float)t)/(float)divs);					glVertex3d(last[t].x, last[t].y, last[t].z);	// Old Point

last[t] = point (temp, temp, temp, x);

glVertex3d(last[t].x, last[t].y, last[t].z);	// New Point
}
``````

glEnd(); // END the triangle srip

}

If you’ve slogged through the code, can you see the problem? Because I’ve been looking at this for a bit now and find myself at a complete loss as to what the problem is. Thanks for reading.

Actually, never mind. I discovered the bug, and it now works beautifully. Sorry to add that much more clutter to the forum. 