If we take out the origin - which is more convenient, more about that later - you need at least one vector that lies in the circle’s plane (ie it’s perpendicular to the normal)
So, you have two vectors, N (the normal) and P1 (perpendicular to the normal). Now you can do a cross-product to get a vector that is perpendicular to both of them.
P2 = N x P1
Normalize P1 and P2. You can now start to generate points (vertices!) along the circle. The same output can also be used as surface normals for your cylinder.
Some pseudo code might look like this:
const float pi=3.14blabla;
const int circle_vertices=100; //choose what you want
for (int step=0;step<circle_vertices;++step)
There you are
These vertices are all centered around (0;0;0) so you can translate, rotate and scale them as you please. You should also be able to quite easily extrude the cylinder.
The remaining problem is to find perp1.
I suggest something like this
Note that this may still fail due to insufficient precision of your floating point format. Things like (float==0.0f) are extremely rare to go right on limited precision. You should try to measure if the difference falls below a small threshold instead, this is just for brevity
Thanks to Furrage for pointing out some stupid mistakes
[This message has been edited by zeckensack (edited 03-07-2002).]