C# How can i rotate 4 objects than are not child of each other in correlation?

Started by
2 comments, last by Obs-D 8 months ago

Hello there,

I have this question because it happens than i can improve somewhat my game from the serverside if i get the answer to this.

Consider the next triangle

////D
A - B - C

  • Given for points, three of them in line between themselfs (A - B - C) and another one, let's called D, than make A - B - C become a triangle.
  • Given B rotates in some ammount of angles in the Y axis.
  • Given than the rotation of B provoke the equal rotation of all the rest of the square, altering the position of them (A, C and D) in a proportional angle, keeping the relation with B from the original position.

How can i get the new position of all the other dots which are not B?

Please consider C# for this question.

Thank you

None

Advertisement

To rotate points A and C around point B, first compute the vectors AB and CB which are the relative position of A and C with respect to B. This moves A and C such that B is the origin. Rotations should always be applied with the center of rotation as the origin.

AB = A - B
CB = C - B

Then, you need to apply a 3x3 rotation matrix R which applies the rotation at point B:

RAB = R * AB
RCB = R * CB

Alternatively with 4x4 homogeneous coordinate matrix it would look like this:

RAB = (R * vec4( AB, 0.0f )).xyz
RCB = (R * vec4( CB, 0.0f )).xyz

Then you add point B to RAB and RCB to move the coordinates back to world space (rather than relative to B):

RA = RAB + B
RC = RCB + B

Here, RA and RC are the rotated versions of A and C when rotated by matrix R around point B.

@Aressera Ok, thank you, but how can i get the Matrix3x3?

Let's say i want to rotate B 90°Y, i can get a quaternion with that rotation but, how can i convert that to a Matrix3x3?

If it's better without Quaternions, how can i implement that 90° on the Y axis in the Matrix3x3?

Thanks a lot

None

This topic is closed to new replies.

Advertisement