I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index » Programming » C/C++ »

lucian\′s Photo
10 Nov 05, 8:41AM
Hi there!

So you know how a 3D rotation matrix can be expressed in mathematical form. All you need to do is write a function that applies this transformation to a certain point in 3D given by its coordinates. I would consider storing the point as a struct or as an array of 3 components, i.e.

struct Point
{
  double x, y, z;
};

or

double Point[3];

The function prototype would then have this form:

Point Rotate(Point &P, double alpha, double beta, double gamma);

if you would like not to modify the original point and obtain another, by rotation, or

void Rotate(Point &P, double alpha, double beta, double gamma);

which would rotate the point and affect its coordinates, without creating a second point. In both versions I have considered alpha, beta and gamma to be the angles about the X, Y and Z axis. In what implementation of this function is concerned, it is easy to construct the 3D rotation matrix by first calculating sin(alpha), cos(alpha), sin(beta), cos(beta), sin(gamma), cos(gamma), storing them in separate variables, and then calculate each element of the matrix. To apply the rotation on the given point you would consider that the point forms a matrix of 3 rows and 1 column, with its elements coresponding to the 3 coordinates. Then you would do matrix multiplication between this row-matrix and the rotation matrix, which I assume would not be very difficult to do. In the end, return the new point if you have considered the first version of the prototype.

I hope this helps.

Currently you need to be logged in to leave a message.