   Triangle Orientation
  How can I figure out if a 2D triangle is oriented clockwise or counter-clockwise if each vertex is assigned L1, L2, or L3.It''s really easy for humans to tell, but is there a formula a computer can use? 
  Do a crossproduct of vectors from L1 to L2 and L1 to L3, and find the dot product of the result with the view vector.  If it''s postive, the polygon is clockwise ordered. ;  How do you find the cross-product of a 2D vector? All the tutorials I found only explain it for 3D.What I''m really trying to find is the normal of L1->L2. However, since there are two (negatives of each other), I''m trying to find out which one points toward L3. ;  In 2D a cross product just gives you a number.  It works like so:two vectors: A = (ax, ay), B = (bx, by), |A| = magnitude of A (same for B)|A|*|B|*sin(theta) = A x B = ax*by - bx*ay(where x is the cross product symbol and theta is the angle between the vectors).  This is equivalent to finding the cross product of 3D vectors that lie in the xy plane.If you want to know if the 2D triangle is clockwise ordered (as opposed to 3D triangle rendered as I thought you meant above), find the cross product as I outlined above and note whether the result is positive or negative.  +ve = clockwise ordered.  (I think... check that and if it''s wrong, just reverse it);  What does the cross-product represent in 2D? ;  The area of (or is it half?) the parallelogram with sides parallel to the vectors. (eg. two leaving from one point, then the other ones attached to each of the ends so that they meet back up at the same point.)  This is -ve if the order of the vectors is switched.It also gives the would-have-been z component (length) of a vector normal to the 2D vectors, had they been 3D vectors that just happened to lie in the xy plane. ;  So how do I find the normal of L1->L2 that points to L3? It has to be in terms of a 2D vector.BTW, thanks for all your help. ;  OH... you want to find the closest point to L3 on the line passing through L1 and L2?  (At the closest point, the line will be perpendicular -> normal).Basically, you want a line perpendicular to the one from L1 to L2, so determine that vectorV = (x2 - x1, y2 - y1) = (xv, yv)then find a vector perpendicular to that by switching the coordinates and multiplying one (either, doesn''t matter) by -1N = (y1 - y2, x2 - x1) = (xn, yn)From this you can directly get a vector that passes through L3 and is normal to V, but you want to find the point where a line passing through L3 (x3, y3) with direction given by N meets the line passing through L1 and L2 (with direction given by V)To do this, you solve(x3 + s*xn, y3 + s*yn) = (x1 + t*xv, y1 + t*yv)x3 + s*xn = x1 + t*xvy3 + s*yn = y1 + t*yvfor s and t, which are parameters that define the lines that you''re intersecting (ie. L1 + s*N defines the line through L1 and L2 if you vary s, and L3 + t*N defines the line through L3 that''s perpendicular to the first line).from the above, you end up witht0 = -(-xn*y3+xn*y1+yn*x3-yn*x1)/(xn*yv-yn*xv)s0 = -(x3*yv-x1*yv-xv*y3+xv*y1)/(xn*yv-yn*xv)from which you can determine the point where the lines meet (P) using either ofP = L1 + s0*VP = L3 + t0*NFrom that, you can define your result vector R asR = P - t0*N  (ie. it starts at P and goes -t0*N to get to L3)I hope that was coherant... and I hope that was the best way to do this... there might be a better way.  It''s definitely simpler to find the distance separating the point and line, or just the normal, so if you don''t care where the vector starts, and just want it''s slope/normal. ;  Well, actually, I just wanted the position vector (from origin), I don''t need the position of the starting point. I knew that you had to switch the coordinates and negate one of them. My problem is, which one do you negate so that it points toward L3? ;  Use the cross product definition above to determine if they're clockwise ordered and a piece of paper to construct a few test cases.  Depending on whether the slope is +ve or -ve before the component swap, the component you negate will determine if the rotation is clockwise or counterclockwise.An alterate method would be to find the vector projecton of the L1->L3 vector onto the L1->L2 vector, and subtract the result from the L1->L2 vector.  This will give you the component of the L1->L3 vector that is perpendicular to the L1->L2 vector.   [edited by - Geoff the Medio on August 1, 2003 10:39:31 AM]