View Full Version : Finding Rotation Angle

 fays123411 November 2010, 02:25 AMHi, I am trying to aggregate a number of equilateral triangles recursively. I start with one triangle (triangle1) , duplicate it, place the pivot of the new triangle (triangle2) on vertex 0, run through a number of conditional statements and then move triangle2 (with the pivot on vertex 0) to one of the 3 vertices of triangle1. This is not a 2-dimensional operation, therefore the rotational operation cannot be the same variable all the time. So, if the new triangle2.vtx0 is placed on triangle1.vtx1, I need to rotate triangle2 (in 3-d) so that it's edge 1 meets triangle1.edge0. Basically, I need to orient triangles so they meet on an edge to edge connection. Any help would be greatly appreciated.
NaughtyNathan
11 November 2010, 11:54 AM
Modify > Snap Align Objects > 2 Points to 2 Points works with two edges selected... so that would be perfect for aligning any two triangles along a common edge... is this any help at all?
I assume your function needs to rotate along this edge once aligned though right..? that would be the tricky bit...

:nathaN

fays1234
11 November 2010, 01:40 PM
That is very helpful, thanks, I just need to figure out how to write it in mel. Seems like a possible task.

you are right, the next step would be to rotate triangle2 about that common edge. I've already stored the midpoint of each edge by calculating v0+v1/2 (and for all other edges). I think I'll move the pivot again to that midpoint, and attempt to rotate about the edge. Before that though, I think I would have to rotate the pivot itself so it matches the angle of the edge, that could be the tricky part.

fays1234
11 November 2010, 02:48 PM
nathan, when I do the command you proposed manually, I get these numbers. Do you have any idea what these 6 numbers represent? are they two vectors? and if so, which two?

thanks

NaughtyNathan
11 November 2010, 04:14 PM
iirc this snap function runs a mel script that works out a new position and rotation for one object based on the 2(4) points selected. I guess that line you've ended up with is simply the last rotate command issued by this script. the first 3 numbers are the x,y,z position of the rotation pivot and the last 3 numbers are the x,y,z angle (in RADians) that the object rotated through to get into its final position.

If you turn on "Echo All Commands" in the Script Editor and then apply the 2 point snap command you should see the name of the MEL command/script that is being executed. loading this up in a text editor and figuring it out may be a big help.

:nathaN

fays1234
11 November 2010, 04:28 PM
ahhhhhh, makes sense. It's Snap2PointsTo2Points;

now, there is one thing that is bothering me. the command does not always put the two triangles next to each other, most of the times (i.e 2 out of 3, it places the triangle directly on top of the other triangle), do you have any idea why that is happening? I assume it has to do with how it computes the edge numbers of each triangles, but I can't be totally sure.

I had been trying to do this using another approach, and I'm not sure what you think:

-Move triangle two vtx.0 to on of the three vertices of triangle1
-I create a space locator there.
-figure out the 3-D rotation angle (what is proving to be the difficult part)
-do that rotation