SlideShare a Scribd company logo
MATHS
ASSIGNMENT
SUBMITTED TO:
DR. RISHI ASTHANA
SUBMITTED BY:
DHEERAJ MANGAL
PRAMAN SATYA
SAUMYA TIWARI
SHUBHAM SHARMA
SOMESH SHARMA
(SECTION F)
ACKNOWLEDGEMENT
We extend our sincere gratitude towards Dr. RISHI ASTHANA for giving
us his invaluable knowledge and wonderful technical guidance. We
express our thanks to all of parents who believed in us. This report has
helped us in learning the mathematics of reflection, shearing, scaling
and we came to know about many new things, the most important
being the value of teamwork.
TABLE OF CONTENTS
Sr. No. CONTENTS Pg. No.
1.
INTRODUCTION-
2D & 3D TRANSFORMATION:
1) Reflection
2) Scaling
3) Shear
4) Translation
5) Rotation
4 - 13
2. PROBLEM STATEMENT 14
3. ALGORITHM 15-18
4. CODING OF PROGRAM 19-31
5. REFERENCES 32
INTRODUCTION
LINEAR TRANSFORMATION
In linear algebra, linear transformations can be represented by matrices. If T is a linear
transformation mapping Rn
to Rm
and is a column vector with n entries, then
for some m×n matrix A, called the transformation matrix of T.
2D TRANSFORMATION:
1) SCALING:
To change the size of an object, scaling transformation is used. In the scaling process, you
either expand or compress the dimensions of the object. Scaling can be achieved by
multiplying the original coordinates of the object with the scaling factor to get the desired
result.
Let us assume that the original coordinates are (P, Q), the scaling factors are (SX, SY), and
the produced coordinates are (P’, Q’). This can be mathematically represented as shown
below −
P' = P X SX and Q' = Q X SY
The scaling factor SX, SY scales the object in X and Y direction respectively. The above
equations can also be represented in matrix form as below –[Let X=P & Y=Q]
Then-
OR
P’ = P. S
Where S is the scaling matrix. The scaling process is shown in the following figure.
If we provide values less than 1 to the scaling factor S, then we can reduce the size of the
object. If we provide values greater than 1, then we can increase the size of the object.
2) SHEAR:
In plane geometry, a shear mapping is a linear map that displaces each point in fixed
direction, by an amount proportional to its signed distance from a line that is parallel to that
direction.[1]
This type of mapping is also called shear transformation, transvection, or
just shearing.
Horizontal and vertical shear of the plane:
In the plane, R2
= R × R , a horizontal shear (or shear parallel to the x axis) is a function that
takes a generic point with coordinates (x,y) to the point(x+my,y) ; where m is a fixed
parameter, called the shear factor.
The effect of this mapping is to displace every point horizontally by an amount proportionally
to its y coordinate. Any point above the x-axis is displaced to the right (increasing x) if m>0,
and to the left if m<0. Points below the x-axis move in the opposite direction, while points on
the axis stay fixed.
Straight lines parallel to the x-axis remain where they are, while all other lines are turned, by
various angles, about the point where they cross the x-axis. Vertical lines, in particular,
become oblique lines with slope 1/m. Therefore the shear factor m is the cotangent of the
angle φ by which the vertical lines tilt, called the shear angle.
If the coordinates of a point are written as a column vector (a 2×1 matrix), the shear mapping
can be written as multiplication by a 2×2 matrix:
A vertical shear (or shear parallel to the y-axis) of lines is similar, except that the roles
of x and y are swapped. It corresponds to multiplying the coordinate vector by
the transposed matrix:
The vertical shear displaces points to the right of the y-axis up or down, depending on the
sign of m. It leaves vertical lines invariant, but tilts all other lines about the point where they
meet the y-axis. Horizontal lines, in particular, get tilted by the shear angle of φ to become
lines with slope m.
General shear mappings
For a vector space V and subspace W, a shear fixing W translates all vectors parallel to W.
To be more precise, if V is the direct sum of W and W′, and we write vectors as
v = w + w′ correspondingly, the typical shear fixing W is L where
L (v) = (w + Mw′) + w ′where M is a linear mapping from W′ into W. Therefore in block
matrix terms L can be represented as
3) TRANSLATION:
In Euclidean geometry, a translation is a geometric transformation that moves every point of
a figure or a space by the same amount in a given direction.
A translation can also be interpreted as the addition of a constant vector to every point, or as
shifting the origin of the coordinate system.
A translation moves an object to a different position on the screen. You can translate a point
in 2D by adding translation coordinate (tx, ty ) to the original coordinate (X, Y) to get the new
coordinate (X’, Y’).
From the above figure, you can write that −
X’ = X + tx
Y’ = Y + ty
The pair (tx, ty ) is called the translation vector or shift vector. The above equations can also be
represented using the column vectors.
We can write it as −
P’ = P + T
4) REFLECTION
In a plane geometry, to find the reflection of a point drop a perpendicular from the point to the
line (plane) used for reflection, and extend it the same distance on the other side. To find the
reflection of a figure, reflect each point in the figure.
The matrix for a reflection is orthogonal with determinant −1 and eigenvalues −1, 1, 1, ..., 1.
The product of two such matrices is a special orthogonal matrix that represents a rotation.
Every rotation is the result of reflecting in an even number of reflections in hyperplanes
through the origin, and every improper rotation is the result of reflecting in an odd number.
Thus reflections generate the orthogonal group, and this result is known as the Cartan–
Dieudonné theorem.
To reflect a vector about a line that goes through the origin, let be a vector in the
direction of the line:
Orthogonal projection
To project a vector orthogonally onto a line that goes through the origin, let be
a vector in the direction of the line. Then use the transformation matrix:
As with reflections, the orthogonal projection onto a line that does not pass through the origin is
an affine, not linear, transformation.
Parallel projections are also linear transformations and can be represented simply by a matrix.
However, perspective projections are not, and to represent these with a matrix, homogeneous
coordinates must be used.
5) ROTATION:
A motion of a Euclidean space is the same as its isometry: it leaves the distance between
any two points unchanged after the transformation. But a (proper) rotation also has to
preserve the orientation structure. The "improper rotation" term refers to isometries that
reverse (flip) the orientation. In the language of group theory the distinction is expressed
as direct vs. indirect isometries in the Euclidean group, where the former comprise
the identity component. Any direct Euclidean motion can be represented as a composition of
a rotation about the fixed point and a translation.
In two dimensions, to carry out a rotation using a matrix the point (x, y) to be rotated
counterclockwise is written as a column vector, then multiplied by a rotation
matrix calculated from the angle, θ:
where (x′, y′) are the coordinates of the point that after rotation, and the formulae
for x′ and y′ can be seen to be
The vectors have the same magnitude and are separated by an angle θ as
expected.
Points on the R2 plane can be also presented as complex numbers: the point (x, y) in the
plane is represented by the complex number
This can be rotated through an angle θ by multiplying it by eiθ, then expanding the product
using Euler's formula as follows:
and equating real and imaginary parts gives the same result as a two-dimensional matrix:
Since complex numbers form a commutative ring, vector rotations in two dimensions are
commutative, unlike in higher dimensions. They have only one degree of freedom, as such
rotations are entirely determined by the angle of rotation.
3D TRANSFORMATION:
1) REFLEXION:
To reflect a point through a plane ax+by+cz=0 (which goes through the origin), one can
use , where I is the 3x3 identity matrix and N is the three-
dimensional unit vector for the vector normal of the plane. If the L2 norm of a, b and c is
unity, the transformation matrix can be expressed as:
2)
Note that these are particular cases of a Householder reflection in two and three dimensions.
A reflection about a line or plane that does not go through the origin is not a linear
transformation — it is an affine transformation — as a 4x4 affine transformation matrix, it can
be expressed as follows (assuming the normal is a unit vector):
Where d=p.N for some point p on the plane.
If the 4th component of the vector is 0 instead of 1, then only the vector's direction is
reflected and its length remains unchanged, as if it were mirrored through a parallel plane
that passes through the origin.
2) SCALING:
In Euclidean geometry, uniform scaling (or isotropic scaling) is a linear transformation that
enlarges (increases) or shrinks (diminishes) objects by a scale factor that is the same in all
directions. The result of uniform scaling is similar (in the geometric sense) to the original. A
scale factor of 1 is normally allowed, so that congruent shapes are also classed as similar.
Uniform scaling happens, for example, when enlarging or reducing a photograph, or when
creating a scale model of a building, car, airplane, etc.
A scaling can be represented by a scaling matrix. To scale an object by a vector v = (vx, vy,
vz), each point p = (px, py, pz) would need to be multiplied with this scaling matrix:
As shown below, the multiplication will give the expected result:
Such a scaling changes the diameter of an object by a factor between the scale factors,
the area by a factor between the smallest and the largest product of two scale factors, and
the volume by the product of all three.
The scaling is uniform if and only if the scaling factors are equal (vx = vy = vz). If all except
one of the scale factors are equal to 1, we have directional scaling.
In the case where vx = vy = vz = k, scaling increases the area of any surface by a factor of
k2
and the volume of any solid object by a factor of k3
.
3) SHEAR:
A transformation that slants the shape of an object is called the shear transformation. Like in
2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D.
As shown in the above figure, there is a coordinate P. You can shear it to geta new coordinate
P', which can be represented in 3D matrix form as below –
4) TRANSLATION:
A translation is an affine transformation with no fixed points. Matrix
multiplications always have the origin as a fixed point. Nevertheless, there is a
common workaround using homogeneous coordinates to represent a translation of a vector
space with matrix multiplication: Write the 3-dimensional vector w = (wx, wy, wz) using 4
homogeneous coordinates as w = (wx, wy, wz, 1).
To translate an object by a vector v, each homogeneous vector p (written in homogeneous
coordinates) can be multiplied by this translation matrix:
As shown below, the multiplication will give the expected result:
The inverse of a translation matrix can be obtained by reversing the direction of the vector:
Similarly, the product of translation matrices is given by adding the vectors:
Because addition of vectors is commutative, multiplication of translation matrices is therefore
also commutative (unlike multiplication of arbitrary matrices).
5) ROTATION:
As in two dimensions, a matrix can be used to rotate a point (x, y, z) to a point (x′, y′, z′).
The matrix used is a 3×3 matrix,
6)
This is multiplied by a vector representing the point to give the result
7)
The set of all appropriate matrices together with the operation of matrix multiplication is
the rotation group SO(3). The matrix A is a member of the three-dimensional special
orthogonal group, SO(3), that is it is an orthogonal matrix with determinant 1. That it is an
orthogonal matrix means that its rows are a set of orthogonal unit vectors (so they are
an orthonormal basis) as are its columns, making it simple to spot and check if a matrix is a
valid rotation matrix.
Problem Statement:
Write a program in C to show the effect of reflection, scaling, shear, translation and rotation on a point
in 2D and 3D. Also write a program in C to show the effect of reflection, scaling, shear, translation and
rotation on an object in 2D.
ALGORITHM
1. Start
2. Ask whether 2d or 3d point
For 2D:
3. Take x and y coordinates as input from user
4. Reflection
a. Across the origin
i. x’=-x , y’=-y
ii. print(x’,y’)
b. Across y=x line
i. x’=y , y'=x
ii. print(x’,y’)
c. About Y axis
i. x’=-x , y’=y
ii. print(x’,y’)
d. About X axis
iii. x’=x , y’=-y
iv. print(x’,y’)
5. Shear Transformation
i. Take shear coefficients a & b
ii. x’=x+ay , y’=y+bx
iii. print(x’,y’)
6. Scaling
i. Take scaling factor input a & b
ii. x’=x*a , y=y*b
iii. print(x’,y’)
7. Translation
i. Take translation input a & b
ii. x’=x+a , y’=y+b
iii. print(x’,y’)
8. Rotation
i. Take angle in radians as input (ang)
ii. x’=x*cos(ang) , y’=y*sin(ang)
iii. print(x’,y’)
For 3d:
3. Take x,y,z coordinates as input from user
4. Reflection
a. Across the origin
i. x’=-x , y’=-y ,z’=-z
ii. print(x’,y’,z’)
b. Across xy plane
i. x’=x , y'=y , z’=-z
ii. print(x’,y’,z’)
c. Across xz plane
i. x’=x , y'=-y , z’=z
ii. print(x’,y’,z’)
d. Across yz plane
i. x’=-x , y'=y , z’=z
ii. print(x’,y’,z’)
e. About Y axis
i. x’=-x , y’=y , z’=-z
ii. print(x’,y’,z’)
f. About X axis
i. x’=x , y’=-y , z’=-z
ii. print(x’,y’,z’)
5. Shear Transformation
i. Take shear coefficients a & b
ii. Sheared points in xy plane are x’= x + a*y , y’= y + b*x , z’=z
iii. Sheared points in yz plane are x’=x , y’=y+az , z’=z+bz
iv. Sheared points in xz plane are x’=x+bz , y’=y , z’=z+ax
iii. print(x’,y’,z’)
6. Scaling
i. Take scaling factor input a , b and c
ii. x’=x*a , y=y*b ,z=z*c
iii. print(x’,y’,z’)
7. Translation
i. Take translation input a ,b and c
ii. x’=x+a , y’=y+b , z’=z+c
iii. print(x’,y’,z’)
8. Rotation
i. Take angle in radians as input (ang)
ii. z-axis rotation : x’= x*cos(ang) - y*sin(ang)
y’= y*cos(ang) + x*sin(ang)
z’=z
iii. x-axis rotation : x’= x
y’= y*cos(ang) - z*sin(ang)
z’=y* sin(ang) + z*cos(ang)
iv. y-axis rotation : x’= z*sin(ang) + x*cos(ang)
y’= y
z’= -x*sin(ang) + z*cos(ang)
v. print(x’,y’,z’)
CODING
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
int choice,option,type,type_ref,scale_x,scale_y,scale_z,a,b,c;
float x,y,z,ang,x_she,y_she;
system("COLOR 0A");
printf("nnnt Enter the corrosponding number to go through that:");
printf("nnnnntSelect the type of operation(1 for points and 2 for object) : ");
scanf("%d" , &choice);
switch(choice)
{
case 1:
system("cls");
system("COLOR 0B");
printf("nnnnttEnter the type of point(2 for 2D or 3 for 3D) : ");
scanf("%d" , &option);
switch(option)
{
case2:
system("COLOR 0C");
printf("nnntttEnter the type of transformationnntttt 1 for reflectionntttt 2
for scaling ntttt 3 for shear ntttt 4 for translation ntttt 5 for rotation) : ");
scanf("%d" , &type);
switch(type)
{
case 1:
system("cls");
system("COLOR 0D");
printf("nnnnnnttttYou have chosen Reflection.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
system("COLOR 0E");
printf("nnntttEnter the type of reflection : nnttt 1 across origin nttt 2 across
y=x line nttt 3 across across axes ");
scanf("n%d" , &type_ref);
switch(type_ref)
{
case 1:
system("cls");
system("COLOR 2E");
printf("nnnnntttThe reflection across the origin isnntttttx'=
%.2fnttttty'= %.2f.n" , -x , -y);
break;
case 2:
system("cls");
system("COLOR 2E");
printf("nnnnntttThe reflection across y=x line isnntttt x'=%.2fntttt
y'=%.2f.n" , y , x);
break;
case 3:
system("cls");
system("COLOR 2E");
printf("nnnnntThe reflection across x-axis isnnttttx'= %.2fntttty'=
%.2f.n" , x , -y);
printf("ntThe reflection across y-axis isnnttttx'= %.2fntttty'= %.2f.n" , -x ,
y);
break;
default:
system("cls");
system("COLOR 2E");
printf("nnnnntttt|| Invalid Input.||n");
break;
};
break;
case2:
system("cls");
system("COLOR 0F");
printf("nnnnnnttttYou have chosen Scalingn");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nnttEnter the scaling for x and y point :nntttscale of x= ");
scanf("%d" ,&scale_x);
printf("ntttscaleof y= ");
scanf("%d" ,&scale_y);
system("cls");
system("COLOR 4F");
printf("nnnnntttThe points after scaling are:nnttttx'= %.2fntttty'= %.2f.n"
, (scale_x*x) , (scale_y*y)) ;
break;
case 3:
system("cls");
system("COLOR 1A");
printf("nnnnnntttYou have chosen Shear transformation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nnttEnter shear coefficients a and b( x = x + ay , y = y + bx): ");
scanf("%d %d" , &a , &b);
x_she = x + y*a;
y_she= y + x*b;
system("cls");
system("COLOR 3F");
printf("nnnnntttSheared points are: nnttttx'= %.2fntttty'= %.2f.n" , x_she
, y_she);
break;
case 4:
system("cls");
system("COLOR 6E");
printf("nnnnnntttYou have chosen translation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nntttEnter translation distance for x and y: ");
scanf("%d %d" , &a , &b);
system("cls");
system("COLOR 5C");
printf("nnnnntttTranslated points are: nnttttx'= %.2fntttty'= %.2f.n" , (x +
a) , (y + b) );
break;
case5:
system("cls");
system("COLOR 7F");
printf("nnnnnnttttYou have chosen rotation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nnnttEnter angle in radians for rotation in x and y :nttttt ");
scanf("%f" , &ang);
system("cls");
system("COLOR 8E");
printf("nnnnntttThe rotated coordinates are: nnttttx'= %.2fntttty'=
%.2f.n" , (x*cos(ang) - y*sin(ang)) , (y*cos(ang) + x*sin(ang)) );
break;
default:
system("cls");
system("COLOR 2E");
printf("nnnnntttt|| Invalid Input.||n");
break;
}
break;
case 3:
system("COLOR 0E");
printf("nnntttEnter the type of transformationnntttt 1 for reflectionntttt 2
for scaling ntttt 3 for shear ntttt 4 for translation ntttt 5 for rotation) : ");
scanf("%d" , &type);
switch(type)
{
case 1:
system("cls");
system("COLOR 0D");
printf("nnnnnnttttYou have chosen Reflection.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nttttEnter z coordinate : ");
scanf("%f" , &z);
printf("nnntttEnter the type of reflection :nnttt 1 across origin nttt 2 across
planes nttt 3 across axes) : ");
scanf("n%d" , &type_ref);
switch(type_ref)
{
case 1:
system("cls");
system("COLOR 2E");
printf("nnnnntttThe reflection across the origin isnntttttx'= %.2f
nttttty'= %.2fntttttz'= %.2fn" , -x , -y , -z);
break;
case 2:
system("cls");
system("COLOR 2E");
printf("nnntttThe reflection across xy plane isnttttx'= %.2fntttty'= %.2f
nttttz'= %.2f.n" , x , y , -z);
printf("ntttThe reflection across yz plane isnttttx'= %.2f ntttty'= %.2f
nttttz'= %.2f.n" , -x , y , z);
printf("ntttThe reflection across xz plane isnttttx'= %.2f ntttty'= %.2f
nttttz'= %.2f.n" , x , -y , z);
break;
case 3:
system("cls");
system("COLOR 2E");
printf("nnnnnttThe reflection across x-axis is nttttx'= %.2f ntttty'= %.2f
nttttz'= %.2f.n" , x , -y , -z);
printf("nttThe reflection across y-axis is nttttx'= %.2fntttty'= %.2f
nttttz'= %.2f.n" , -x , y , -z);
printf("nttThe reflection across z-axis is nttttx'= %.2f ntttty'= %.2f
nttttz'= %.2f.n" , -x , -y , z);
break;
default:
system("cls");
system("COLOR 2E");
printf("nnnnntttt|| Invalid Input.||n");
};
break;
case2:
system("cls");
system("COLOR 0F");
printf("nnnnnnttttYou have chosen Scalingn");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nttttEnter z coordinate : ");
scanf("%f" , &z);
printf("nnttEnter the scaling for x, y and z point :nntttscaleof x= ");
scanf("%d" ,&scale_x);
printf("ntttscaleof y= ");
scanf("%d" ,&scale_y);
printf("ntttscaleof z= ");
scanf("%d" ,&scale_z);
system("cls");
system("COLOR 4F");
printf("nnnnntttThe points after scaling are:nnttttx'= %.2fntttty'=
%.2fnttttz'= %.2f.n" , (scale_x*x) , (scale_y*y) , (scale_z*z) ) ;
break;
case3:
system("cls");
system("COLOR 1A");
printf("nnnnnntttYou have chosen Shear transformation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nttttEnter z coordinate : ");
scanf("%f" , &z);
printf("nnttEnter shear coefficients a and b( x = x + ay , y = y + bx): ");
scanf("%d %d" , &a , &b);
system("cls");
system("COLOR 3F");
printf("nnntttSheared points in xy plane are nttttx'= %.2f ntttty'= %.2f
nttttz'=%.2f.n" , x + a*y , y + b*x , z);
printf("nntttSheared points in yz plane are nttttx'= %.2f ntttty'= %.2f
nttttz'=%.2f.n" , x , y + a*z , z + b*y);
printf("nntttjSheared points in zx plane are nttttx'= %.2f ntttty'= %.2f
nttttz'=%.2f.n" , x + b*z , y , z + a*x);
break;
case4:
system("cls");
system("COLOR 6E");
printf("nnnnnntttYou have chosen translation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nttttEnter z coordinate : ");
scanf("%f" , &z);
printf("Enter translation distance for x,yand z: ");
scanf("%d %d %d" , &a , &b , &c);
system("cls");
system("COLOR 5C");
printf("nnnnntttTranslated points are: nnttttx'= %.2fntttty'=
%.2f.nttttz'=%.2f" , (x + a) , (y + b) , (z + c) );
break;
case5:
system("cls");
system("COLOR 7F");
printf("nnnnnnttttYou have chosen rotation.n");
printf("nnttttEnter x coordinate : ");
scanf("%f" , &x);
printf("nttttEnter y coordinate : ");
scanf("%f" , &y);
printf("nttttEnter z coordinate : ");
scanf("%f" , &z);
printf("nnntEnter anglein radians for rotation in x,y and z :nttttt ");
scanf("%f" , &ang);
system("cls");
system("COLOR 8E");
printf("nnntttCoordinates after z-axis rotation are nnttttx'= %.2f ntttty'=
%.2fz'= %.2f.n" , (x*cos(ang) - y*sin(ang)) , (y*cos(ang)+ x*sin(ang)), z);
printf("nntttCoordinates after x-axis rotation arennttttx'= %.2f ntttty'=
%.2fz'= %.2f.n" , x , (y*cos(ang) - z*sin(ang)) , (y*sin(ang) + z*cos(ang)));
printf("nntttCoordinates after y-axis rotation are nnttttx'= %.2fntttty'=
%.2fz'= %.2f.n" , (z*sin(ang) + x*cos(ang)) , y , (-x*sin(ang) + z*cos(ang)));
break;
default:
system("cls");
system("COLOR 2E");
printf("nnnnntttt|| Invalid Input.||n");
}
break;}
break;}
REFERENCES
1. “ANSI C” by Balaguruswami.
2. Let us “C” by Kanetkar.
3. www.wikipedia.org

More Related Content

PPT
Coordinate transformation
PPS
Overview of 2D and 3D Transformation
PDF
2D Transformations(Computer Graphics)
PDF
Computer graphics mcq question bank
PDF
Computer Graphics & linear Algebra
PPTX
2d-transformation
PDF
important Questions class 11 chapter 1 sets
PPTX
Scaling and shearing
Coordinate transformation
Overview of 2D and 3D Transformation
2D Transformations(Computer Graphics)
Computer graphics mcq question bank
Computer Graphics & linear Algebra
2d-transformation
important Questions class 11 chapter 1 sets
Scaling and shearing

What's hot (20)

PDF
3D Transformation
PPTX
Hidden surface removal
PPTX
Back face detection
PPTX
Visible surface identification
PPTX
Window to viewport transformation&amp;matrix representation of homogeneous co...
PPTX
KEY FRAME SYSTEM-Ruby Stella mary.pptx
PPTX
3d transformation computer graphics
PPT
Intro to scan conversion
PDF
Unit 3
PPTX
Reflection transformation
PPT
Visible surface detection in computer graphic
PPTX
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
PPTX
Polygons - Computer Graphics - Notes
PPT
Composite transformations
PPTX
3D transformation in computer graphics
PPTX
Matrix representation- CG.pptx
PPTX
2D viewing & clipping
PPTX
Raster scan system & random scan system
PPTX
2 d viewing computer graphics
PPTX
Curve and text clipping
3D Transformation
Hidden surface removal
Back face detection
Visible surface identification
Window to viewport transformation&amp;matrix representation of homogeneous co...
KEY FRAME SYSTEM-Ruby Stella mary.pptx
3d transformation computer graphics
Intro to scan conversion
Unit 3
Reflection transformation
Visible surface detection in computer graphic
HOMOGENEOUS CO-ORDINATES IN COMPUTER GRAPHICS PPT
Polygons - Computer Graphics - Notes
Composite transformations
3D transformation in computer graphics
Matrix representation- CG.pptx
2D viewing & clipping
Raster scan system & random scan system
2 d viewing computer graphics
Curve and text clipping
Ad

Similar to Reflection, Scaling, Shear, Translation, and Rotation (20)

PPT
2 d geometric transformations
PPT
2 d transformations by amit kumar (maimt)
PPTX
Geometrical Transformations
PPT
Two dimentional transform
PDF
2 d transformations
PDF
Transformations of functions
PDF
Mapping of functions
PPT
2 d transformation
PPTX
Transformations zambia
PPT
2d transformation
DOCX
Transf handout
PPT
2D-Transformations-Transformations are the operations applied to geometrical ...
DOC
Unit 3 notes
PPTX
Vectors and Transformation of the Plane.pptx
PPT
Two dimensional geometric transformations
PPTX
Information Sheet for grade 7 on percenatges
PPT
Two dimensional_Transformations Notes.ppt
PPT
Matrix 2 d
PPTX
Two dimensionaltransformations
PPTX
Presentation3(UNIT-3) presentation of std
2 d geometric transformations
2 d transformations by amit kumar (maimt)
Geometrical Transformations
Two dimentional transform
2 d transformations
Transformations of functions
Mapping of functions
2 d transformation
Transformations zambia
2d transformation
Transf handout
2D-Transformations-Transformations are the operations applied to geometrical ...
Unit 3 notes
Vectors and Transformation of the Plane.pptx
Two dimensional geometric transformations
Information Sheet for grade 7 on percenatges
Two dimensional_Transformations Notes.ppt
Matrix 2 d
Two dimensionaltransformations
Presentation3(UNIT-3) presentation of std
Ad

More from Saumya Tiwari (11)

PDF
APPLICATION OF SIGNAL PROCESSING IN RADIO ASTRONOMY SYSTEMS
PDF
Voice Control Home Automation
PDF
Case Study: LED
PDF
IoT Based Fire Alarm and Monitoring System
PPTX
Anti bag snatching alarm
PPTX
Detection of Abandoned Bag
PDF
Cloning
PPTX
Isotherm project
DOCX
Queue less report
DOCX
Climbing Cleaning Robot
PDF
Modes of entry
APPLICATION OF SIGNAL PROCESSING IN RADIO ASTRONOMY SYSTEMS
Voice Control Home Automation
Case Study: LED
IoT Based Fire Alarm and Monitoring System
Anti bag snatching alarm
Detection of Abandoned Bag
Cloning
Isotherm project
Queue less report
Climbing Cleaning Robot
Modes of entry

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
master seminar digital applications in india
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Trump Administration's workforce development strategy
Microbial diseases, their pathogenesis and prophylaxis
O5-L3 Freight Transport Ops (International) V1.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Computing-Curriculum for Schools in Ghana
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
master seminar digital applications in india
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
human mycosis Human fungal infections are called human mycosis..pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
Supply Chain Operations Speaking Notes -ICLT Program
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Weekly quiz Compilation Jan -July 25.pdf
Final Presentation General Medicine 03-08-2024.pptx
Trump Administration's workforce development strategy

Reflection, Scaling, Shear, Translation, and Rotation

  • 1. MATHS ASSIGNMENT SUBMITTED TO: DR. RISHI ASTHANA SUBMITTED BY: DHEERAJ MANGAL PRAMAN SATYA SAUMYA TIWARI SHUBHAM SHARMA
  • 2. SOMESH SHARMA (SECTION F) ACKNOWLEDGEMENT We extend our sincere gratitude towards Dr. RISHI ASTHANA for giving us his invaluable knowledge and wonderful technical guidance. We express our thanks to all of parents who believed in us. This report has helped us in learning the mathematics of reflection, shearing, scaling and we came to know about many new things, the most important being the value of teamwork.
  • 3. TABLE OF CONTENTS Sr. No. CONTENTS Pg. No. 1. INTRODUCTION- 2D & 3D TRANSFORMATION: 1) Reflection 2) Scaling 3) Shear 4) Translation 5) Rotation 4 - 13 2. PROBLEM STATEMENT 14 3. ALGORITHM 15-18 4. CODING OF PROGRAM 19-31 5. REFERENCES 32
  • 4. INTRODUCTION LINEAR TRANSFORMATION In linear algebra, linear transformations can be represented by matrices. If T is a linear transformation mapping Rn to Rm and is a column vector with n entries, then for some m×n matrix A, called the transformation matrix of T. 2D TRANSFORMATION: 1) SCALING: To change the size of an object, scaling transformation is used. In the scaling process, you either expand or compress the dimensions of the object. Scaling can be achieved by multiplying the original coordinates of the object with the scaling factor to get the desired result. Let us assume that the original coordinates are (P, Q), the scaling factors are (SX, SY), and the produced coordinates are (P’, Q’). This can be mathematically represented as shown below − P' = P X SX and Q' = Q X SY The scaling factor SX, SY scales the object in X and Y direction respectively. The above equations can also be represented in matrix form as below –[Let X=P & Y=Q] Then- OR P’ = P. S Where S is the scaling matrix. The scaling process is shown in the following figure.
  • 5. If we provide values less than 1 to the scaling factor S, then we can reduce the size of the object. If we provide values greater than 1, then we can increase the size of the object. 2) SHEAR: In plane geometry, a shear mapping is a linear map that displaces each point in fixed direction, by an amount proportional to its signed distance from a line that is parallel to that direction.[1] This type of mapping is also called shear transformation, transvection, or just shearing.
  • 6. Horizontal and vertical shear of the plane: In the plane, R2 = R × R , a horizontal shear (or shear parallel to the x axis) is a function that takes a generic point with coordinates (x,y) to the point(x+my,y) ; where m is a fixed parameter, called the shear factor. The effect of this mapping is to displace every point horizontally by an amount proportionally to its y coordinate. Any point above the x-axis is displaced to the right (increasing x) if m>0, and to the left if m<0. Points below the x-axis move in the opposite direction, while points on the axis stay fixed. Straight lines parallel to the x-axis remain where they are, while all other lines are turned, by various angles, about the point where they cross the x-axis. Vertical lines, in particular, become oblique lines with slope 1/m. Therefore the shear factor m is the cotangent of the angle φ by which the vertical lines tilt, called the shear angle. If the coordinates of a point are written as a column vector (a 2×1 matrix), the shear mapping can be written as multiplication by a 2×2 matrix: A vertical shear (or shear parallel to the y-axis) of lines is similar, except that the roles of x and y are swapped. It corresponds to multiplying the coordinate vector by the transposed matrix: The vertical shear displaces points to the right of the y-axis up or down, depending on the sign of m. It leaves vertical lines invariant, but tilts all other lines about the point where they meet the y-axis. Horizontal lines, in particular, get tilted by the shear angle of φ to become lines with slope m. General shear mappings For a vector space V and subspace W, a shear fixing W translates all vectors parallel to W. To be more precise, if V is the direct sum of W and W′, and we write vectors as v = w + w′ correspondingly, the typical shear fixing W is L where L (v) = (w + Mw′) + w ′where M is a linear mapping from W′ into W. Therefore in block matrix terms L can be represented as
  • 7. 3) TRANSLATION: In Euclidean geometry, a translation is a geometric transformation that moves every point of a figure or a space by the same amount in a given direction. A translation can also be interpreted as the addition of a constant vector to every point, or as shifting the origin of the coordinate system. A translation moves an object to a different position on the screen. You can translate a point in 2D by adding translation coordinate (tx, ty ) to the original coordinate (X, Y) to get the new coordinate (X’, Y’). From the above figure, you can write that − X’ = X + tx Y’ = Y + ty The pair (tx, ty ) is called the translation vector or shift vector. The above equations can also be represented using the column vectors. We can write it as − P’ = P + T
  • 8. 4) REFLECTION In a plane geometry, to find the reflection of a point drop a perpendicular from the point to the line (plane) used for reflection, and extend it the same distance on the other side. To find the reflection of a figure, reflect each point in the figure. The matrix for a reflection is orthogonal with determinant −1 and eigenvalues −1, 1, 1, ..., 1. The product of two such matrices is a special orthogonal matrix that represents a rotation. Every rotation is the result of reflecting in an even number of reflections in hyperplanes through the origin, and every improper rotation is the result of reflecting in an odd number. Thus reflections generate the orthogonal group, and this result is known as the Cartan– Dieudonné theorem. To reflect a vector about a line that goes through the origin, let be a vector in the direction of the line: Orthogonal projection To project a vector orthogonally onto a line that goes through the origin, let be a vector in the direction of the line. Then use the transformation matrix: As with reflections, the orthogonal projection onto a line that does not pass through the origin is an affine, not linear, transformation. Parallel projections are also linear transformations and can be represented simply by a matrix. However, perspective projections are not, and to represent these with a matrix, homogeneous coordinates must be used. 5) ROTATION: A motion of a Euclidean space is the same as its isometry: it leaves the distance between any two points unchanged after the transformation. But a (proper) rotation also has to preserve the orientation structure. The "improper rotation" term refers to isometries that
  • 9. reverse (flip) the orientation. In the language of group theory the distinction is expressed as direct vs. indirect isometries in the Euclidean group, where the former comprise the identity component. Any direct Euclidean motion can be represented as a composition of a rotation about the fixed point and a translation. In two dimensions, to carry out a rotation using a matrix the point (x, y) to be rotated counterclockwise is written as a column vector, then multiplied by a rotation matrix calculated from the angle, θ: where (x′, y′) are the coordinates of the point that after rotation, and the formulae for x′ and y′ can be seen to be The vectors have the same magnitude and are separated by an angle θ as expected. Points on the R2 plane can be also presented as complex numbers: the point (x, y) in the plane is represented by the complex number This can be rotated through an angle θ by multiplying it by eiθ, then expanding the product using Euler's formula as follows: and equating real and imaginary parts gives the same result as a two-dimensional matrix: Since complex numbers form a commutative ring, vector rotations in two dimensions are commutative, unlike in higher dimensions. They have only one degree of freedom, as such rotations are entirely determined by the angle of rotation.
  • 10. 3D TRANSFORMATION: 1) REFLEXION: To reflect a point through a plane ax+by+cz=0 (which goes through the origin), one can use , where I is the 3x3 identity matrix and N is the three- dimensional unit vector for the vector normal of the plane. If the L2 norm of a, b and c is unity, the transformation matrix can be expressed as: 2) Note that these are particular cases of a Householder reflection in two and three dimensions. A reflection about a line or plane that does not go through the origin is not a linear transformation — it is an affine transformation — as a 4x4 affine transformation matrix, it can be expressed as follows (assuming the normal is a unit vector): Where d=p.N for some point p on the plane. If the 4th component of the vector is 0 instead of 1, then only the vector's direction is reflected and its length remains unchanged, as if it were mirrored through a parallel plane that passes through the origin. 2) SCALING: In Euclidean geometry, uniform scaling (or isotropic scaling) is a linear transformation that enlarges (increases) or shrinks (diminishes) objects by a scale factor that is the same in all directions. The result of uniform scaling is similar (in the geometric sense) to the original. A scale factor of 1 is normally allowed, so that congruent shapes are also classed as similar. Uniform scaling happens, for example, when enlarging or reducing a photograph, or when creating a scale model of a building, car, airplane, etc. A scaling can be represented by a scaling matrix. To scale an object by a vector v = (vx, vy, vz), each point p = (px, py, pz) would need to be multiplied with this scaling matrix:
  • 11. As shown below, the multiplication will give the expected result: Such a scaling changes the diameter of an object by a factor between the scale factors, the area by a factor between the smallest and the largest product of two scale factors, and the volume by the product of all three. The scaling is uniform if and only if the scaling factors are equal (vx = vy = vz). If all except one of the scale factors are equal to 1, we have directional scaling. In the case where vx = vy = vz = k, scaling increases the area of any surface by a factor of k2 and the volume of any solid object by a factor of k3 . 3) SHEAR: A transformation that slants the shape of an object is called the shear transformation. Like in 2D shear, we can shear an object along the X-axis, Y-axis, or Z-axis in 3D. As shown in the above figure, there is a coordinate P. You can shear it to geta new coordinate P', which can be represented in 3D matrix form as below –
  • 12. 4) TRANSLATION: A translation is an affine transformation with no fixed points. Matrix multiplications always have the origin as a fixed point. Nevertheless, there is a common workaround using homogeneous coordinates to represent a translation of a vector space with matrix multiplication: Write the 3-dimensional vector w = (wx, wy, wz) using 4 homogeneous coordinates as w = (wx, wy, wz, 1). To translate an object by a vector v, each homogeneous vector p (written in homogeneous coordinates) can be multiplied by this translation matrix: As shown below, the multiplication will give the expected result: The inverse of a translation matrix can be obtained by reversing the direction of the vector: Similarly, the product of translation matrices is given by adding the vectors:
  • 13. Because addition of vectors is commutative, multiplication of translation matrices is therefore also commutative (unlike multiplication of arbitrary matrices). 5) ROTATION: As in two dimensions, a matrix can be used to rotate a point (x, y, z) to a point (x′, y′, z′). The matrix used is a 3×3 matrix, 6) This is multiplied by a vector representing the point to give the result 7) The set of all appropriate matrices together with the operation of matrix multiplication is the rotation group SO(3). The matrix A is a member of the three-dimensional special orthogonal group, SO(3), that is it is an orthogonal matrix with determinant 1. That it is an orthogonal matrix means that its rows are a set of orthogonal unit vectors (so they are an orthonormal basis) as are its columns, making it simple to spot and check if a matrix is a valid rotation matrix.
  • 14. Problem Statement: Write a program in C to show the effect of reflection, scaling, shear, translation and rotation on a point in 2D and 3D. Also write a program in C to show the effect of reflection, scaling, shear, translation and rotation on an object in 2D.
  • 15. ALGORITHM 1. Start 2. Ask whether 2d or 3d point For 2D: 3. Take x and y coordinates as input from user 4. Reflection a. Across the origin i. x’=-x , y’=-y ii. print(x’,y’) b. Across y=x line i. x’=y , y'=x ii. print(x’,y’) c. About Y axis i. x’=-x , y’=y ii. print(x’,y’) d. About X axis iii. x’=x , y’=-y iv. print(x’,y’) 5. Shear Transformation i. Take shear coefficients a & b ii. x’=x+ay , y’=y+bx iii. print(x’,y’) 6. Scaling i. Take scaling factor input a & b ii. x’=x*a , y=y*b iii. print(x’,y’) 7. Translation i. Take translation input a & b ii. x’=x+a , y’=y+b iii. print(x’,y’) 8. Rotation i. Take angle in radians as input (ang) ii. x’=x*cos(ang) , y’=y*sin(ang)
  • 16. iii. print(x’,y’) For 3d: 3. Take x,y,z coordinates as input from user 4. Reflection a. Across the origin i. x’=-x , y’=-y ,z’=-z ii. print(x’,y’,z’) b. Across xy plane i. x’=x , y'=y , z’=-z ii. print(x’,y’,z’) c. Across xz plane i. x’=x , y'=-y , z’=z ii. print(x’,y’,z’) d. Across yz plane i. x’=-x , y'=y , z’=z ii. print(x’,y’,z’) e. About Y axis i. x’=-x , y’=y , z’=-z ii. print(x’,y’,z’) f. About X axis
  • 17. i. x’=x , y’=-y , z’=-z ii. print(x’,y’,z’) 5. Shear Transformation i. Take shear coefficients a & b ii. Sheared points in xy plane are x’= x + a*y , y’= y + b*x , z’=z iii. Sheared points in yz plane are x’=x , y’=y+az , z’=z+bz iv. Sheared points in xz plane are x’=x+bz , y’=y , z’=z+ax iii. print(x’,y’,z’) 6. Scaling i. Take scaling factor input a , b and c ii. x’=x*a , y=y*b ,z=z*c iii. print(x’,y’,z’) 7. Translation i. Take translation input a ,b and c ii. x’=x+a , y’=y+b , z’=z+c iii. print(x’,y’,z’) 8. Rotation i. Take angle in radians as input (ang) ii. z-axis rotation : x’= x*cos(ang) - y*sin(ang) y’= y*cos(ang) + x*sin(ang) z’=z iii. x-axis rotation : x’= x
  • 18. y’= y*cos(ang) - z*sin(ang) z’=y* sin(ang) + z*cos(ang) iv. y-axis rotation : x’= z*sin(ang) + x*cos(ang) y’= y z’= -x*sin(ang) + z*cos(ang) v. print(x’,y’,z’)
  • 19. CODING #include <stdio.h> #include <math.h> #include <stdlib.h> int main(void) { int choice,option,type,type_ref,scale_x,scale_y,scale_z,a,b,c; float x,y,z,ang,x_she,y_she; system("COLOR 0A"); printf("nnnt Enter the corrosponding number to go through that:"); printf("nnnnntSelect the type of operation(1 for points and 2 for object) : "); scanf("%d" , &choice); switch(choice) { case 1: system("cls"); system("COLOR 0B"); printf("nnnnttEnter the type of point(2 for 2D or 3 for 3D) : "); scanf("%d" , &option); switch(option) {
  • 20. case2: system("COLOR 0C"); printf("nnntttEnter the type of transformationnntttt 1 for reflectionntttt 2 for scaling ntttt 3 for shear ntttt 4 for translation ntttt 5 for rotation) : "); scanf("%d" , &type); switch(type) { case 1: system("cls"); system("COLOR 0D"); printf("nnnnnnttttYou have chosen Reflection.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); system("COLOR 0E"); printf("nnntttEnter the type of reflection : nnttt 1 across origin nttt 2 across y=x line nttt 3 across across axes "); scanf("n%d" , &type_ref); switch(type_ref) { case 1:
  • 21. system("cls"); system("COLOR 2E"); printf("nnnnntttThe reflection across the origin isnntttttx'= %.2fnttttty'= %.2f.n" , -x , -y); break; case 2: system("cls"); system("COLOR 2E"); printf("nnnnntttThe reflection across y=x line isnntttt x'=%.2fntttt y'=%.2f.n" , y , x); break; case 3: system("cls"); system("COLOR 2E"); printf("nnnnntThe reflection across x-axis isnnttttx'= %.2fntttty'= %.2f.n" , x , -y); printf("ntThe reflection across y-axis isnnttttx'= %.2fntttty'= %.2f.n" , -x , y); break; default: system("cls");
  • 22. system("COLOR 2E"); printf("nnnnntttt|| Invalid Input.||n"); break; }; break; case2: system("cls"); system("COLOR 0F"); printf("nnnnnnttttYou have chosen Scalingn"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nnttEnter the scaling for x and y point :nntttscale of x= "); scanf("%d" ,&scale_x); printf("ntttscaleof y= "); scanf("%d" ,&scale_y); system("cls"); system("COLOR 4F"); printf("nnnnntttThe points after scaling are:nnttttx'= %.2fntttty'= %.2f.n" , (scale_x*x) , (scale_y*y)) ;
  • 23. break; case 3: system("cls"); system("COLOR 1A"); printf("nnnnnntttYou have chosen Shear transformation.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nnttEnter shear coefficients a and b( x = x + ay , y = y + bx): "); scanf("%d %d" , &a , &b); x_she = x + y*a; y_she= y + x*b; system("cls"); system("COLOR 3F"); printf("nnnnntttSheared points are: nnttttx'= %.2fntttty'= %.2f.n" , x_she , y_she); break; case 4: system("cls"); system("COLOR 6E"); printf("nnnnnntttYou have chosen translation.n");
  • 24. printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nntttEnter translation distance for x and y: "); scanf("%d %d" , &a , &b); system("cls"); system("COLOR 5C"); printf("nnnnntttTranslated points are: nnttttx'= %.2fntttty'= %.2f.n" , (x + a) , (y + b) ); break; case5: system("cls"); system("COLOR 7F"); printf("nnnnnnttttYou have chosen rotation.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nnnttEnter angle in radians for rotation in x and y :nttttt "); scanf("%f" , &ang); system("cls");
  • 25. system("COLOR 8E"); printf("nnnnntttThe rotated coordinates are: nnttttx'= %.2fntttty'= %.2f.n" , (x*cos(ang) - y*sin(ang)) , (y*cos(ang) + x*sin(ang)) ); break; default: system("cls"); system("COLOR 2E"); printf("nnnnntttt|| Invalid Input.||n"); break; } break; case 3: system("COLOR 0E"); printf("nnntttEnter the type of transformationnntttt 1 for reflectionntttt 2 for scaling ntttt 3 for shear ntttt 4 for translation ntttt 5 for rotation) : "); scanf("%d" , &type); switch(type) { case 1: system("cls"); system("COLOR 0D"); printf("nnnnnnttttYou have chosen Reflection.n");
  • 26. printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nttttEnter z coordinate : "); scanf("%f" , &z); printf("nnntttEnter the type of reflection :nnttt 1 across origin nttt 2 across planes nttt 3 across axes) : "); scanf("n%d" , &type_ref); switch(type_ref) { case 1: system("cls"); system("COLOR 2E"); printf("nnnnntttThe reflection across the origin isnntttttx'= %.2f nttttty'= %.2fntttttz'= %.2fn" , -x , -y , -z); break; case 2: system("cls"); system("COLOR 2E"); printf("nnntttThe reflection across xy plane isnttttx'= %.2fntttty'= %.2f nttttz'= %.2f.n" , x , y , -z);
  • 27. printf("ntttThe reflection across yz plane isnttttx'= %.2f ntttty'= %.2f nttttz'= %.2f.n" , -x , y , z); printf("ntttThe reflection across xz plane isnttttx'= %.2f ntttty'= %.2f nttttz'= %.2f.n" , x , -y , z); break; case 3: system("cls"); system("COLOR 2E"); printf("nnnnnttThe reflection across x-axis is nttttx'= %.2f ntttty'= %.2f nttttz'= %.2f.n" , x , -y , -z); printf("nttThe reflection across y-axis is nttttx'= %.2fntttty'= %.2f nttttz'= %.2f.n" , -x , y , -z); printf("nttThe reflection across z-axis is nttttx'= %.2f ntttty'= %.2f nttttz'= %.2f.n" , -x , -y , z); break; default: system("cls"); system("COLOR 2E"); printf("nnnnntttt|| Invalid Input.||n"); }; break; case2: system("cls");
  • 28. system("COLOR 0F"); printf("nnnnnnttttYou have chosen Scalingn"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nttttEnter z coordinate : "); scanf("%f" , &z); printf("nnttEnter the scaling for x, y and z point :nntttscaleof x= "); scanf("%d" ,&scale_x); printf("ntttscaleof y= "); scanf("%d" ,&scale_y); printf("ntttscaleof z= "); scanf("%d" ,&scale_z); system("cls"); system("COLOR 4F"); printf("nnnnntttThe points after scaling are:nnttttx'= %.2fntttty'= %.2fnttttz'= %.2f.n" , (scale_x*x) , (scale_y*y) , (scale_z*z) ) ; break; case3: system("cls");
  • 29. system("COLOR 1A"); printf("nnnnnntttYou have chosen Shear transformation.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nttttEnter z coordinate : "); scanf("%f" , &z); printf("nnttEnter shear coefficients a and b( x = x + ay , y = y + bx): "); scanf("%d %d" , &a , &b); system("cls"); system("COLOR 3F"); printf("nnntttSheared points in xy plane are nttttx'= %.2f ntttty'= %.2f nttttz'=%.2f.n" , x + a*y , y + b*x , z); printf("nntttSheared points in yz plane are nttttx'= %.2f ntttty'= %.2f nttttz'=%.2f.n" , x , y + a*z , z + b*y); printf("nntttjSheared points in zx plane are nttttx'= %.2f ntttty'= %.2f nttttz'=%.2f.n" , x + b*z , y , z + a*x); break; case4: system("cls"); system("COLOR 6E");
  • 30. printf("nnnnnntttYou have chosen translation.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : "); scanf("%f" , &y); printf("nttttEnter z coordinate : "); scanf("%f" , &z); printf("Enter translation distance for x,yand z: "); scanf("%d %d %d" , &a , &b , &c); system("cls"); system("COLOR 5C"); printf("nnnnntttTranslated points are: nnttttx'= %.2fntttty'= %.2f.nttttz'=%.2f" , (x + a) , (y + b) , (z + c) ); break; case5: system("cls"); system("COLOR 7F"); printf("nnnnnnttttYou have chosen rotation.n"); printf("nnttttEnter x coordinate : "); scanf("%f" , &x); printf("nttttEnter y coordinate : ");
  • 31. scanf("%f" , &y); printf("nttttEnter z coordinate : "); scanf("%f" , &z); printf("nnntEnter anglein radians for rotation in x,y and z :nttttt "); scanf("%f" , &ang); system("cls"); system("COLOR 8E"); printf("nnntttCoordinates after z-axis rotation are nnttttx'= %.2f ntttty'= %.2fz'= %.2f.n" , (x*cos(ang) - y*sin(ang)) , (y*cos(ang)+ x*sin(ang)), z); printf("nntttCoordinates after x-axis rotation arennttttx'= %.2f ntttty'= %.2fz'= %.2f.n" , x , (y*cos(ang) - z*sin(ang)) , (y*sin(ang) + z*cos(ang))); printf("nntttCoordinates after y-axis rotation are nnttttx'= %.2fntttty'= %.2fz'= %.2f.n" , (z*sin(ang) + x*cos(ang)) , y , (-x*sin(ang) + z*cos(ang))); break; default: system("cls"); system("COLOR 2E"); printf("nnnnntttt|| Invalid Input.||n"); } break;} break;}
  • 32. REFERENCES 1. “ANSI C” by Balaguruswami. 2. Let us “C” by Kanetkar. 3. www.wikipedia.org