   Generate a circle in a plane when you have the normal
  Hi.I have a pretty simple scenario but my math skills just aren't good enough it seems...Basically I have a plane defined by a point P and a normal to the plane N. I need to be able to generate a circle of a certain radius in this plane.So basically I sort of want to deduce a new coordinate system where N becomes the up-vector (Y-axis in my case). But I don't know how to get the X and Z axis vectors.Preferrably I would want to do this just using a rotation matrix or a quaternion and transform the original X and Z axis vectors.The reason as to why I need to do this is really not important but I can elaborate on that if someone considering helping me asks. Any help would be greatly appreciated.   
  I think what you do is something like this :-Find the largest abs element of N.Say N = (-0.2,-0.6,0.3), the largest is abs(-0.6)So we need another vector in either X or Z, so pick one. Lets use X = (1,0,0)float d = -Dot(X, N);X = X + (d * N);X.Normalize();Cross those, Z = X x NMake sure they are all normalized.Now you have 3 vectors, X, N and Z. Depending on how your matrix class works set either the rows or the columns to these.   ;  The equation of a plane is, in R³:a*x + b*y + c*z + d = 0orif we define N = ( a, b, c ) and P = ( x, y, z ),dot( N, P ) + d = 0N is the normal of the plane and P a point of the plane. a, b, c and d are known.To attach a basis to the plane, you'll need two unit vectors perpendicular to the normal, that is to say two vectors V1 and V2, that verify these equations:dot( V1, N ) = 0dot( V2, N ) = 0N = cross( V1, V2 )length( V1 ) = 1.0length( V2 ) = 1.0The first equation gives, if we define V1 = ( x1, y1, z1 )a * x1 + b * y1 + c * z1 = 0We have three unknowns. We can arbitrarily choose values for x1 and y1, then compute z1. Let's call those values x1', y1'. Then z1' equals to:z1' = -( a * x1' + b * y1' ) / c ( c != 0 )=> Vs = ( x1', y1', -( a * x1' + b * y1' ) / c ) ( c != 0 )V1 must be a unit vector. So you normalize the vector found:V1 = unit_vector( Vs )V2 is found by:V2 = cross( N, V1 )( V1, V2, N ) form a right handed coordinate system.[Edited by - johnstanp on May 14, 2010 10:26:43 AM];  Thank you. That seems like it could work. The only problem being if the normal (a, b, c) has c = 0. But in that case I can of course use either a or b (since at least one won't be zero).I actually thought of that method before but I didn't think of assigning arbitrary values to x1 and y1. But that's of course perfectly okay since the plane is infinite.Thanks, will try this and edit this post with result.EDIT:There are some numerical issues at certain points (not sure what, but the image flimmers, sort of). But other than that it works great. Thanks.[Edited by - UmaN on May 14, 2010 1:45:24 PM];Quote:There are some numerical issues at certain points (not sure what, but the image flimmers, sort of). But other than that it works great. Thanks.It should be possible to do this without introducing any numerical issues or other similar problems. If you're seeing rendering artifacts, then there's probably a problem with your implementation somewhere.This repeats (at least in part) what's already been said, but here's how you can generate a basis for the circle:1. Cross the plane normal with the cardinal basis vector corresponding to the element of the normal with the least magnitude.2. Normalize the result to yield the first basis vector.3. Cross the normal with this vector to yield the second basis vector.   