View Full Version : Finding Rotation Angle
11-28-2010, 02:25 AM
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.
11-28-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...
11-28-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.
11-28-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?
rotate -r -p 0.4329864383 21.40050581 0.0007166862488 0.001433458606rad 0.0008276061611rad -1.047195829rad pSolid3;
11-28-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.
11-28-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
-rotate about the common edge.
I'm happy using either ways, so long as it works perfectly, hehe. I'm running a big number of triangles, so it's quite tedious to check one by one as opposed to running the function recursively from the beginning.
As for your previous comment about the difficulty of rotating about an edge. Because I'm working with equilateral triangles, that proved to be easy, but the moment I tried something else, it became hard, so I'm looking into aim/orient constraints. But I don't need that at the moment, I'm more concerned about getting them to aggregate without any overlaps.
You've been greatly helpful, thanks a lot.
11-28-2010, 04:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2015, Jelsoft Enterprises Ltd.