Friday 14 October 2011

Composite Transformation and Character Generation

Character Generation in Computer Graphics






Computers uses a special device called a character generator ROM to convert the ASCII bytes to a tiny dot matrix pattern for displaying on the tv screen. This dot matrix can have a density ranging from 5×7 (the most coarse and not allowing lowercase) to 10×12 (the most dense and allowing all symbols of the alphabet). As the resolution of the dot matrix of the character increases so does the cost of the ROM chip; so the 5×7 and 7×9 matrixes have become popular, the 7×9 in Fig. 2-4B having uppercase, lowercase, and Greek math symbols. Besides cost, another factor that limits the character matrix density is maximum dot frequency permitted by the tv. This simply means that the internal circuits of the television set will not allow a dot pattern to be resolved if there are frequency components in it which exceed about 6 MHz.


Composite Transformation in Computer Graphics




2D Composite Tranformation :

To perform the 2D transformation such as translation, rotation, scaling, shearing, Reflection

FUNCTIONS USED:

Line()
      The function line() is used to draw a line from(x1,y1)to (x2,y2)

Syntax:
        line (x1,y1,x2,y2)

initgraph().
       This function takes thee arguments and they are
         i).the video driver to be used (gd).
         ii).the graphics mode (gm).
         iii).the path name.

Syntax:
       Initgraph(gd,gm,path)


ALGORITHM:

Step1: Declare the variables xa,ya,xa1,ya1 of array type.
Step2:Declare the variables gd,gm,n,i,op,tx,ty,xf,yf,rx,ry.
Step3: Initialise the graphics function.
Step4: Input the number of points.
Step5: Input the value of co-ordinate according to number of points.
Step6. Using switch statement selects the option to perform translation, rotation, scaling,    reflection and shearing.
Step7: Translation:
             a).input the translation vector
             b).add the translation vectors with the coordinates
                     xa1[i]=xa[i]=tx, ya1[i]=ya[i]=ty,
            c).using the function line,display the object before and after translation.
Step8: Rotation
               a). input the rotation angle
               b). using formula theta=(theta*3.14)/180
              c).input the value of reference point
             d). calculate new coordinate point using formula
                      xa1[i]=xf+(xa[i]-xf)*cos(theta)-(ya[i]-yf)*sin(theta),
                      ya1[i]=yf+(xa[i]-xf)*sin(theta)-(ya[i]-yf)*cos(theta),
           e). using the function line,display the object before and after rotation.
Step9: Scaling:
            a).input the scaling factor and reference point
            b).calculate new coordinate point using formula
                      xa1[i]=(xa[i]*sx+rx*(1-sx),
                       ya1 [i] = (ya[i]*sy+ry*(1-sy)
             c). using the function line, display the object before and after scaling.
   Step10: Shearing:
            a).input the shearing value and reference point.
       b). input the shear direction x or y
                          i).if direction x
                                     xa1[i]=xa[i]+shx*(ya[i]-yref)
                         ii).otherwise
                                    ya1[i]=ya[i]+shy*(xa[i]-xref)
                       iii). using the function line, display the object before and after shearing.
Step11: Reflection:
               a).display the object before  reflection using the function line
             b). display the object after reflection using the function line
Step12: Stop.








PROGRAM:

#include
#include
#include
#include
#include
void main()
{
int gd,gm,n,i,xa[10],ya[10],op,tx,ty,xa1[10],ya1[10],theta,xf,yf,rx,ry,sx,sy,shx,shy,xref,yref;
char d;
gd=DETECT;
initgraph(&gd,&gm,"");
cout<<"enter the no of points";
cin>>n;
for(i=0;i
{
cout<<"enter the coordinates"<
cin>>xa[i]>>ya[i];
}

do
{
cout<<"menu";
cout<<"\n1.translation\n2.rotation\n3.scaling\n4.shearing\n5.reflection\n6.exit";
cin>>op;
switch(op)
{
case 1:
cout<<"enter the translation vector";
cin>>tx>>ty;
for(i=0;i
{
xa1[i]=xa[i]+tx;
ya1[i]=ya[i]+ty;
}
cout<<"before translation";
for(i=0;i
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
 cout<<"after translation";
for(i=0;i
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 2:
cout<<"enter the rotation angle";
cin>>theta;
theta=(theta*3.14)/180;
cout<<"enter the reference points";
cin>>xf>>yf;
for(i=0;i
{
xa1[i]=xf+(xa[i]-xf)*cos(theta)-(ya[i]-yf)*sin(theta);
ya1[i]=yf+(xa[i]-xf)*sin(theta)-(ya[i]-yf)*cos(theta);
}
cout<<"before rotation";
for(i=0;i
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}

cout<<"after rotation";
for(i=0;i
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 3:
cout<<"enter the scaling factor";
cin>>sx>>sy;
cout<<"enter the reference point";
cin>>rx>>ry;
for(i=0;i
{
xa1[i]=xa[i]*sx+rx*(1-sx);
ya1[i]=ya[i]*sy+ry*(1-sy);
 }
cout<<"before scaling";
for(i=0;i
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
 cout<<"after scaling";
for(i=0;i
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 4:
cout<<"enter the shear value";
cin>>shx>>shy;
cout<<"enter the reference point";
cin>>xref>>yref;
cout<<"enter the shear direction x or y";
cin>>d;
if(d=='x')
{
for(i=0;i
{
xa1[i]=xa[i]+shx*(ya[i]-yref);
ya1[i]=ya[i];
 }
}
cout<<"before shearing";
for(i=0;i
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
cout<<"after shearing";
for(i=0;i
{
line(xa1[i],ya1[i],xa1[(i+1)%n],ya1[(i+1)%n]);
}
getch();
cleardevice();
break;
case 5:
cout<<"before reflection";
for(i=0;i
{
line(xa[i],ya[i],xa[(i+1)%n],ya[(i+1)%n]);
}
 cout<<"after reflection";
for(i=0;i
{
line(ya[i],xa[i],ya[(i+1)%n],xa[(i+1)%n]);
}
getch();
cleardevice();
break;
case 6:
exit(0);
break;
}
}while(op!=6);
}



INPUT & OUTPUT:
enter the no of points:3
enter the coordinates 1:50 150
enter the coordinates 2:50 50
enter the coordinates 3:75 150

menu
1. translation
2. rotation
3. scaling
4.shearing
5.reflection
6.exit1
enter the translation vector:30 40



Buy me a Cup of Coffee







MONIKA YADAV (MCA),
Software Engineer,
www.NotesGuru.in, Indore

ROHIT KESHRIYA (MCA),
Software Engineer,
www.NotesGuru.in, Indore

For guest faculty Contact us on following E-mail ID:

monikay.aerosoft@gmail.com
monikay.aerosoft@rediffmail.com
monikay.aerosoft@yahoo.com
monikay.aerosoft@hotmail.com
rohit.aerosoft@gmail.com
rohit.aerosoft@rediffmail.com
rohit.aerosoft@yahoo.com
rohit.aerosoft@hotmail.com

Note: We have been used search engines for gathering content.











free counters