extension joomla, template joomla,banner extension joomla,jomla slider,slider joomla
3D Transformation [Translation, Rotation and Scaling] in C/C++


In a three-dimensional homogeneous coordinates representation, a point is translated from position P = (x, y, z) to position P = (x’, y’, z’) with the following equations.
x’ = x + tx
y’ = y + ty
z’ = z + tz

Rotation about axes

To generate a rotation transformation for an object, we must designate an axis of rotation (about which the the object is to be rotated) and the amount of angular rotation. Unlike 2D applications, where all transformations are carried out in the xy plane, a three-dimensional rotation can be specified around any line in space. I will cover rotation about arbitrary axis in another post, here the discussion is restricted to rotation about coordinate axes.
About x – axis

If a point (x, y, z) is rotated through angle ? about x – axis to a new point (x’, y’, z’) then the new point is calculated as
y’ = y cos? – z sin?
z’ = y sin? + z cos?
x’ = x

About y – axis

z’ = z cos? – x sin?
x’ = z sin? + x cos?
y’ = y

About z – axis

x’ = x cos? – y sin?
y’ = x sin? + y cos?
z’ = z

Scaling with respect  a selected fixed position (xf, yf, zf) can be represented with the following transformation sequence:

1. Translate the fixed point to the origin
2. Scale the object relative to the coordinate origin
3. Translate the fixed point back to its original position

The equations for this sequence of transformation is (where s is scaling factor)

x’ = x * s + (1 – s) * xf
y’ = y *s + (1 – s) * yf
z’ = z * s + (1 – s) * zf

Source Code

Related Article

destination source:https://www.programming-techniques.com/?p=97