pikebu 122 Report post Posted December 3, 2004 hi, i have a triangle with 3 points, e.g. P1(x1,y1,z1), P2(x2,y2,z2) and P3(x3,y3,z3). how can i get the point normal form of the plane equation: ax + by + cz + d = 0 of it? can anyone tell me how to calculate a, b, c and d? thanks for help. 0 Share this post Link to post Share on other sites
joanusdmentia 1060 Report post Posted December 3, 2004 Lets start with some ASCII art....P*| \ | \ | \ *____* QRYou can calculate the normal (a,b,c) of the plane by finding the cross-product of PQ and PR (assuming clockwise is front-facing). Then, take a vector from the origin to P (actually, any of the 3 points will do) and project it onto the normal, the length of the resulting vector is the distance to the plane from the origin (d).EDIT: My ASCII art crapped itself!! 0 Share this post Link to post Share on other sites
Airo 197 Report post Posted December 3, 2004 http://home.planet.nl/~woute890/normals.htmlthis is a short thing i once wrote. there's a nice geometry serie on flipcode. 0 Share this post Link to post Share on other sites
pikebu 122 Report post Posted December 3, 2004 what do you mean with project it onto the normal??? 0 Share this post Link to post Share on other sites
Trap 684 Report post Posted December 3, 2004 project onto means dot product. 0 Share this post Link to post Share on other sites
joanusdmentia 1060 Report post Posted December 3, 2004 No, it doesn't. When you project one vector onto another, your finding out how much of the 1st vector is in the same direction as the 2nd vector. In general, the projection of U onto V is(U.V) V----- * ----- |V| |V|When projecting onto a normal (ie. a unit vector), the length is 1 so this becomes(U.V) * VAnd again because V is a unit vector, the length of the projection is (U.V). So, the length of the projection onto a unit vector is the dot product of the two vectors. 0 Share this post Link to post Share on other sites
pikebu 122 Report post Posted December 3, 2004 k,now i'm totally confused.i have my 3 points and my normal e.g. (1,2,3)a vector from the origin to one of the 3 points is similar to one of these 3 points, isn't it? so when i have point1 with (4,5,6), point2 with (8,9,0) and point3 with (11,44,22) everyone of these points could be the vector to my triangle.and now ???:-( 0 Share this post Link to post Share on other sites
joanusdmentia 1060 Report post Posted December 3, 2004 Quote:Original post by pikebuk,now i'm totally confused.i have my 3 points and my normal e.g. (1,2,3)a vector from the origin to one of the 3 points is similar to one of these 3 points, isn't it? so when i have point1 with (4,5,6), point2 with (8,9,0) and point3 with (11,44,22) everyone of these points could be the vector to my triangle.and now ???:-(That's correct. The reason I made a point of saying 'a vector from the origin to a point' is that conceptually points and vectors are 2 different things. A vector is a direction and distance that can be positioned anywhere in space, whereas a point is a fixed position in space. Having said that, when it comes to game programming the distinction usually isn't that important. BTW, if I mention a point O below (or a vector that's something like OP) then the O is the origin.OK, to start off you want to get the normal of the triangle's plane, that is the direction it is facing. Now, the normal is perpendicular to the triangles face. If a triangle was lying flat on the ground, it's normal would point up or down (from here I'll keep refering to the direction of the normal as up). Now, you can use the cross product to calculate a vector that is perpendicular to 2 other vectors, so you need 2 vectors that lie flat on the plane. For this you can use the vectors between the triangle's points, that is you need 2 of three sides of the triangle. But, you also need to be careful about the order of the vectors as the order will determine if the normal points up or down. To get the normal to point up the vectors should be specifid in clockwise order, and to point down they should be specified in counter-clockwise order. This is the same as when you specify the front face of the triangle as being clockwise or counter-clockwise in OpenGL or Direct3D.Lets consider the triangle PQR in my previous post. Say I want clockwise to point up, I could use the vectors PQ and PR in clockwise order.P _* \ | \ | Clockwise| \ / | \ < -* * QRSo, I would find the cross of PQ and PR to get a vector that points up. Since I only care about direction, I now normalise that vector (ie. keep it's direction but make it's length 1) by dividing each element by the vectors length. So, PQ x PRplane's normal = --------- |PQ x PR|This gives you a,b and c of the plane equation as the plane's normal = (a,b,c). You now need d, the distance of the plane from the origin. To understand calculating this, imagine a triangle somewhere in space and extend it's side into infinity (ie. form a plane). Now take any point on that plane and keep sliding it around (keeping it on the plane) until you find a point where the distance from the origin to the point is at it's smallest. This is the distance from the origin to the plane. Not only this, but if you were to move in the direction of the plane's normal from the origin, this point is where you intersect with the plane. In other words, the direction in which the distance from the origin to the plane is shortest is also the normal. Since we already know the normal this makes life that much easier, since what you're now asking 'if I had any random point on the plane and made a vector from the origin to it, how much of that vector would be in the same direction as the normal?'.Now, with the triangle PQR you only know 3 points on the plane (P, Q and R) so you need to start with one of them. It doesn't matter which one, so I'll just use P. You want to know how much of the vector OP lies in the same direction as the normal. This is called projection of OP onto the normal. Since, we are projecting onto a unit vector (the normal) and only want the distance of the projection, so we can just take the dot product (as I described in my previous post).distance to plane = |OP| . normalSo to wrap things up, here's all the equations you need in one place. Given a triangle PQR, the plane the the triangle lies on isax + bx + cz + d = 0Where, PQ x PR(a,b,c) = --------- |PQ x PR|andd = |OP| . normalHope that helps!!! 0 Share this post Link to post Share on other sites
Rocket05 152 Report post Posted December 5, 2004 great ascii art joanusdmentia. rated you up just for that. 0 Share this post Link to post Share on other sites
harmless 139 Report post Posted December 6, 2004 There's a very nice article about geometric planes and how they are represented in different form.The link is here and is written by Dan Sunday.It's very concise. I hope you find answers on your questions there. 0 Share this post Link to post Share on other sites