CG ASsignment
CG ASsignment
CG ASsignment
DDA Algorithm
#include <bits/stdc++.h>
int round(float n)
return (int)n;
// Calculate dx and dy
int dx = x1 - x0;
int dy = y1 - y0;
int step;
// line
step = abs(dx);
else
step = abs(dy);
float x = x0;
float y = y0;
cout << round(x) << " " << round(y) << "\n";
x += x_incr;
y += y_incr;
// delay(10);
// Driver code
int main()
return 0;
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
putpixel(x+xc,y+yc,RED);
putpixel(x+xc,-y+yc,YELLOW);
putpixel(-x+xc,-y+yc,GREEN);
putpixel(-x+xc,y+yc,YELLOW);
putpixel(y+xc,x+yc,12);
putpixel(y+xc,-x+yc,14);
putpixel(-y+xc,-x+yc,15);
putpixel(-y+xc,x+yc,6);
int x=0,y=r,d=3-(2*r);
EightWaySymmetricPlot(xc,yc,x,y);
while(x<=y)
if(d<=0)
d=d+(4*x)+6;
else
d=d+(4*x)-(4*y)+10;
y=y-1;
x=x+1;
EightWaySymmetricPlot(xc,yc,x,y);
int main(void)
errorcode = graphresult();
getch();
scanf("%d%d",&xc,&yc);
scanf("%d",&r);
BresenhamCircle(xc,yc,r);
getch();
closegraph();
return 0;
#include <graphics.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
class bresen
float x, y,a, b, r, p;
public:
};
void main ()
{
bresen b;
b.get ();
b.cal ();
getch ();
cin>>a>>b;
cout<<"ENTER r";
cin>>r;
getch ();
x=0;
y=r;
p=5/4)-r;
while (x<=y)
If (p<0)
p+= (4*x)+6;
else
p+=(2*(x-y))+5;
y--;
x++;
code |= LEFT;
code |= RIGHT;
code |= BOTTOM;
else if (y > y_max) // above the rectangle
code |= TOP;
return code;
while (true) {
accept = true;
break;
// in same region
break;
else {
int code_out;
double x, y;
if (code1 != 0)
code_out = code1;
else
code_out = code2;
// x = x1 + (1 / slope) * (y - y1)
y = y_max;
y = y_min;
x = x_max;
x = x_min;
// by intersection point
if (code_out == code1) {
x1 = x;
y1 = y;
else {
x2 = x;
y2 = y;
if (accept) {
cout << "Line accepted from " << x1 << ", "
<< y1 << " to " << x2 << ", " << y2 << endl;
else
// Driver code
int main()
{
cohenSutherlandClip(5, 5, 7, 7);
cohenSutherlandClip(1, 5, 4, 1);
return 0;
#include <iostream>
#include <utility>
#include <vector>
Vertex line[] = {
Vertex(Vector2f(p0.first, p0.second)),
Vertex(Vector2f(p1.first, p1.second))
};
window->draw(line, 2, Lines);
float max(vector<float> t)
maximum = t[i];
return maximum;
float min(vector<float> t)
{
float minimum = INT_MAX;
minimum = t[i];
return minimum;
// Calculating P1 - P0
= make_pair(line[1].first - line[0].first,
line[1].second - line[0].second);
P0_PEi[i].first
= vertices[i].first - line[0].first;
if (denominator[i] > 0)
tE.push_back(t[i]);
else
tL.push_back(t[i]);
float temp[2];
tE.push_back(0.f);
temp[0] = max(tE);
tL.push_back(1.f);
temp[1] = min(tL);
// is completely outside
return newPair;
}
// Calculating the coordinates in terms of x and y
newPair[0].firs
= (float)line[0].first
+ (float)P1_P0.first * (float)temp[0];
newPair[0].second
= (float)line[0].second
+ (float)P1_P0.second * (float)temp[0];
newPair[1].first
= (float)line[0].first
+ (float)P1_P0.first * (float)temp[1];
newPair[1].second
= (float)line[0].second
+ (float)P1_P0.second * (float)temp[1];
return newPair;
// Driver code
int main()
make_pair(250, 100),
make_pair(200, 150),
make_pair(100, 150),
make_pair(50, 100),
make_pair(100, 50) };
temp2[0] = line[0];
temp2[1] = line[1];
while (window.isOpen()) {
window.clear();
Event event;
if (window.pollEvent(event)) {
if (event.type == Event::Closed)
window.close();
if (event.type == Event::KeyPressed)
trigger = !trigger;
if (trigger) {
line[0] = temp1[0];
line[1] = temp1[1];
else {
line[0] = temp2[0];
line[1] = temp2[1];
window.display();
return 0;