How to get the matrix in which I translated, then rotate, and then translate, and then rotate a second time?

In an Android app, I want to draw a running foot. To output the upper leg, I do something like:

// legCX,legCY is the location on screen about which the leg rotates.
Matrix m = new Matrix();
m.postTranslate(-legCX,-legCY);
m.postRotate(legRot);
m.postTranslate(legCX,legCY);

Then I set the matrix on the canvas and draw the leg.

How to make the second part of the leg below the knee? It rotates at a different speed than the leg above it, and has a central point that moves with its legs above it. I tried the following, but it turns out that the end result is a rotation around a single point that does not match the leg above.

Matrix m = new Matrix();
m.postTranslate(-legCX,-legCY);
m.postRotate(legRot);
m.postTranslate(0,-legLength);
m.postRotate(footRot);
m.postTranslate(0,legLength);
m.postTranslate(legCX,legCY);

I suspect that it is probably necessary to make two rotations in two different Matrix objects, and then somehow combine them, but I cannot figure out exactly how to do this.

EDIT: , -, " ". . , .

, , , , .

, , .

+5
2

, . , . .

double pendulum

, p1, p0,

p2, p1,

, p2, p0,

.

+6

, - - - Android, Android ! , , Android, , .

- , ( - , ): UpperLeg LowerLeg.

  • UpperLeg , (RotationPoint) ( , ), , LowerLeg (AttachmentPoint) ( , ).
  • LowerLeg , (RotationPoint) ( , , ).

UpperLeg.AttachmentPoint= LowerLeg.RotationPoint ( ).

, ( UpperLeg LowerLeg): UpperLeg.Rotation LowerLeg.Rotation.

( - , - , - 1846 - , , ( ) Gimbal-lock).

UpperLeg :

  • UpperLeg, UpperLeg.RotationPoint
  • UpperLeg.Rotation
  • UpperLeg, , . , .

, LowerLeg :

  • LowerLeg, LowerLeg.RotationPoint
  • (UpperLeg.Rotation LowerLeg.Rotation)
  • LowerLeg , UpperLeg 3
  • LowerLeg , ( UpperLeg.RotationPoint UpperLeg.AttachmentPoint), UpperLeg.Rotation.

.

, :
LowerLeg, , , - , , UpperLeg , , LowerLeg UpperLeg.

, , - , , .

+2

All Articles