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


Maths - angles and so on

Recommended Posts

Roaders    122
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: 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;
	segments[2]._rotation = angle1;
	segments[3]._rotation = angle1;
	segments[4]._rotation = angle1;
	segments[5]._rotation = angle2;
	segments[6]._rotation = angle2;
	segments[7]._rotation = angle2;
	segments[8]._rotation = angle2;
	segments[9]._rotation = angle3;
	segments[10]._rotation = angle3;
	segments[11]._rotation = angle3;
	segments[12]._rotation = angle3;
	segments[13]._rotation = angle4;
	segments[14]._rotation = angle4;
	segments[15]._rotation = angle4;
	segments[16]._rotation = 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

Share this post

Link to post
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 this post

Link to post
Share on other sites
Roaders    122
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.

Share this post

Link to post
Share on other sites