Creating A Tripod Using Expressions

Hi there,
the goal is to get a camera and tripod, knowing that the camera height (Y) will drive the opening of the 3 tripod legs, that will always be in contact with the floor, in the lower end, and with the camera in the upper end, where the 3 legs meet.
Constarints? IK handles? ... I was trying to avoid driven keys..

Thanks in advance,
Daniel

This was a question on Highend3D.com, and served as the inspiration for this tutorial. Click here for finished example.

The basic concept is that the tripod is really made of 3 right triangles. Each leg is a hypotenuse; one side is formed by the height of the tripod measured at the middle, the other side by the distance from the center to the tip of the leg.

 

Since we know from the Pythagorean Theorem that for any right triangle, the square of the hypotenuse is equal to the sum of the squares of the two sides, or more simply,

A2 + B2 =C2, where A and B are the two sides, and C is the hypotenuse.

Given the hard data that we know (the length of one leg) and data that we can control (the height of the tripod), all we need to do is to solve for the remaining side.

 

The Setup

I took geometry in high school and spent a few years working as a carpenter, so I'm familiar with a few right triangles that come out "even". For this example I started with a variable of the 3-4-5 right triangle; mine is just a 6-8-10. This means that if the long side is eight units, the short side is six, then the hypotenuse has to be 10. Rearranging the above formula to solve for what we need, if the hypotenuse is 10 and one side is 8, then the remaining side has to be 6.

Step One:

Create a bone using two joints. Draw the first joint at (0, 10, 0) and the second at (0, 0, 0), so the bone is 10 units long. Create a cylinder of equal length and parent it to the bone. Move the hierarchy away from the center and duplicate it twice, moving each duplicate away as you go. Create a single-chain IK handle for each joint, and name the handles something obvious, like "leg1", "leg2" and "leg3". (see fig 2)

fig 2
fig 3

 

These will be your tripod legs. They are also the ten-unit hypotenuses for our right triangles. (or is that hypoteni?).

 

Step Two:

Create a locator, and place it at (0, 8, 0). This will be the height of our triangle. Name it "A". Point constrain each top joint to the locator by selecting the locator first, <shift> select the joint and click on Constrain -> Point Constrain. As you complete the operation on each joint, move the IK handle off to the side so it looks a little like a tripod. This isn't really necessary, but it's helpful in keeping your work neat and keeping track of everything. (fig 3).

Step Three:

We need to consider a few facts for the postion of the feet. We know that in this example, the distance from the center of the grid to each foot has to be 6 units, but as the feet won't fall directly on a grid intersection, we may have to do a lot of math to figure the exact position ... or ...

Create default circle with a radius of one. Group this circle to itself three times, and name the nodes "one", "two", "three", and "base", with "base" being the top of the hierarchy. Scale the "base" node to (6, 1, 6). A circle with a scale of 6 in X and Z will have a radius in grid space of 6 units.

Select the "base" node, and click on "Display->Nurbs Components->Edit Points" Using the hypergraph or outliner window, and working your way from the bottom of the hierarchy up, point-snap the pivot points of each circle to an edit point, beginning at any point on the circle, then at 120° increments, as shown.

 

 

 

Point constrain each handle to its corresponding leg, i.e., constrain "leg1" to "one", "leg2" to "two", etc. At this point, your handles may be pulled away from the joints, but don't worry about it. Test the constraints by scaling the "base" node up and down; the IK handles should follow.

NOTE: The hierarchy here is imperative. The legs want to touch the pivot points of each lower circle; the size of each lower circle will adjust with the scale of the "base". Make sure you create the hierarchy BEFORE you scale the top node, otherwise the expression won't work!

 

Step Four:

It's now time to write the expression. Look at the scene, and think of what you know, and what you want to solve for. We know the hypotenuse is 10, we will input the value of the height (A.ty) and we want to solve for the radius of the base, which in this case is the same as (base.sx and base.sz).

Write the expression out longhand first, then make substitutions; if you haven't used expressions or formulas before it'll help your understanding of how things work

A2 + B2 = C2 rewritten is

B2 = C2 - A2. or

base.scale2 = 102 - A.ty2

To my knowledge, there's no way of writing "square" in an expression, but there is a square root function. Also, we want to write this expressoin twice, once for the scale in X of the circle, and once for the scale in Z.

If you take the square root of both sides of the equation, you'll be solving for the square root of base.scale2, or base.scale. This is equal to the square root of (102 - A.ty2)

Open up the expression editor, and in the entry field, type in:

base.sx=sqrt(100 - (A.ty*A.ty));
base.sz=sqrt(100 - (A.ty*A.ty));

Thus, the scale of the base will adjust according to the height (y -translate) of the locator named A.

Did it work? Click here

Didn't work? Try rewriting the expression. Remember that it's case sensitive; make sure your parentheses are correct - formulas like this solve from the innermost parentheses outward. Here we're solving A.ty*A.ty first, then subtracting that value from 100, then taking the square root of the result. After you've written it, count the number of open parentheses and close parentheses - there have to be the same number. Good luck!