Bound angle between cuboids

Pages: 123
I did it in the way below, and it almost works, just something is missing as the angle deviates +-20 degrees from the required. Perhaps you can see the mistake?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// .... the previous solution for generating the required random Matrix
Mat A = { { edge.x, third.x, axis.x },
              { edge.y, third.y, axis.y },
              { edge.z, third.z, axis.z }};

//taking and converting the rotation of the first cuboid of the second chain
float ax, ay, az, athet              
align_to.get_rotation(ax, ay, az, atheta);
Mat B = rotationMatrix({ax,ay,az}, atheta);

Mat Binv = transpose(B);
Mat ABinv = A * Binv;

Pt monomer_axis;
float new_theta;
axisAngle(ABinv, monomer_axis, new_theta);


Then I move the second chain to the end of first chain, and rotate_whole_chain using the axisAngle I got around its junction point ( which is the top_center of the last cuboid of the first chain and bottom_center of the first cuboid of the second chain. The rotation function is well tested and works well.

Maybe the rotation center is chosen wrongly in such solution and the second chain should be rotated according its own (mass) center?
Last edited on
The second chain needs to be ROTATED about the centre of the base of its first element.

It then needs to be TRANSLATED so that the centre of the base of the first element in the second chain coincides with the centre of the top of the last element of the first chain.
Works perfectly, thanks. Forgot the scale>rotate>translate rule.

Thank you very much for your support. At least now I have a basic understanding how how the rotation matrices can be used for such operations.
All rotations (unless they do include translation component) occur around axis that goes through origin -- the (0,0,0) in 3D.

Since we want to rotate about a point on "object", that point must be on the axis of rotation.
The trivial solution is to first TRANSLATE whole object to bring the point to origin, then ROTATE whole object and finally TRANSLATE whole object to bring point where we want it.

Example:
Let B be point to rotate about
Let T be point, where B should be after rotation and translation
Let R be rotation
FOR every point P in Object
  X = P - B
  Y = R * X
  P = Y + T
@keskiverto , thank you. Yes, my mistake was that in the beginning I translated the object where I wanted, and then applied rotation.
Topic archived. No new replies allowed.
Pages: 123