Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Answers/ans1_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Answers/ans3_output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions Answers/mohit_1901011(code1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include<stdio.h>
#include<graphics.h>
int main( )
{
int gd=DETECT, gm, x0, y0, x1, y1, dx, dy, p, x, y;
printf("Co-ordinates of first point: ");
printf("\nEnter the value of x1: ");
scanf("%d",&x0);
printf("Enter the value of y1: ");
scanf("%d",&y0);
printf("Co-ordinates of second point: ");
printf("\nEnter the value of x2: ");
scanf("%d",&x1);
printf("Enter the value of y2: ");
scanf("%d",&y1);
initgraph(&gd,&gm,"");
dx=x1-x0;
dy=y1-y0;
x=x0;
y=y0;
p=2*dy-dx;
while(x<x1)
{
if(p>=0)
{
putpixel(x,y,4);
y=y+1;
p=p+2*dy-2*dx;
}
else
{
putpixel(x,y,4);
p=p+2*dy;
}
x=x+1;
}
getch();
return 0;
29 changes: 29 additions & 0 deletions Answers/mohit_1901011(code2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
#include <graphics.h>
int main( ){
int gd=DETECT,gm;
int t[3][3]={1,0,0,0,1,0,0,0,1},a[3][3],r[3][3]={0},i,j,k;
printf("Enter value of x1 and y1: "); scanf("%d %d", &a[0][0], &a[0][1]);
printf("Enter value of x2 and y2: "); scanf("%d %d", &a[1][0], &a[1][1]);
printf("Enter value of x3 and y3: "); scanf("%d %d", &a[2][0], &a[2][1]);
printf("Enter value of tx and ty: "); scanf("%d %d", &t[2][0], &t[2][1]);
a[0][2]=a[1][2]=a[2][2]=1;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
for(k=0;k<3;k++){
r[i][j] = r[i][j] + (a[i][k]*t[k][j]);
}
}
}
initgraph(&gd,&gm,"NULL");
line(a[0][0],a[0][1],a[1][0],a[1][1]);
line(a[1][0],a[1][1],a[2][0],a[2][1]);
line(a[0][0],a[0][1],a[2][0],a[2][1]);
outtext("- - - Before Translation - - -");
delay(5000);
cleardevice();
line(r[0][0],r[0][1],r[1][0],r[1][1]);
line(r[1][0],r[1][1],r[2][0],r[2][1]);
line(r[0][0],r[0][1],r[2][0],r[2][1]);
outtext("- - - After Translation - - -");
delay(5000);closegraph( );return 0 ;}