Tuesday, October 21, 2014

Shearing in c Language

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
    int gdriver=DETECT,gmode;
    double midx=350,midy=300;
    double x1=300,y1=200,x2=400,y2=200,x3=400,y3=300,x4=300,y4=300;
    double x11,y11,x22,y22,x33,y33,x44,y44;

    int x,y,i;
    double shx,shy;
    double theta,t;
    clrscr();
    initgraph(&gdriver,&gmode,"c:/tc/bgi");
       /*    printf("\n Enter the 1st co-ordinate=");
    scanf("%lf%lf",&x1,&y1);
    printf("\n Enter the 2nd co-ordinate=");
    scanf("%lf%lf",&x2,&y2); */
    line(x1,y1,x2,y2); outtextxy(x1-20,y1-20,"(x1,y1)");
    line(x2,y2,x3,y3); outtextxy(x2-20,y2-20,"(x2,y2)");
    line(x3,y3,x4,y4); outtextxy(x3-20,y3+20,"(x3,y3)");
    line(x4,y4,x1,y1); outtextxy(x4-20,y4+20,"(x4,y4)");
    while(1)
    {
        printf("\n Press 1 for shear relative to the x-axis=");
        printf("\n Press 2 for shear relative to the y-axis=");
        printf("\n Press 3 for exit=");
        printf("\n Enter your choice=");
        scanf("%d",&i);
        switch(i)
        {
            case 1:// cleardevice();
                printf("\n Enter shearing factor=");
                scanf("%lf",&shx);
                x11=x1+shx*y1; x22=x2+shx*y2;
                y11=y1; y22=y2;
                setcolor(2);
                line(x11,y11,x22,y22);
                line(x22,y22,x3,y3);
                line(x3,y3,x4,y4);
                line(x4,y4,x11,y11);
                outtextxy(250,430,"shear relative to the x-axis");
                break;
            case 2: printf("\n Enter shearing factor=");
                scanf("%lf",&shy);
                x11=x1; x44=x4;
                y11=y1+shy*x1; y44=y4+shy*x4;
                setcolor(3);
                line(x11,y11,x2,y2);
                line(x2,y2,x3,y3);
                line(x3,y3,x44,y44);
                line(x44,y44,x11,y11);
                outtextxy(250,430,"shear relative to the y-axis");
                break;
            default: exit(1);
        }
    }
    getch();


}

No comments:

Post a Comment