2d Composite Transformation Program In Computer Graphics Using C

admin
2d Composite Transformation Program In Computer Graphics Using C Average ratng: 8,2/10 9442 votes

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 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.

A scaling transformation alters size of an object. In the scaling process, we either compress or expand the dimension of the object.

Operation we use 3 x 3 matrices and pad our points to become 3 x 1 matrices. This coordinate system (using three values to represent a 2D point) is called homogeneous coordinates. 2D Transformation Translation Rotation Scaling The Below Programs are for 2D Transformation. This is a part of Mumbai University MCA Colleges Computer Graphics MCA Sem 2. 2D Translation.

Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the polygon by scaling factor s x and s y to produce the transformed coordinates as (x’, y’). So, x’ = x * s x and y’ = y * s y. The scaling factor s x, s y scales the object in X and Y direction respectively. So, the above equation can be represented in matrix form: Or P’ = S. P Scaling process: Note: If the scaling factor S is less than 1, then we reduce the size of the object.

If the scaling factor S is greater than 1, then we increase size of the object. Algorithm: 1. Makehuman 2 0 updates

Make a 2x2 scaling matrix S as: S x 0 0 S y 2. For each point of the polygon. (i) Make a 2x1 matrix P, where P[0][0] equals to x coordinate of the point and P[1][0] equals to y coordinate of the point. (ii) Multiply scaling matrix S with point matrix P to get the new coordinate. Draw the polygon using new coordinates.

Below is C implementation.