   angles between vectors
  Hi,I have a problem for determining if an angle between 2 vector3 in 3D goes clockwise or counter clockwise.In fact the problem is :- I have a 3D object (sphere, face,...- I determine a surface on this 3D object (i choose at least 3 points and rejoint all the consecutive points and the last point choosen is relied to the first one)- then i search to determine all the points which lie in this area.So i am trying a technique that work in 2D (but not sure of what it will do here because it's in 3D).For exemple if i have 5 points that determine the surface (A B C D E in this order).For each points of the 3D object (if X is the current point tested), i test the angle made by the vectors AX and BX then by the vectors BX and CX then by the vectors CX and DX then by the vectors DX and EX then by the vectors EX and AX then by the vectorsAnd if all the angle are clockwise or counter clockwise, the point is in the area otherwise (some clockwise, some counterclockwise) no.But the problem is that i can't determine if the angle is clockwise or counterclockwise using : dot_product(AX, BX) = Norm(AX) * Norm(BX) * cos(theta)-> theta = acos(dot_product(AX, BX)/(Norm(AX) * Norm(BX)))Do you have an idea of how determine this?Or a better idea to find if a point is in the area determined by the points choosen (if it can help, point choosen are linked by the intersection on the 3D surface with a plan (and i know the equation of the plan)).thanks in advance for your help   
  Assuming all points A...E are coplanar, the easiest way to do it in 3D is to take the dot product of the vector from A to X with the vector from A to B, and find the angle between them (never mind clockwise or what for now)Take the angle and store it for later. Do the same for vector B->X and B->C, and add the angle between them to the first angle. Repeat for C->X and C->D, ..., all the way through E->X and E->ACheck the sum of the angles, it should be 2.0*pi if the point is interior the ABCDE polygon.I might have left out something, if it still doesn't work the friendly neighborhood [google] might pick up the pieces.   ;  Thanks for your answer but, the problem is that it's not coplanar, it's a kind of 2D surface on a 3D model so it's harder to determine.Here is an exemple of what i want : http://photobucket.com/albums/y36/ioda100/?action=view&current=sphere_surface.jpgHere it's a sphere (but it can be everything and i have choosen 5 points on the sphere. The points are linked by a sort of geodesic (cut of the sphere by a plan between the 2 points).Now i am searching all the points lying in the surface. So it's not in 2D. And the 3D object can be much more "chaotic".   ;  another exemple of a 3D object and the area that i am searching : http://photobucket.com/albums/y36/ioda100/?action=view&current=dragoon_surface.jpghere it's small object to make an idea but the object can be made of 500 000 points and even more   ;  My gut feeling is that the way to do it is to check every triangle defined by the surface (since tris are by definition coplanar) using the above described method.My reasoning is that if you have some irregular shape or surface you lose the ability to use straight linear transformations, and you would need to solve some equations which describe the surface(because it is not a plane), like a bezier or spline or such.If this is unreasonable(performance, or whatever) you could maybe use a heuristic that chose each combination of 3 of the surface-defining points and projected point X into that plane(and then checking the interior conditions) YMMV.   ;  ok thx for your answeri am not sur of how to make it work but i will try and post   ;Quote:Original post by iodaI have a problem for determining if an angle between 2 vector3 in 3D goes clockwise or counter clockwise.I'm not sure, but I think what you need is the cross product.  Cross product of two vectors in R3 is defined byV1 = (x1, y1, z1)V2 = (x2, y2, z2)crossprod(V1, V2) = V1 x V2 = (y1*z2 - y2*z1, z1*x2 - z2*x1, x1*y2 - x2*y1)If V1 and V2 lie in the x-y plane,x1*y2 - x2*y1 = |V1||V2|sin(theta)(and similarly for the y-z or x-z planes)If the vectors lie in one of those planes, then since sin(theta) can go positive or negative with theta, you can distinguish between clockwise or counterclockwise oriented vectors, or positive or negative angles between vectors.  (You do, however, lose the ability to distinguish between angles greater or less than 90 degrees between the vectors, since sin repeats itself with bigger angles, unlike cos)Do you need to know if the vectors are clockwise or counter-clockwise as seen from by the viewer, or relative to the normal of the surface they are on?If as seen by the viewer, find the projection of the two vectors on the plane of the viewport, and calculate the cross product of those two projected vectors.  The cross product of two vectors lying in the x-y plane will be entirely in the z-direction, so you can just calculate the one component and check if it is positive or negative.If the vectors don't lie in a nice plane, you can use the full 3D result, the magnitude of which gives the area of the parallelogram with sides of lengths and orientations given by the two vectors, and the direction of which gives the orientation of the normal of the surface, as defined by the right-hand-rule: if thumb is V1, and index/pointer finger is V2, then middle finger is direction of V3.So if you need the orientation relative to the surface of the sphere, then calculate the cross product of the two vectors, then find its dot product with the normal to the surface at the where the vectors meet.  Alternatively, if you need the orientation relative to the viewport, calculate the cross product of the two vectors in full 3D, and then find its dot product with the view vector.   ;  thanks for this well explained methodi will try and tell if it worksbut the more i advance the more i figure it's not the best way to determine which points are on the surface delimited by the choosen points   ;  Assuming you've got these points all oriented clockwise or counterclockwise, and your surface is fairly smooth (eg you're actually going to be working with sphere), it's probably a workable method.You'll need to be sure that the enclosing points are on the same side of the sphere as the enclosed point though... as if you just checked that all the sequential pairs of vectors make angles that are always positive / negative, then you wouldn't be able to distinguish between a point in the middle of the enclosing points, and one which is on the other side of the sphere from an enclosed point; all sequential pairs of vectors would still have all positive or all negative angles.So I guess you should make sure the vectors from the centre of the sphere to the enclosing points are all within 90 degrees of the vector from the centre to the enclosed point.  Or you should make sure you've got your enclosing points oriented counter-clockwise, so that subsequent pairs of vectors have cross products that are oriented outwards, and that the dot product of these cross products with the normal vector is always positive, never negative.   ;  Hrm... it looks like you're not going to be using a sphere...  and you're not even using a convex polyhedron... so you're going to have some problems generalizing this... especially depending how you generate your set of points to check.Using the vectors / dot products / etc. method won't really work in general, since you could have an enclosed region with whatever weird random 3D shaped surface inside it... the particular normals at any point inside are arbitrary.I think you might need to do a complicated surface tracing algorithm, where you have your circle of points, then incrementally move the surface by testing adjacent triangles to the border, then if the point isn't in each triangle, moving the border to exclude that triangle and proceeding again until you've shrunk the enclosed area down enough to get to the point... or run out of triangles to check and thus determined the point isn't in the enclosed region.  I've never done this though, so there's probably a better method, depending what specific assumptions you can make about your surface and the nature of the enclosed region.   