Pergunta

I'm playing with body animation in AS3. I did a body with all parts (excluding fingers) and make a XML with the "skeleton". The XML got the instances of each part and the place of the articulation of the next part. I make it work with cardinal coordinates (x,y) and the body moves when I rotate a part and recalculate all the links again (each part in each articulation).

However, this will demand some calculation each little modification of the body, so now I'm optimizing it. As for de design x,y is easier, so when the body instance is created, the class re-build the XML converting coordinates to Polar system (r,t), like this ("Quadro" is the node with coordinates):

dx = Quadro.@x;
dy = Quadro.@y;
Quadro.@r = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2));
Quadro.@t = (dy>0)? Math.asin(dx/Quadro.@r) : Math.acos(dy/Quadro.@r);

I did some changes to make it work but at list one quadrant is always wrong! In this case, the upper left is wrong. The neck and the head should be in this place and they are in upper right (mirrored).

Any tips for a right conversion in AS3?

Foi útil?

Solução

Try to use this:

Quadro.@t=Math.atan2(dy,dx);

From Wikipedia:

The Cartesian coordinates x and y can be converted to polar coordinates r and φ with r ≥ 0 and φ in the interval (−π, π] by:

enter image description here
enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top