[RESOLVED] deterimining the angle(s) of a 3D face
Does anyone know an easy or standard way of determining the angles of a 3D face? If a face is defined by three points I'm assuming it's orientation can be described by two angles, any two angles, as long as they relate to two of the three axis.
http://www.vbforums.com/attachment.p...1&d=1215649228
any guidance would be appreciated :) My maths ain't great and my current method is quite complicated.
Edit: A bit more info...
My current idea to determine the angle around the X-axis; I take the middle X vertex and work out the 2D vector which intersects the edge opposite along the YZ plane. Then use arctangent with this vector to get the angle around X. Rinse and repeat for either Y or Z.
Does this sound about right?
I aware that because I don't know (at this stage) which direction the face is facing that any answers will be between 0 and Pi.
Re: deterimining the angle(s) of a 3D face
Which angles are you after? The angles between two lines of the triangle? Or the angle one line makes with the x-axis, y-axis etc..?
You can describe the 3 points that define the triangle in Cartesian coordinates like usual (eg, P1: (x_1, y_1, z_1), P2: (x_2, y_2, z_2), P3: (x_3, y_3, z_3)) where the points are defined via their x,y and z coordinates.
But you can also use spherical coordinates, where the points are defined using the distance to the origin, the angle the line from the origin to the point makes with the positive z-axis, and the angle the line from the origin to the point makes with the positive x-axis.
http://i36.tinypic.com/2wp5v6g.jpg
You can convert between cartesian and spherical coordinates using the following relations:
http://i34.tinypic.com/23mo6l3.jpg
You might be able to work out the angle from that.
Re: deterimining the angle(s) of a 3D face
Quote:
Originally Posted by NickThissen
Which angles are you after? The angles between two lines of the triangle? Or the angle one line makes with the x-axis, y-axis etc..?
Cheers Nick,
neither I think :confused: I want a way of describing the orientation of the face, not the edges. All the same I think what you have said about relating spherical coordinates to Cartesian is just what I need. :thumb:
Re: deterimining the angle(s) of a 3D face
What do you mean by the orientation?
The three points in your picture form a plane through the origin in 3-space. You might have connected the three points so it looks like a triangle, but you can imagine extending the triangle to each side infinitely long and you got an infinitely large plane.
It would be possible to find the equation of the plane from the three points (although I will have to check how to do that), and from that equation you can also find the 'normal-vector' which is a vector perpendicular to the plane. This vector is usually used to give the orientation of a plane, you can determine the angle the plane makes with the xy-plane, yz-plane and xz-plane all via this vector alone.
Re: deterimining the angle(s) of a 3D face
Sorry my logic is quite strong but my terminology is rather weak.
Yes, the three points describe plane, but this plane does not (or at least very rarely) pass through 0,0,0. Where the three points lie in this infinite plane is also significant for what I want. Also at the stage of this calculation the direction the plane is facing is unknown. The 'triangles' represent the facets of a larger 3D object.
I've got it into my head that the best way of describing the planes orientation would be using two angles (about the X axis or from the YZ plane, and about the Z axis or from the XY plane), a unit vector describing the planes normal would be fine for me also, possibly better as I'm also manipulating the vertices with a series of 3x3 matrix transformations. Then again a unit vector has 3 elements as opposed to 2 so I think using angles will possibly be quicker to compute (less comparisons) and require less storage (I have a lot of triangles)
I think I've cracked it anyway using something derived from your first post. I don't think finding the equation of the plane is necessary. I've got an inkling of something quite simple which I'll post later when I get the chance to code it.
Thankyou :)
Re: deterimining the angle(s) of a 3D face
I'd bet that if you store angles, you'll end up having to use trig/inverse trig operations, whereas storing a normal vector would likely allow the matrix operations to happen using only multiplications. Trig operations, of course, are slow.
In this case, assuming you have one vertex of your triangle at the origin and the other two at p1=(x1, y1, z1) and p2=(x2, y2, z2), you can compute the normal vector by taking p1 cross p2, which happens to be n=(y1z2 - z1y2, z1x2 - x1z2, x1y2 - y1x2).
You can easily convert this normal vector to spherical coordinates using the formulas above to get your two angles if you so desire.
I'm a bit rusty but I know you can very easily find the equation of the plane using the normal vector n=(n1, n2, n3). It's something like...
n1*x+n2*y+n3*z = 0
for a plane passing through the origin.
If it doesn't pass through the origin... then you can find a normal by taking [p1-p3] cross [p2-p3]; that is, you effectively make an arbitrary point the origin for purposes of the orientation calculation, since the orientation is invariant through translation. If you just wanted the normal, this would definitely be the standard (and quite fast, algorithmically speaking) way of doing so.
Re: deterimining the angle(s) of a 3D face
Thanks Jemidiah, that's pretty much what I've ended up using. I'm glad I did not post the first method I derived, rather messy in comparison.
I'll probably stick with using angles as I don't think I need to do any trig with them other than deriving them in the first place, it will be more a case of If AngX < CutoffAngX.... They are so the rendering engine can quickly determine if it has to render a particular face and if so what shade to use (Gouraud shading, nothing fancy). I'll try using both and see which ends up more useful/efficient.
All the rotation is handled with 3x3 matrices as it is (I've not been able to get my head around using Quaternions)
My biggest problem with this sort of thing is my lack of mathematical terminology. I had to look up what Cartesian meant :blush: and I can't google mathematical symbols to find out what they mean.
Thankyou both.
[RESOLVED]