Overview of Transformations (18 marks) In many applications, changes in orientations, size, and shape are accomplished with

Similar documents
//2D TRANSFORMATION TRANSLATION, ROTATING AND SCALING. #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<stdlib.

UNIT 2 2D TRANSFORMATIONS

SE Mock Online Retest 2-CG * Required

Chapter 8 Three-Dimensional Viewing Operations

Chapter 5. Projections and Rendering

Introduction to Computer Graphics 4. Viewing in 3D

Windowing And Clipping (14 Marks)

So we have been talking about 3D viewing, the transformations pertaining to 3D viewing. Today we will continue on it. (Refer Slide Time: 1:15)

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Coordinate transformations. 5554: Packet 8 1

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Content. Coordinate systems Orthographic projection. (Engineering Drawings)

Computer Graphics. P05 Viewing in 3D. Part 1. Aleksandra Pizurica Ghent University

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Computer Graphics Viewing

MET71 COMPUTER AIDED DESIGN

2D and 3D Transformations AUI Course Denbigh Starkey

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

MAE : Lecture #12 - Projection and Perspective. Lecture Overview:

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

ME-430 Introduction to CAD Lecture Notes- Part 3

Computer Graphics 7: Viewing in 3-D

Computer Graphics: Geometric Transformations

Arrays in C. By Mrs. Manisha Kuveskar.

Specifying Complex Scenes

MATHEMATICS FOR ENGINEERING TUTORIAL 5 COORDINATE SYSTEMS

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Computer Vision cmput 428/615

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

Computer Graphics Solved MCQs -Part 2 MCQs Questions

Object Representation Affine Transforms. Polygonal Representation. Polygonal Representation. Polygonal Representation of Objects

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Chap 7, 2008 Spring Yeong Gil Shin

Two Dimensional Viewing

Interactive Computer Graphics. Hearn & Baker, chapter D transforms Hearn & Baker, chapter 5. Aliasing and Anti-Aliasing

CALCULATING TRANSFORMATIONS OF KINEMATIC CHAINS USING HOMOGENEOUS COORDINATES

CS452/552; EE465/505. Models & Viewing

LAB MANUAL OF COMPUTER GRAPHICS BY: Mrs. Manisha Saini

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Lecture 6 Sections 4.3, 4.6, 4.7. Wed, Sep 9, 2009

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

Computer Graphics. Jeng-Sheng Yeh 葉正聖 Ming Chuan University (modified from Bing-Yu Chen s slides)

Part 3: 2D Transformation

CSE328 Fundamentals of Computer Graphics

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

Game Engineering: 2D

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

Projection Lecture Series

Vector Algebra Transformations. Lecture 4

Answers to practice questions for Midterm 1

Three-Dimensional Viewing Hearn & Baker Chapter 7

Viewing with Computers (OpenGL)

CS 4204 Computer Graphics

THE VIEWING TRANSFORMATION

2D TRANSFORMATIONS AND MATRICES

2D Object Definition (1/3)

Lesson 5.6: Angles in Standard Position

Computer Graphics Hands-on

Lecture 4: Transforms. Computer Graphics CMU /15-662, Fall 2016

2D Image Transforms Computer Vision (Kris Kitani) Carnegie Mellon University

LINE,CIRCLE AND ELLIPSE DRAWING USING BRESENHAM S ALGORITHM

Computer Graphics Geometric Transformations

Mathematics (

Supplementary Material: The Rotation Matrix

DDA ALGORITHM. To write a C program to draw a line using DDA Algorithm.

COMP Computer Graphics and Image Processing. a6: Projections. In part 2 of our study of Viewing, we ll look at. COMP27112 Toby Howard

Parallel and perspective projections such as used in representing 3d images.

Figure 1. Lecture 1: Three Dimensional graphics: Projections and Transformations

Section III: TRANSFORMATIONS

Shadows in Computer Graphics

SIR C.R.R COLLEGE OF ENGINEERING, ELURU.

Chap 7, 2009 Spring Yeong Gil Shin

UNIT 3 2D TRANSFORMATIONS Unit-03/Lecture-01

February 1. Lab Manual INSTITUTE OF INFORMATION TECHNOLOGY & MANAGEMENT GWALIOR COMPUTER GRAPHICS & MUTIMEDIA

Technical Arts 101 Prof. Anupam Saxena Department of Mechanical engineering Indian Institute of Technology, Kanpur. Lecture - 7 Think and Analyze

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Math 7 Elementary Linear Algebra PLOTS and ROTATIONS

About Graphing Lines

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

Computer Graphics: Viewing in 3-D. Course Website:

Game Engineering CS S-05 Linear Transforms

Last week. Machiraju/Zhang/Möller/Fuhrmann

MATRIX REVIEW PROBLEMS: Our matrix test will be on Friday May 23rd. Here are some problems to help you review.

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Chapter 2 - Basic Mathematics for 3D Computer Graphics

1. DDA Algorithm(Digital Differential Analyzer)

Game Engineering CS S-07 Homogenous Space and 4x4 Matrices

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

CSC 470 Computer Graphics. Three Dimensional Viewing

3.0 Trigonometry Review

CSC 470 Computer Graphics

PreCalculus Unit 1: Unit Circle Trig Quiz Review (Day 9)

MODULE - 7. Subject: Computer Science. Module: Other 2D Transformations. Module No: CS/CGV/7

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Transcription:

Two Dimensional Transformations In many applications, changes in orientations, size, and shape are accomplished with geometric transformations that alter the coordinate descriptions of objects. Basic geometric transformations are: These are most useful and most commonly used. Translation (Position Rotation (Orientation) Scaling (Size) Other transformations: These transformations are useful in certain applications. Reflection (Mirror) Shear (Size) 2D Translation: - Moves points to new locations by adding translation amounts to the coordinates of the points. Initial Position point P (x, y) The new point P (x, y ) Where, x = x + tx y = y + ty tx and ty is the displacement in x and y respectively. The translation pair (tx, ty) is called a translation vector or shift vector.

Matrix representation OR P = P + T PROGRAM: Write a program for 2D Translation of a Triangle. #include<stdio.h> #include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> int x1,y1,x2,y2,x3,y3,mx,my; void draw(); void tri(); void main() int gd=detect,gm; int c; initgraph(&gd,&gm,"c:\\turboc3\\bgi "); printf("enter the 1st point for the triangle:"); scanf("%d%d",&x1,&y1); printf("enter the 2nd point for the triangle:"); scanf("%d%d",&x2,&y2); printf("enter the 3rd point for the triangle:"); scanf("%d%d",&x3,&y3); cleardevice(); draw(); getch(); tri(); getch(); void draw() line(x1,y1,x2,y2);

line(x2,y2,x3,y3); line(x3,y3,x1,y1); void tri() int x,y,a1,a2,a3,b1,b2,b3; printf("enter the Transaction coordinates"); scanf("%d%d",&x,&y); cleardevice(); a1=x1+x; b1=y1+y; a2=x2+x; b2=y2+y; a3=x3+x; b3=y3+y; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); Rotation: Default rotation center: Origin (0,0) Rotation is applied to an object by repositioning it along a circular path in the xy plane. To generate a rotation, we specify Rotation angle θ Pivot point ( xr, yr) Positive values of θ for counterclockwise rotation Negative values of θ for clockwise rotation. (x,y) -> Rotate about the origin by θ" -> (x, y )

x = r cos (φ) y = r sin (φ) x = r cos (φ + θ) y = r sin (φ + θ) x = r cos (φ + θ) = r cos(φ) cos(θ) r sin(φ) sin(θ) = x cos(θ) y sin(θ) y = r sin (φ + θ) = r sin(φ) cos(θ) + r cos(φ)sin(θ) = y cos(θ) + x sin(θ) So, x = x cos(θ) y sin(θ) and y = y cos(θ) + x sin(θ) Representing the above equation in matrix form, OR Where R is the rotation matrix P = P. R For positive rotation angle, we can use the above rotation matrix. However, for negative angle rotation, the matrix will change as shown below Program:

Write a program for 2D Rotation of a Triangle #include<stdio.h> #include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> void triangle(int x1,int y1,int x2,int y2,int x3,int y3); void Rotate(int x1,int y1,int x2,int y2,int x3,int y3); void main() int gd=detect,gm; int x1,y1,x2,y2,x3,y3; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("enter the 1st point for the triangle:"); scanf("%d%d",&x1,&y1); printf("enter the 2nd point for the triangle:"); scanf("%d%d",&x2,&y2); printf("enter the 3rd point for the triangle:"); scanf("%d%d",&x3,&y3); triangle(x1,y1,x2,y2,x3,y3); getch(); cleardevice(); Rotate(x1,y1,x2,y2,x3,y3); setcolor(1); triangle(x1,y1,x2,y2,x3,y3); getch(); void triangle(int x1,int y1,int x2,int y2,int x3,int y3) line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); void Rotate(int x1,int y1,int x2,int y2,int x3,int y3) int x,y,a1,b1,a2,b2,a3,b3,p=x2,q=y2; float Angle; printf("enter the angle for rotation:"); scanf("%f",&angle); cleardevice(); Angle=(Angle*3.14)/180; a1=p+(x1-p)*cos(angle)-(y1-q)*sin(angle); b1=q+(x1-p)*sin(angle)+(y1-q)*cos(angle); a2=p+(x2-p)*cos(angle)-(y2-q)*sin(angle); b2=q+(x2-p)*sin(angle)+(y2-q)*cos(angle); a3=p+(x3-p)*cos(angle)-(y3-q)*sin(angle);

b3=q+(x3-p)*sin(angle)+(y3-q)*cos(angle); printf("rotate"); triangle(a1,b1,a2,b2,a3,b3); 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. Let us assume that the original coordinates are (X, Y), the scaling factors are (S X, S Y ), and the produced coordinates are (X, Y ). This can be mathematically represented as shown below 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. scaling matrix form as below 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. Program: #include<stdio.h> Write a program for 2D Scaling of a Triangle

#include<conio.h> #include<graphics.h> #include<process.h> #include<math.h> int x1,y1,x2,y2,x3,y3,mx,my; void draw(); void scale(); void main() int gd=detect,gm; int c; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("enter the 1st point for the triangle:"); scanf("%d%d",&x1,&y1); printf("enter the 2nd point for the triangle:"); scanf("%d%d",&x2,&y2); printf("enter the 3rd point for the triangle:"); scanf("%d%d",&x3,&y3); draw(); scale(); void draw() line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); void scale() int x,y,a1,a2,a3,b1,b2,b3; int mx,my; printf("enter the scalling coordinates"); scanf("%d%d",&x,&y); mx=(x1+x2+x3)/3; my=(y1+y2+y3)/3; cleardevice(); a1=mx+(x1-mx)*x; b1=my+(y1-my)*y; a2=mx+(x2-mx)*x; b2=my+(y2-my)*y; a3=mx+(x3-mx)*x; b3=my+(y3-my)*y; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); draw(); getch();

Homogeneous coordinates: In design and picture formation process, many times require to perform translation, rotations and scaling to fit the picture components into their proper positions. General matrix form: For Translation: For rotation: For Scaling: (To produce sequence of transformation with above equations, such as translation followed by rotation and then scaling, the calculation of transformed coordinates one step at a time. To combine sequence of transformations into one transformation so that final coordinate

positions are obtained directly from initial coordinates. This eliminates the calculation of intermediate coordinate values.) To perform a sequence of transformation such as translation followed by rotation and scaling, we need to follow a sequential process Translate the coordinates, Rotate the translated coordinates, and then Scale the rotated coordinates to complete the composite transformation. To shorten this process, we have to use 3 3 transformation matrix instead of 2 2 transformation matrix. To convert a 2 2 matrix to 3 3 matrix, we have to add an extra dummy coordinate W. In this way, we can represent the point by 3 numbers instead of 2 numbers, which is called Homogenous Coordinate system. In this system, we can represent all the transformation equations in matrix multiplication. Any Cartesian point P(X, Y) can be converted to homogenous coordinates by P (X h, Y h, h). Homogeneous coordinates for translation: So Homogeneous coordinates for Rotation:

So Homogeneous coordinates for Scaling: Therefore we have, Reflection:

Reflection is the mirror image of original object. In other words, we can say that it is a rotation operation with 180. In reflection transformation, the size of the object does not change. The examples of some common reflections are:

Program : #include<stdio.h> #include<process.h> #include<conio.h> #include<graphics.h> #include<math.h> TO PERFORM 2D TRANSFORMATIONS (REFLECTION)

void disp(int n,float c[][3]) float maxx,maxy; int i; maxx=getmaxx(); maxy=getmaxy(); maxx=maxx/2; maxy=maxy/2; i=0; while(i<n-1) line(maxx+c[i][0],maxy-c[i][1],maxx+c[i+1][0],maxy-c[i+1][1]); i++; i=n-1; line(maxx+c[i][0],maxy-c[i][1],maxx+c[0][0],maxy-c[0][1]); setcolor(green); line(0,maxy,maxx*2,maxy); line(maxx,0,maxx,maxy*2); setcolor(white); void mul(int n,float b[][3],float c[][3],float a[][3]) int i,j,k; for(i=0;i<n;i++) for(j=0;j<3;j++) a[i][j]=0; for(i=0;i<n;i++) for(j=0;j<3;j++) for(k=0;k<3;k++) a[i][j] = a[i][j] + (c[i][k] * b[k][j]); void reflection(int n,float c[][3]) float b[10][3],a[10][3]; int i=0,ch,j; cleardevice(); printf("\n\t* * MENU * *"); printf("\n\t1) ABOUT X-AXIS"); printf("\n\t2) ABOUT Y-AXIS"); printf("\n\t3) ABOUT ORIGIN"); printf("\n\t4) ABOUT X=Y"); printf("\n\t5) ABOUT -X=Y");

printf("\n\t6) EXIT "); printf(" \n\tenter YOUR CHOICE : "); scanf("%d",&ch); clrscr(); cleardevice(); disp(n,c); for(i=0;i<3;i++) for(j=0;j<3;j++) b[i][j]=0; if(i==j) b[i][j]=1; switch(ch) case 1: b[1][1]=-1; break; case 2: b[0][0]=-1; break; case 3: b[0][0]=-1; b[1][1]=-1; break; case 4: b[0][0]=0; b[1][1]=0; b[0][1]=1; b[1][0]=1; break; case 5: b[0][0]=0; b[1][1]=0; b[0][1]=-1; b[1][0]=-1; break; case 6: break; default: printf(" \n\tinvalid CHOICE! "); break; mul(n,b,c,a); setcolor(red); disp(n,a); void main()

int i,j,k,cho,n,gd=detect,gm; float c[10][3],tx,ty,sx,sy,ra; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("\nenter the number of vertices : "); scanf("%d",&n); for(i=0;i<n;i++) printf("\nenter the co-ordinates of the %d vertex :",i+1); scanf("%f%f",&c[i][0],&c[i][1]); c[i][2]=1; disp(n,c); reflection(n,c); getch(); closegraph(); Shear: A transformation that slants the shape of an object is called the shear transformation. There are two shear transformations X-Shear and Y-Shear. One shift X coordinate s values and other shifts Y coordinate values. However in both the cases only one coordinate changes its coordinates and other preserves its values. X shear The X-Shear preserves the Y coordinate and changes are made to X coordinates, which causes the vertical lines to tilt right or left as shown in below figure.

a) original object b) object after x shear The transformation matrix for X-Shear can be represented as Y-Shear The Y-Shear preserves the X coordinates and changes the Y coordinates which causes the horizontal lines to transform into lines which slopes up or down as shown in the following figure a) original object b) object after y shear b) The Y-Shear can be represented in matrix from as

shearing relative to other reference line: In x shear transformation use y reference line and in y shear use x reference line. X shear with y reference line: y shear with x reference line: Program: //Shearing tranformation in C graphics #include<stdio.h> #include<graphics.h> #include<math.h> #include<conio.h> #include<dos.h> void mul(int mat[3][3],int vertex[10][3],int n); void shear(int vertex[10][3],int n); void init(int vertex[10][3],int n); int main() int i,x,y,xsh,ysh,xref,yref; int vertex[10][3],n; clrscr(); printf("\nenter the no. of vertex : "); scanf("%d",&n); for(i=0;i<n;i++)

points (x,y): "); scanf("%d%d",&x,&y); vertex[i][0]=x; vertex[i][1]=y; vertex[i][2]=1; shear(vertex,n); getch(); return 0; void init(int vertex[10][3],int n) int gd=detect,gm,i; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); setcolor(10); line(0,240,640,240); //drawing X axis line(320,0,320,480); //drawing Y axis setcolor(3); line(450,20,490,20); setcolor(15); line(450,50,490,50); setcolor(6); outtextxy(500,20,"original"); outtextxy(500,50,"transformed"); setcolor(3); printf("enter the for(i=0;i<n-1;i++) line(320+vertex[i][0],240-vertex[i][1],320+vertex[i+1][0],240- vertex[i+1][1]); line(320+vertex[n-1][0],240-vertex[n-1][1],320+vertex[0][0],240-vertex[0][1]); void mul(int mat[3][3],int vertex[10][3],int n) int i,j,k; // loop variables int res[10][3]; for(i=0;i<n;i++) for(j=0;j<3;j++) res[i][j]=0; for(k=0;k<3;k++) res[i][j] = res[i][j] + vertex[i][k]*mat[k][j];

setcolor(15); for(i=0;i<n-1;i++) line(320+res[i][0],240-res[i][1],320+res[i+1][0],240-res[i+1][1]); line(320+res[n-1][0],240-res[n-1][1],320+res[0][0],240-res[0][1]); void shear(int vertex[10][3],int n) int opt,xref,yref; int shear_array[3][3]; printf("\n1.x-shear\n2.y-shear\n3.x shear with yref\n4.y shear with xref\nyour Choice: "); scanf("%d",&opt); switch(opt) case 1: case 2: int xsh; printf("\nenter the x shear : "); scanf("%d",&xsh); shear_array[0][0]=1; shear_array[1][0]=xsh; shear_array[2][0]=0; shear_array[0][1]=0; shear_array[1][1]=1; shear_array[2][1]=0; shear_array[0][2]=0; shear_array[1][2]=0; shear_array[2][2]=1; init(vertex,n); mul(shear_array,vertex,n); break; int ysh; printf("\nenter the y shear : "); scanf("%d",&ysh); shear_array[0][0]=1; shear_array[1][0]=0; shear_array[2][0]=0; shear_array[0][1]=ysh; shear_array[1][1]=1; shear_array[2][1]=0; shear_array[0][2]=0; shear_array[1][2]=0; shear_array[2][2]=1;

case 3: case 4: init(vertex,n); mul(shear_array,vertex,n); break; printf("\nenter the y shear : "); scanf("%d",&ysh); printf("\nenter the x ref : "); scanf("%d",&xref); shear_array[0][0]=1; shear_array[1][0]=0; shear_array[2][0]=0; shear_array[0][1]=ysh; shear_array[1][1]=1; shear_array[2][1]=-ysh*xref; shear_array[0][2]=0; shear_array[1][2]=0; shear_array[2][2]=1; init(vertex,n); mul(shear_array,vertex,n); break; printf("\nenter the x shear : "); scanf("%d",&xsh); printf("\nenter the y ref: "); scanf("%d",&yref); shear_array[0][0]=1; shear_array[1][0]=xsh; shear_array[2][0]=-xsh*yref; shear_array[0][1]=0; shear_array[1][1]=1; shear_array[2][1]=0; shear_array[0][2]=0; shear_array[1][2]=0; shear_array[2][2]=1; init(vertex,n); mul(shear_array,vertex,n); break; Composite transformations The basic purpose of composing transformations is to gain efficiency by applying a single composed transformation to a point, rather than applying a series of transformation, one after another.

If a transformation of the plane T1 is followed by a second plane transformation T2, then the result itself may be represented by a single transformation T which is the composition of T1 and T2 taken in that order. This is written as T = T1 T2. For example, to rotate an object about an arbitrary point (X p, Y p ), we have to carry out three steps (T*R*T) Translate point (X p, Y p ) to the origin. Rotate it about the origin. Finally, translate the center of rotation back where it belonged. Rotation about arbitrary point: Suppose the reference point of rotation is other than origin, then in that case follow series of transformation. Assume that to rotate a point P1 with respect to (Xm, Ym) then perform three steps. I) Translation: First we have to translate the (Xm, Ym) to origin as shown in figure Translation matrix (T1) will become

3D Transformations Translation Offset Vector = (t x, t y, t z ) Program #include<stdio.h> #include<conio.h> #include<math.h> #include<process.h> #include<graphics.h> int x1,x2,y1,y2,mx,my,depth; void draw(); void trans(); void main() z y x t z z t y y t x x 1 0 1 0 0 0 0 1 0 0 0 0 1 1 1 z y x t t t z y x z y x

int gd=detect,gm,c; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("\n\t\t3d Translation\n\n"); printf("\nenter 1st top value(x1,y1):"); scanf("%d%d",&x1,&y1); printf("enter right bottom value(x2,y2):"); scanf("%d%d",&x2,&y2); depth=(x2-x1)/4; mx=(x1+x2)/2; my=(y1+y2)/2; draw(); getch(); cleardevice(); trans(); getch(); void draw() bar3d(x1,y1,x2,y2,depth,1); void trans() int a1,a2,b1,b2,dep,x,y; printf("\n Enter the Translation Distances:"); scanf("%d%d",&x,&y); a1=x1+x;

a2=x2+x; b1=y1+y; b2=y2+y; dep=(a2-a1)/4; bar3d(a1,b1,a2,b2,dep,1); setcolor(5); draw(); Scaling To change the size of an object using scaling transformation. In the scaling process, 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. The following figure shows the effect of 3D scaling In 3D scaling operation, three coordinates are used. Let us assume that the original coordinates are (X, Y, Z), scaling factors are (SX,SY,Sz) respectively, and the produced coordinates are (X, Y, Z ). This can be mathematically represented as shown below

Program: #include<stdio.h> #include<conio.h> #include<math.h> #include<process.h> #include<graphics.h> int x1,x2,y1,y2,mx,my,depth; void draw(); void scale(); void main() int gd=detect,gm,c; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); printf("\n\t\t3d Scaling\n\n"); printf("\nenter 1st top value(x1,y1):"); scanf("%d%d",&x1,&y1);

printf("enter right bottom value(x2,y2):"); scanf("%d%d",&x2,&y2); depth=(x2-x1)/4; mx=(x1+x2)/2; my=(y1+y2)/2; draw(); getch(); cleardevice(); scale(); getch(); void draw() bar3d(x1,y1,x2,y2,depth,1); void scale() int x,y,a1,a2,b1,b2,dep; printf("\n\n Enter scaling Factors:"); scanf("%d%d",&x,&y); a1=mx+(x1-mx)*x; a2=mx+(x2-mx)*x; b1=my+(y1-my)*y; b2=my+(y2-my)*y; dep=(a2-a1)/4; bar3d(a1,b1,a2,b2,dep,1);

setcolor(5); draw(); Rotation Program: #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> int maxx,maxy,midx,midy; void axis() getch(); cleardevice(); line(midx,0,midx,maxy);

line(0,midy,maxx,midy); void main() int x,y,z,o,x1,x2,y1,y2; int gd=detect,gm; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\turboc3\\bgi"); maxx=getmaxx(); maxy=getmaxy(); midx=maxx/2; midy=maxy/2; axis(); bar3d(midx+50,midy-100,midx+60,midy-90,5,1); printf("enter rotating angle"); scanf("%d",&o); x1=50*cos(o*3.14/180)-100*sin(o*3.14/180); y1=50*sin(o*3.14/180)+100*cos(o*3.14/180); x2=60*cos(o*3.14/180)-90*sin(o*3.14/180); y2=60*sin(o*3.14/180)+90*cos(o*3.14/180); axis(); printf("after rotation about z axis"); bar3d(midx+x1,midy-y1,midx+x2,midy-y2,5,1); axis(); printf("after rotation about x axis"); bar3d(midx+50,midy-x1,midx+60,midy-x2,5,1); axis(); printf("after rotation about yaxis"); bar3d(midx+x1,midy-100,midx+x2,midy-90,5,1); getch(); closegraph(); Types of projections After converting description of objects from world co-ordinates to viewing co-ordinates, project 3D objects into 2D view plane. There are two types of projection: 1. Parallel projection 2. Perspective projection

Parallel projection In parallel projection, z coordinate is discarded and parallel lines from each vertex on the object are extended until they intersect the view plane. The point of intersection is projection of the vertex. The parallel projection preserves relative proportions of objects but doesn t produce real objects. Types of parallel projections: Fig: Parallel projection of an object to the view plane a) Orthographic parallel projection:

In this projection, the direction of the projection is normal (perpendicular) to the view plane. Orthographic projections are further classified as axonometric and Multiview Orthographic projections. When Orthographic projections displays more than one face of an object then it becomes Axonometric Orthographic projections. Axonometric Orthographic projections are of three types: Isometric : all three principle axes are foreshortened equally. Dimetric : two principle axes are foreshortened equally. Trimetric : all three principle axes are foreshortened unequally. b) Oblique parallel projection: In this, the direction of projection is not perpendicular to view plane. The Oblique parallel projections are further divided into cabinet and cavalier projections.

For cavalier projection, the direction of projection makes 45 degree angle with view plane. For cabinet projection, the direction of projection makes 63.4 degree angle with view plane. Perspective projection Produces the realistic views but doesn t preserve relative proportions. Projections converge at center of projection Parallel lines (not parallel to the projection plan) on the object converge at a single point in the projection (the vanishing point). A vanishing point is a point on the image plane of a perspective drawing where the two-dimensional perspective projections of mutually parallel lines in three-dimensional space appear to converge. Three types of perspective projection Three-Point Perspective No principal face parallel to projection plane Three vanishing points for cube

Two-Point Perspective On principal direction parallel to projection plane Two vanishing points for cube One-Point Perspective One principal face parallel to projection plane One vanishing point for cube