Hello There, Guest! RegisterLogin with Facebook
Login with Facebook

New Anna University Nov / Dec 2016 Examination Important Questions
New Anna University (UG / PG) Nov/Dec 2016 and Jan 2017 Theory , Practical Exam Timetable
>>> Anna University Sixth Semester Question Bank Collection (R2013) ECE,MECH,CSE,IT,EEE,CIVIL,EIE
>>> Anna University November/December 2015 Examination Question Papers
>>> Anna University Study Materials for all Departments
>>> Anna University Question Papers : April May June 2015 Question Papers | Nov Dec 2014 and Jan 2015 Question Papers

Register or Login to Submit Study Materials , Shoutbox and also to access Many Features !!

Vidyarthiplus Shop :: Handwritten Premium Lecture Notes
Share your Study Materials with us
Share your Study Materials with us : Click Here

C Program For 2D Transformation of Scaling
#1
Thumbs Up 


Program Name: 2 D Scaling

Program Language:c

Program Requirements:C++ Or C Program Compilers

Program Description:
Scaling is a linear transformation that enlarges or diminishes objects. When we talk about scaling we usually mean some amount of scaling along each dimension. That is, we must specify how much to change the size along each dimension. To know more on what scaling is and its matrix representation see 2D scaling

Source Code:

Code:
#include<graphics.h>
#include<stdio.h>
#include<conio.h>


void scale( int figure[], int edges, int dx, int dy, int cx, int cy )
{
    for(int i=0; i < edges; i++)
    {
        figure[2*i] = (figure[2*i] - cx) * dx + cx;
        figure[2*i+1] = (figure[2*i+1] - cy) * dy + cy;
    }
}

void main()
{
    int figure[20], edges; // A Figure with Max 10 edges.
    int dx, dy, cx=0, cy=0;
    int gd = DETECT, gm;
    clrscr();

    printf( "Number of edges: " );
    scanf( "%d", &edges );

    for(int i=0; i < edges; i++)
    {
        printf( "Enter edge (x%d,y%d) : ", i , i );
        scanf( "%d %d", &figure[2*i], &figure[2*i+1] );
    }
    figure[2*i] = figure[0];
    figure[2*i+1] = figure[1];
    edges += 1;

    printf( "Enter dx: ");
    scanf( "%d", &dx);
    printf( "Enter dy: ");
    scanf( "%d", &dy);

    printf( "Enter the center of scaling: \n");
    printf( "cx: ");
    scanf( "%d", &cx);
    printf( "cy: ");
    scanf( "%d", &cy);

    initgraph( &gd, &gm, "" );
    cleardevice();
    setbkcolor(WHITE);

    setcolor(GREEN);
    setlinestyle(SOLID_LINE, 0, 3);
    drawpoly( edges, figure );
    getch();

    scale(figure,edges,dx,dy,cx,cy);

    setcolor(RED);
    drawpoly( edges, figure );
    getch();
}


Heart
Make a Great History


Reply

Subscribe


Recommend on Google