Finding Angle between Vertices

Hi,

I want to find the angle between three vertices (they may have different x, y, z value). However, I don’t know how to find it efficiently. Now, I only have the idea to find the length of three lines between each vertice first. Then, I use cosine law to find the angle using the lenght of three lines.

Is there any efficient method to find the angle between three vertices?

Suppose you have vertices A, B and C and you want to measure the angle between the lines AB and BC. First, subtract B from both A and C so that you have vectors from B to the other two points…now normalize vector A and vector C (ie divide the three component of the vector by its length)…next you can compute the “dot product” of those two normalized vectors:

dot = Ax * Cx + Ay * Cy + Az * Cz

…the dot product is now the cosine of the angle between the two vectors - so taking the arc-cosine (acos) of the dot product gives you that angle…in radians. Don’t forget to convert it to degrees if that’s what you need!

Yes. It is very useful.

Now, I still have one problem. I also need to implement one more thing. When I input the angle, the vertices will automatically change to form the new angle. Since I have three vertices, I want to change one of the vertices (i.e. angle ABC, only change vertice A).

However, I have difficulties on calculating the vertices because the x, y coordinates change together (assume z coordinate is fixed) and I still cannot solve this equation. Is there any method like dot product and normalization to find the new vertices?

So you have a fixed line BC and you want to create a new line BA that’s at a particular angle to BC?

Yes.

Well, I guess I’d figure out the angle between the line BC and (say) the X axis using ‘atan2’ with the vector (C-B). Now you can figure out at what angle the line BA needs to be relative to the X axis in order yield the correct angle with BC - and use sin() and cos() to get the X and Y components of that vector - then add B to the results to translate it out to the right position in space…there may be easier ways - but that’ll work. Mostly though, this wouldn’t come up because I’d just use my matrix algebra software to translate BC to the origin, rotate it by the appropriate

This forum is really a bad place to be asking these kinds of questions. We’re not here to provide remedial math support - but to discuss WebGL.

If you’re going to do much graphics programming, you REALLY need to get a firm grasp of euclidean geometry, basic trigonometry and (most importantly) vector algebra or you’ll spend the rest of your life asking overly-simple questions and waiting for days for an answer. If you’ve forgotten all of this stuff from high school - then taking a refresher course at a local community college is a REALLY good idea.