#### Archived

This topic is now archived and is closed to further replies.

# Maths - angles and so on

This topic is 5307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

It''s been a long time since I''ve done anything with angles or equations and I''m a bit stuck. I am trying to animate a caterpillar. You can see how it is constructed here: http://www.caterpillar-designs.com at the moment I pass one angle in to control how the caterpilalr bends. You can set the angle using the far left slider. The sliders in the top left show the angle at the different intersections. If you press the button that says visible you can see the skeleon. I want to be able to work out the angle I need to pass in to set the distance between the back foot and the front foot. I started to work out the distance between the two feet but got stuck when the angle became more than 90 degrees (e.g. if the angle is 30 and you are looking at the 4th node the total angle will be 120). Also the equation was getting pretty complicated and would not know how to rearrange it: 3.x = x position of 3''rd node -15 = length of bone first and last segment ignored for now 3.x = (cos angle * -15) + (cos(ngle*2) * -15) + (cos(angle*3)*-15). from this I have n oidea how re-arrange it so that the equation reads angle = something. On top of this I also want to be able to pass in a second parameter to control the height of the back foot relative to the front foot. This is what the second from left slider is supposed to be for. It does move the tail up and down but not to a specific height. The height depends on the angle passed in in the first parameter as well. What I really want is a function that takes two parameters - the x distance from the front foot to the back foot and the y offset from the front foot the back foot. The code I have at the moment for setting the angles is:
function positionCaterpillar(angle, heightAdjustment){
if(angle < 0){
angle = -angle;
}
angle1 = angle + parseInt(heightAdjustment);
angle2 = -angle + parseInt(heightAdjustment);
angle3 = -angle - heightAdjustment;
angle4 = angle - heightAdjustment;

segments[1]._rotation = angle1;
_root.rotTest1.setNewvalue(angle1);

segments[2]._rotation = angle1;
_root.rotTest2.setNewvalue(angle1);
segments[3]._rotation = angle1;
_root.rotTest3.setNewvalue(angle1);
segments[4]._rotation = angle1;
_root.rotTest4.setNewvalue(angle1);

segments[5]._rotation = angle2;
_root.rotTest5.setNewvalue(angle2);

segments[6]._rotation = angle2;
_root.rotTest6.setNewvalue(angle2);
segments[7]._rotation = angle2;
_root.rotTest7.setNewvalue(angle2);
segments[8]._rotation = angle2;
_root.rotTest8.setNewvalue(angle2);

segments[9]._rotation = angle3;
_root.rotTest9.setNewvalue(angle3);
segments[10]._rotation = angle3;
_root.rotTest10.setNewvalue(angle3);
segments[11]._rotation = angle3;
_root.rotTest11.setNewvalue(angle3);

segments[12]._rotation = angle3;
_root.rotTest12.setNewvalue(angle3);

segments[13]._rotation = angle4;
_root.rotTest13.setNewvalue(angle4);
segments[14]._rotation = angle4;
_root.rotTest14.setNewvalue(angle4);
segments[15]._rotation = angle4;
_root.rotTest15.setNewvalue(angle4);

segments[16]._rotation = angle4;
_root.rotTest16.setNewvalue(angle4);
}

where segments is an array pointing to the segments of the caterpillar. segment[0] is the head so would rotate the whole caterpillar so this is always left at 0. I really hope some haths genius out there can help. Even if someone came back and said that this is way to comoplicated at least then I could look at other ways of animatng. THis would be the neatest and most flexible way so I really want to get it to work. Hope you can help. Thanks Giles Roadnight giles.roadnight.name

##### Share on other sites
I haven''t actually tried to do so, but it looks like that can''t be solved algebraically. You''ll probably need some sort of interative solution finder.

A quick test with maple suggests the solution to your 3 angle example is:

angle = arccos(1/30*(2125-225*x+75*sqrt(-150-170*x+9*x^2))^(1/3)+35/6/((2125-225*x+75*sqrt(-150-170*x+9*x^2))^(1/3))-1/6)

where x = 3.x

So I don''t imagine it''ll get any simplier with more angles.

##### Share on other sites
Thanks Geoff.

I am making some progress with the algebra. I think it can be solved it just takes a lot of pen and paper work!!

I think I''ll get there in the end.