0% found this document useful (0 votes)
131 views7 pages

The Below Programs Are For 2D Transformation. This Is A Part of Mumbai University MCA Colleges Computer Graphics MCA Sem 2

This document contains code samples for 2D transformations including translation, rotation, and scaling. It provides C code to perform translation by adding offsets to x and y coordinates, rotation by applying rotation matrices, and scaling by multiplying x and y coordinates. The code is intended for a Mumbai University MCA computer graphics course on 2D transformations.

Uploaded by

Monish Narwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views7 pages

The Below Programs Are For 2D Transformation. This Is A Part of Mumbai University MCA Colleges Computer Graphics MCA Sem 2

This document contains code samples for 2D transformations including translation, rotation, and scaling. It provides C code to perform translation by adding offsets to x and y coordinates, rotation by applying rotation matrices, and scaling by multiplying x and y coordinates. The code is intended for a Mumbai University MCA computer graphics course on 2D transformations.

Uploaded by

Monish Narwani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programs

MCA Syllabus

HSC What next?

About Us

Contact Us

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:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
void main()
{
int graphdriver=DETECT,graphmode,errorcode;
int i;
int x2,y2,x1,y1,x,y;
printf("Enter the 2 line end points:");
printf("x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
line(x1,y1,x2,y2);
printf("Enter translation co-ordinates ");
printf("x,y");
scanf("%d%d",&x,&y);
x1=x1+x;
y1=y1+y;
x2=x2+x;
y2=y2+y;
printf("Line after translation");
line(x1,y1,x2,y2);
getch();
closegraph();

2D Rotation:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
void main()
{
int graphdriver=DETECT,graphmode,errorcode;
int i;
int x2,y2,x1,y1,x,y,xn,yn;
double r11,r12,r21,r22,th;
clrscr();
printf("Enter the 2 line end points:");
printf("x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
line(x1,y1,x2,y2);
printf("\n\n\n[ Enter the angle");
scanf("%lf",&th);
r11=cos((th*3.1428)/180);
r12=sin((th*3.1428)/180);
r21=(-sin((th*3.1428)/180));
r22=cos((th*3.1428)/180);
//printf("%lf %lf %lf %lf",r11,r12,r21,r22);
xn=((x2*r11)-(y2*r12));
yn=((x2*r12)+(y2*r11));
line(x1,y1,xn,yn);
getch();
closegraph();
}

2D Scaling:
#include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
void main()
{
int graphdriver=DETECT,graphmode,errorcode;
int i;
int x2,y2,x1,y1,x,y;
printf("Enter the 2 line end points:");
printf("x1,y1,x2,y2");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
initgraph(&graphdriver,&graphmode,"c:\\tc\\bgi");
line(x1,y1,x2,y2);
printf("Enter scaling co-ordinates ");
printf("x,y");
scanf("%d%d",&x,&y);
x1=(x1*x);
y1=(y1*y);
x2=(x2*x);
y2=(y2*y);
printf("Line after scaling");
line(x1,y1,x2,y2);
getch();
closegraph();
}

Hope this Program is useful to you in some sense or other. Keep


on following this blog for more Mumbai University MCA
College Programs. Happy Programming and Studying.
Email ThisBlogThis!Share to TwitterShare to FacebookShare to Pinterest
No comments:
Post a Comment

Post a Comment
Newer Post Older Post Home
Subscribe to: Post Comments (Atom)
Download

Browse

2012 (75)

2011 (64)

2010 (44)
o December 2010 (16)
o November 2010 (14)

Sutherland-Hodgeman Polygon Clipping

2D Transformations 1 program

Mid Point Ellipse Drawing Algorithm

Character Generation Computer Graphics

Liang-Barsky Algorithm CG

Cohen-Sutherland Algorithm

Cohen-Sutherland Line Clipping

3D Transformations, Translation, Rotation, Scaling...

2D Transformation Translation Rotation Scaling

Display File Creation CG

line drawing using DDA algorithm

Normalized to Actual coordinates conversion

Animation/Movement of Circles Graphics

Bresenhams Line Drawing Algorithm

o October 2010 (1)


o March 2010 (13)

Total Pageviews
795,936

Contributors

SS Sagar

Siddhesh Shetye

Mukesh Patidar

Interesting

Data Structure

UML Diagrams

Data Communication And networking

Computer Graphics

Interview Questions

Popular Posts

UML Diagrams Library Management System


UML Diagrams for ATM Machine

Template images by dino4. Powered by Blogger.

You might also like