You are on page 1of 4

ASSIGNMENT NO.

1
TITLE : Polygon filling
using scan line algorithm
ASSIGNMENT NO. 1
TITLE : Polygon filling
using scan line algorithm
ASSIGNMENT NO. 1
TITLE : Polygon filling
using scan line algorithm
ASSIGNMENT NO. 1

TITLE : Polygon filling using scan line algorithm :

PROBLEM STATEMENT: Write C++ program to draw a concave polygon and fill it with desired color
using scan fill algorithm. Apply the concept of inheritance.

OBJECTIVE:

1. To understand scan line algorithm to fill polygon.

2. To understand the implementation of Inheritance.

THEORY:

Inheritance in C++:-
The capability of a class to derive properties and characteristics from another class is called Inheritance.
Inheritance is one of the most important feature of Object Oriented Programming.

Sub Class: The class that inherits properties from another class is called Sub class or Derived class.

Super Class:The class whose properties are inherited by sub class is called Base Class or Super class.

Implementing inheritance in C++: For creating a sub-class which is inherited from the base class we have
to follow the below syntax.

Syntax:

class subclass_name : access_mode base_class_name

//body of subclass

};

Here, subclass_name is the name of the sub class, access_mode is the mode in which you
want to inherit this sub class for example: public, private etc. and base_class_name is the name
of the base class from which you want to inherit the sub class.

Note: A derived class doesn’t inherit access to private data members.

However, it does inherit a full parent object, which contains any private members which that class
declares.

filter_none

edit

play_arrow

brightness_4

// C++ program to demonstrate implementation of Inheritance

#include <bits/stdc++.h>

using namespace std;

//Base class

class Parent

public:

int id_p;
};

// Sub class inheriting from Base Class(Parent)

class Child : public Parent

public:

int id_c;

};

//main function

int main()

Child obj1;

// An object of class child has all data members and member functions of class parent

obj1.id_c = 7;

obj1.id_p = 91;

cout << "Child id is " << obj1.id_c << endl;

cout << "Parent id is " << obj1.id_p << endl;

return 0;

Scan line:-
The scan line fill algorithm is an ingenious way of filling in irregular polygons. The algorithm begins with
a set of points. Each point is connected to the next, and the line between them is considered to be an
edge of the polygon. The points of each edge are adjusted to ensure that the point with
the smaller y value appears first. Next, a data structure is created that contains a list of edges that
begin on each scan line of the image. The program progresses from the first scan line
upward. For each line, any pixels that contain an intersection between this scan line and an edge of the
polygon

are filled in. Then, the algorithm progresses along the scan line, turning on when it reaches a polygon
pixel and turning off when it reaches another one, all the way across the scan line.

The basic scan-line algorithm is as follows:


Find the intersections of the scan line with all active edges of the polygon

Sort the intersections by increasing x coordinate

Fill in all pixels between pairs of intersections that lie interior to the polygon

Process involved:

The scan-line polygon-filling algorithm involves

• the horizontal scanning of the polygon from its lowermost to its topmost vertex,

• identifying which edges intersect the scan-line,

• finally drawing the interior horizontal lines with the specified fill color process.

Algorithm
CONCLUSION: Thus we have implemented scan line algorithm to fill

polygon successfully.

You might also like