Sign in to follow this  
fig

Probably simple vector math

Recommended Posts

If I have 3 vertices that make up a triangle, they can be in any order as long as it's anti-clockwise. I need to find the order like in the pic.. Basically, I need the 3 vertices, in order, that make up the corner with the largest angle.. 90 degrees in the pic. If I subtract the vertices to get the direction vector of each edge.. e1=v2-v1 e2=v3-v2 e3=v1-v3 Then do a dot product of each edge with the others... a1=arcCos(e1.e2) a2=arcCos(e2.e3) a3=arcCos(e3.e1) This should give me the angles of each corner? This is where the mental block comes in. :) If it's OK so far, what now? If t's not, how can I do this? Thanks in advance

Share this post


Link to post
Share on other sites
You can just do dot(edge1, edge2), no need to take the arc cosine. In fact, that wont give you the angle if the edge length are not zero. You need to normalize the lengths before you take the arc-cosine. Regardless, you don't need to know the angle because you can use the property of the dot product. That dotting two vectors that are 90 degree's will give you zero.

That means the edges that give zero will always share the middle vert. If your guarenteed the order of the verts, you just need to find the middle vert(aka the one that dotted will give you zero).

so if dot(e1, e2) == 0, then e1 has the first vert, e2 shares the middle vert with e1 and e3 has the last vert.

Share this post


Link to post
Share on other sites
Thank you. I'll try that as soon as I can.

I knew there had to be a formula for it. :)

What if it isn't a right angled triangle? Could I use the dot product to find the largest angle?

I really should learn exactly what a dot product is. The most I've used it for is to check if 2 direction/velocity vectors or normals etc. face each other.

Share this post


Link to post
Share on other sites
fig, you can certainly use it to find the largest angle. Really, understanding the dot product is just understanding its properties. You are about to learn one of the most useful properties of the dot product so remember it!

Angle 90 then dot(a,b) = 0
Angle > 90 then dot(a,b) > 0
Angle < 90 then dot (a,b) < 0

This says that any acute angle will be positive, any obtuse angle will be negative and perpendicular vectors give you 0.

So to find the largest angle, look for the angle with the smallest number(the most negative).

Hope that helps!

- Dave

Share this post


Link to post
Share on other sites
If you're looking for the smallest dot product (as opposed to a zero one), you need to normalise the product first otherwise the lengths of the edges will affect the result and you won't always get the biggest answer.

That is, you want to find the smallest (a.b)/|a|×|b| for any two edges a and b.

Share this post


Link to post
Share on other sites
On a side note, the dot product's formula is this:


dot(u, v) = mag(u)*mag(v)*cos( theta )

...where mag() represents the vector's magnitude, and theta is the angle between them.

Remember that a normalized vector's mag()is 1.0f, so thus, with normalized vectorrs, the dot product is merely


dot(u, v) = cos( theta );

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this