Mod 2
Mod 2
3a. how do you classify the polygon? Explain openGL polygon fill primitives.
Polygon Classifications
2. Concave Polygon
Convex Polygon:
✓ The polygon is convex if all interior angles of a polygon are less than or equal to 180◦, where an
interior angle of a polygon is an angle inside the polygon boundary that is formed by two adjacent
edges
✓ An equivalent definition of a convex polygon is that its interior lies completely on one side of the
infinite extension line of any one of its edges.
✓ Also, if we select any two points in the interior of a convex polygon, the line segment joining the
two points is also in the interior.
Concave Polygon:
✓ A polygon that is not convex is called a concave polygon. The below figure shows convex and
concave polygon
✓ The term degenerate polygon is often used to describe a set of vertices that are collinear or that
have repeated coordinate positions.
Problems in concave polygon: ➔ Implementations of fill algorithms and other graphics routines are
more complicated
Solution: ➔ It is generally more efficient to split a concave polygon into a set of convex polygons
before processing.
When rendering a polygon, OpenGL provides several primitive types that can be used to fill the
interior of the shape. These primitives include:
Sure, here are some examples of how each of the OpenGL polygon fill primitives can be used:
1. GL_POINTS: Suppose we have a set of 2D points that we want to plot as a scatter plot. We could
use GL_POINTS to render each point as a single pixel on the screen. Here's some example code:
```
glBegin(GL_POINTS);
glVertex2f(points[i].x, points[i].y);
glEnd();
```
2. GL_LINES: Suppose we want to draw a simple rectangle on the screen. We could use GL_LINES to
connect the four corners of the rectangle with straight lines. Here's some example code:
```
glBegin(GL_LINES);
glVertex2f(0, 0);
glVertex2f(0, 1);
glVertex2f(0, 1);
glVertex2f(1, 1);
glVertex2f(1, 1);
glVertex2f(1, 0);
glVertex2f(1, 0);
glVertex2f(0, 0);
glEnd();
```
3. GL_LINE_STRIP: Suppose we want to draw a simple curve on the screen that starts at (0,0) and
ends at (1,1). We could use GL_LINE_STRIP to connect a series of points that define the curve. Here's
some example code:
```
glBegin(GL_LINE_STRIP);
glVertex2f(0, 0);
glVertex2f(0.2, 0.4);
glVertex2f(0.4, 0.6);
glVertex2f(0.6, 0.8);
glVertex2f(0.8, 1);
glVertex2f(1, 1);
glEnd();
```
4. GL_LINE_LOOP: Suppose we want to draw a simple closed shape on the screen, such as a square.
We could use GL_LINE_LOOP to connect the four corners of the square with straight lines. Here's
some example code:
```
glBegin(GL_LINE_LOOP);
glVertex2f(0, 0);
glVertex2f(0, 1);
glVertex2f(1, 1);
glVertex2f(1, 0);
glEnd();
```
5. GL_TRIANGLES: Suppose we want to draw a simple triangle on the screen. We could use
GL_TRIANGLES to define the three vertices of the triangle. Here's some example code:
```
glBegin(GL_TRIANGLES);
glVertex2f(0, 0);
glVertex2f(0.5, 1);
glVertex2f(1, 0);
glEnd();
```
6. GL_TRIANGLE_STRIP: Suppose we want to draw a more complex shape on the screen, such as a
curved surface. We could use GL_TRIANGLE_STRIP to define a series of connected triangles that
approximate the surface. Here's some example code:
```
glBegin(GL_TRIANGLE_STRIP);
glVertex3f(0, 0, 0);
glVertex3f(0, 1, 0);
glVertex3f(1, 0, 0);
glVertex3f(1, 1, 0);
glEnd();
```
7. GL_TRIANGLE_FAN: Suppose we want to draw a circular shape on the screen. We could use
GL_TRIANGLE_FAN to define a series of connected triangles that approximate the circle. Here's some
example code:
```
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0, 0);
glEnd();
```
In each of these examples, the glBegin and glEnd functions are used to define a block of code that
specifies the vertices and primitive type for the polygon. The glVertex functions are used to specify
the individual vertices of the polygon.
b. Explain translation, Scaling, rotation in 2D homogenous coordinate system
with matrix representations.
(refer formula sheet)
In computer graphics, it's common to work with objects represented in a homogeneous coordinate
system, which is a 4D coordinate system that extends the traditional 3D coordinate system with an
additional dimension that allows for transformations like translation, scaling, and rotation. These
transformations can be represented using matrix operations.
1. Translation: Translation is a transformation that moves an object from one location to another in
2D space. Given a vector (tx, ty) representing the translation amount in the x and y directions, we
can represent a translation operation as a matrix:
```
| 1 0 tx |
| 0 1 ty |
|001 |
```
This matrix can be used to transform a homogeneous coordinate (x, y, 1) to a new location (x', y', 1)
by multiplying the original coordinate by the translation matrix:
```
| x' | | 1 0 tx | | x |
| y' | = | 0 1 ty | * | y |
|1 | |001 | |1|
```
2. Scaling: Scaling is a transformation that changes the size of an object in 2D space. Given scaling
factors sx and sy for the x and y directions, we can represent a scaling operation as a matrix:
```
| sx 0 0 |
| 0 sy 0 |
|0 0 1|
```
This matrix can be used to transform a homogeneous coordinate (x, y, 1) to a new location (x', y', 1)
by multiplying the original coordinate by the scaling matrix:
```
| x' | | sx 0 0 | | x |
| y' | = | 0 sy 0 | * | y |
|1 | |0 0 1| |1|
```
3. Rotation: Rotation is a transformation that rotates an object around a fixed point in 2D space.
Given an angle theta for the amount of rotation in radians, we can represent a rotation operation as
a matrix:
```
| cos(theta) -sin(theta) 0 |
| sin(theta) cos(theta) 0 |
|0 0 1|
```
This matrix can be used to transform a homogeneous coordinate (x, y, 1) to a new location (x', y', 1)
by multiplying the original coordinate by the rotation matrix:
```
|1 | |0 0 1| |1|
```
Using these matrix representations, we can combine multiple transformations (such as translation
followed by scaling followed by rotation) by multiplying the corresponding matrices together. For
example, to perform a translation followed by a scaling followed by a rotation, we can multiply the
translation matrix, scaling matrix, and rotation matrix together in the appropriate order:
```
T*S*R
```
where T is the translation matrix, S is the scaling matrix, and R is the rotation matrix. The resulting
matrix can then be used to transform the original homogeneous coordinate to the final position.
Aug-2022
3a. what is the need of Homogenous coordinate system?
Homogeneous coordinates are used in computer graphics because they
provide a way to represent affine transformations (such as translation,
rotation, scaling, and shearing) using matrix multiplication.
In a homogeneous coordinate system, a point in 2D or 3D space is represented
as a vector with an additional coordinate, typically set to 1. Homogeneous
coordinates allow affine transformations to be represented as a matrix
multiplication, which can be more efficiently computed than applying the
transformations individually to each point.
Additionally, homogeneous coordinates allow for the representation of points
at infinity, which cannot be represented in a traditional Cartesian coordinate
system. This is useful in computer graphics, where points at infinity are often
used to represent vanishing points, light sources, and other important
features.
In summary, homogeneous coordinates are essential in computer graphics
because they allow for efficient representation and manipulation
of geometric transformations, as well as the representation of points at
infinity.
(xh/h,yh/h,h) usually h=1
Explain translation, rotation and scaling in 2D Homogenous coordinate
system, with matrix representation. (Repeat)
b. Explain with example any two algorithm used to identify interior and
exterior area of a polygon.
Identifying interior and exterior region of polygon.
➢ For such shapes, it is not always clear which regions of the xy plane we
should call “interior” and which regions.
➢ We should designate as “exterior” to the object boundaries.
✓ Draw a line from any position P to a distant point outside the coordinate extents of the closed
polyline.
✓ Then we count the number of line-segment crossings along this line.
✓ If the number of segments crossed by this line is odd, then P is considered to be an interior point
Otherwise, P is an exterior point
✓ We can use this procedure, for example, to fill the interior region between two concentric circles
or two concentric polygons with a specified colour.
✓ This counts the number of times that the boundary of an object “winds” around a particular point
in the counter-clockwise direction termed as winding number,
✓ Initialize the winding number to 0 and again imagining a line drawn from any position P to a
distant point beyond the coordinate extents of the object.
✓ The line we choose must not pass through any endpoint coordinates.
✓ As we move along the line from position P to the distant point, we count the number of object line
segments that cross the reference line in each direction
✓ We add 1 to the winding number every time we intersect a segment that crosses the line in the
direction from right to left, and we subtract 1 very time we intersect a segment that crosses from left
to right
✓ The nonzero winding-number rule tends to classify as interior some areas that the oddeven rule
deems to be exterior.
✓ Variations of the nonzero winding-number rule can be used to define interior regions in other
ways define a point to be interior if its winding number is positive or if it is negative; or we could use
any other rule to generate a variety of fill shapes
✓ Boolean operations are used to specify a fill area as a combination of two regions
✓ One way to implement Boolean operations is by using a variation of the basic winding-number
rule consider the direction for each boundary to be counter-clockwise, the union of two regions
would consist of those points whose winding number is positive
✓ The intersection of two regions with counterclockwise boundaries would contain those points
whose winding number is greater than 1,
▪ To set up a fill area that is the difference of two regions (say, A − B), we can enclose region A with a
counter-clockwise border and B with a clockwise border
EXAMPLES:
The odd-even rule and the nonzero winding-number rule are two commonly used algorithms for
determining whether a point is inside or outside a polygon. Here is an example of how each
algorithm works:
1. Odd-Even rule:
The odd-even rule, also known as the "even-odd" rule, works by counting the number of times a ray
from the point intersects the polygon edges. If the number of intersections is odd, the point is inside
the polygon, otherwise, it is outside.
```
(1,2)------(5,6)
| |
| |
(2,5)------(4,3)
```
To determine whether the point P(3,4) is inside or outside the polygon using the odd-even rule, we
draw a horizontal ray from P as shown below:
```
(1,2)------(5,6)
| |
| P |
(2,5)------(4,3)
```
The ray intersects the polygon edges twice, at points (2,5) and (4,3), so the total number of
intersections is 2, which is even. Therefore, the point P is outside the polygon.
The nonzero winding-number rule works by counting the number of times the polygon winds around
the point in a counterclockwise direction. If the winding number is zero, the point is outside the
polygon, otherwise, it is inside.
```
(1,2)------(5,6)
| |
| |
(2,5)------(4,3)
```
To determine whether the point P(3,4) is inside or outside the polygon using the nonzero winding-
number rule, we draw a small circle around the point and count the number of times the polygon
edges cross the circle in a counterclockwise direction:
```
(1,2)------(5,6)
| |
| o |
(2,5)------(4,3)
```
In this case, the polygon winds around the point once in a counterclockwise direction, so the winding
number is 1. Therefore, the point P is inside the polygon.
Both the odd-even rule and the nonzero winding-number rule are commonly used in computer
graphics and other fields where polygonal objects are analyzed. The choice of algorithm depends on
the specific application and the properties of the polygon being analyzed.
➢ A section of a two-dimensional scene that is selected for display is called a clipping Window.
➢ Sometimes the clipping window is alluded to as the world window or the viewing window
➢ Graphics packages allow us also to control the placement within the display window using
another “window” called the viewport.
➢ The clipping window selects what we want to see; the viewport indicates where it is to be viewed
on the output device.
➢ By changing the position of a viewport, we can view objects at different positions on the display
area of an output device
➢ Usually, clipping windows and viewports are rectangles in standard position, with the rectangle
edges parallel to the coordinate axes.
➢ We first consider only rectangular viewports and clipping windows, as illustrated in Figure
Viewing Pipeline
➢ To make the viewing process independent of the requirements of any output device, graphics
systems convert object descriptions to normalized coordinates and apply the clipping routines.
➢ Systems use normalized coordinates in the range from 0 to 1, and others use a normalized range
from −1 to 1.
➢ At the final step of the viewing transformation, the contents of the viewport are transferred to
positions within the display window.
➢ This allows us to reduce computations by first concatenating the various transformation matrices
• The GLU library provides a function for specifying a two-dimensional clipping window, and we have
GLUT library functions for handling display windows.
✓ Before we select a clipping window and a viewport in OpenGL, we need to establish the
appropriate mode for constructing the matrix to transform from world coordinates to screen
coordinates
✓ We must set the parameters for the clipping window as part of the projection transformation.
✓ Function:
glMatrixMode (GL_PROJECTION);
glLoadIdentity ( );
This ensures that each time we enter the projection mode, the matrix will be reset to the identity
matrix so that the new viewing parameters are not combined with the previous ones
✓ This function specifies an orthogonal projection for mapping the scene to the screen the
orthogonal projection has no effect on our two-dimensional scene other than to convert object
positions to normalized coordinates.
✓ Normalized coordinates in the range from −1 to 1 are used in the OpenGL clipping routines.
✓ Objects outside the normalized square (and outside the clipping window) are eliminated from the
scene to be displayed.
✓ If we do not specify a clipping window in an application program, the default coordinates are
(xwmin, ywmin) = (−1.0, −1.0) and (xwmax, ywmax) = (1.0, 1.0).
✓ Thus the default clipping window is the normalized square centered on the coordinate origin with
a side length of 2.0.
➔ vpWidth and vpHeight are pixel width and height of the viewport
✓ Coordinates for the upper-right corner of the viewport are calculated for this transformation
matrix in terms of the viewport width and height:
Xvmax=xvmin+vpWidth, yvmax=yvmin+vpHeight
✓ We can obtain the parameters for the currently active viewport using the query function
glGetIntegerv (GL_VIEWPORT, vpArray);
where,
✓ The GLUT library interfaces with any window-management system, we use the GLUT routines for
creating and manipulating display windows so that our example programs will be independent of
any specific machine.
✓ We have three functions inGLUT for defining a display window and choosing its dimensions and
position:
➔ gives the integer, screen-coordinate position for the top-left corner of the display window,
relative to the top-left corner of the screen
➔ we choose a width and height for the display window in positive integer pixel dimensions.
➔ If we do not use these two functions to specify a size and position, the default size is 300 by 300
and the default position is (−1, −1), which leaves the positioning of the display window to the
window-management system
➔ creates the display window, with the specified size and position, and assigns a title, although the
use of the title also depends on the windowing system
1. glutInitDisplayMode (mode);
➔ We use this function to choose a color mode (RGB or index) and different buffer combinations,
and the selected parameters are combined with the logical or operation.
➔ A background color for the display window is chosen in RGB mode with the OpenGL routine
4. glClearIndex (index);
➔ This function sets the display window color using color-index mode,
➔ Where parameter index is assigned an integer value corresponding to a position within the color
table. GLUT Display-Window Identifier
✓ Multiple display windows can be created for an application, and each is assigned a positive-
integer display-window identifier, starting with the value 1 for the first window that is created.
✓ If we know the display window’s identifier, we can eliminate it with the statement
glutDestroyWindow (windowID);
window, which is either the last display window that we created or the one.
glutSetWindow (windowID);
✓ We can query the system to determine which window is the current display window:
currentWindowID = glutGetWindow ( );
✓ We can reset the screen location for the current display window with the function
✓ Similarly, the following function resets the size of the current display window:
✓ With the following command, we can expand the current display window to fill the
screen:
glutFullScreen ( );
✓ Whenever the size of a display window is changed, its aspect ratio may change and
objects may be distorted from their original shapes. We can adjust for a change in
glutReshapeFunc (winReshapeFcn);
✓ The GLUT library also has a number of routines for manipulating a display window in
various ways.
✓ We use the following routine to convert the current display window to an icon in the form
glutIconifyWindow ( );
✓ The label on this icon will be the same name that we assigned to the window, but we can
✓ We also can change the name of the display window with a similar command:
✓ We can choose any display window to be in front of all other windows by first
designating it as the current window, and then issuing the “pop-window” command:
glutSetWindow (windowID);
glutPopWindow ( );
✓ In a similar way, we can “push” the current display window to the back so that it is
glutSetWindow (windowID);
glutPushWindow ( );
✓ We can also take the current window off the screen with
glutHideWindow ( );
✓ In addition, we can return a “hidden” display window, or one that has been converted to
an icon, by designating it as the current display window and then invoking the function
glutShowWindow ( );
GLUT Subwindows
✓ Within a selected display window, we can set up any number of second-level display
✓ Parameter windowID identifies the display window in which we want to set up the
Subwindow
✓ Subwindows are assigned a positive integer identifier in the same way that first-level
display windows are numbered, and we can place a subwindow inside another
subwindow.
✓ Each subwindow can be assigned an individual display mode and other parameters. We
can even reshape, reposition, push, pop, hide, and show subwindows
✓ We can use the following GLUT routine to request a shape for the screen cursor that is to
glutSetCursor (shape);
✓ After we have created a display window and selected its position, size, color, and other
glutDisplayFunc (pictureDescrip);
✓ This routine, called pictureDescrip for this example, is referred to as a callback function
because it is the routine that is to be executed whenever GLUT determines that the
✓ We may need to call glutDisplayFunc after the glutPopWindow command if the display
window has been damaged during the process of redisplaying the windows.
✓ In this case, the following function is used to indicate that the contents of the current
glutPostRedisplay ( );
✓ When the program setup is complete and the display windows have been created and
initialized, we need to issue the final GLUT command that signals execution of the
program:
glutMainLoop ( );
glutIdleFunc (function);
✓ Finally, we can use the following function to query the system about some of the current
state parameters:
glutGet (stateParam);
✓ This function returns an integer value corresponding to the symbolic constant we select
➔ GLUT_WINDOW_X: obtains the x-coordinate position for the top-left corner of the
Sep2020
3a. Classify the polygons and describe fill area primitives with diagrams.
(Repeat)
b. Describe about Inside-Outside Tests. (Repeat)
4a. Explain general scan line fill algorithm. (Repeat)
b. Describe any two of dimensional composite transformation
i) 2D translation ii) 2D fixed point scaling. (I don’t understand )
July2019
3a. Explain scan-line polygon fill algorithm. (Repeat) Determine the content
of the active edge table to fill the polygon with vertices A(2,4), B(4,6) and
C(4,1) for y=1 to y=6
b. Develop composite homogenous transformation matrix to rotate an object
w.r.t a pivot point.
The data structure used in the scan line polygon fill algorithm is a table or an array called the edge
table (ET). The edge table stores information about the edges of the polygon, such as their starting
and ending points and their slopes. Each row in the edge table corresponds to an edge of the
polygon, and the columns contain the following information:
3. X: the x-coordinate of the intersection of the edge with the scan line
In addition to the edge table, the algorithm also uses an active edge table (AET), which is a linked list
that stores the edges that intersect the current scan line. The edges in the AET are sorted by their x-
coordinates.
During the polygon fill process, the algorithm starts at the topmost scan line that intersects the
polygon and moves downwards. At each scan line, the algorithm updates the edges in the AET and
fills the pixels between the x-coordinates of each pair of edges. The algorithm also removes edges
from the AET when they reach their maximum y-coordinate.
The edge table is an efficient data structure for the scan line polygon fill algorithm because it allows
for quick access to the edges of the polygon and their properties. The AET is also efficient because it
only stores the edges that intersect the current scan line, reducing the amount of memory needed
for the algorithm.
Determine the content of active edge table to fill polygon with vertices
A(2,4), B(2,7), C(4,9) and D(4,6).
b. Give the reason to convert transformation matrix to homogenous
coordinate representation and show the process of conversion. (Repeat)
Shear the polygon A(1,1), B(3,1), C(3,3) D(2,4), E(1,3) along x-axis with
shearing factor of 0.2.
(Wronggggggggggg)
The sorted edge table is an array or a table that stores information about the edges of the polygon,
such as their starting and ending points and their slopes. Each row in the edge table corresponds to
an edge of the polygon, and the columns contain the following information:
3. X: the x-coordinate of the intersection of the edge with the scan line
The edge table is sorted by the y-coordinate of the edges. Sorting the edges by y-coordinate is
important because it allows the algorithm to process the edges one scan line at a time, starting with
the topmost scan line that intersects the polygon.
The active edge list is a linked list that stores the edges that intersect the current scan line. The
edges in the AET are sorted by their x-coordinates. The AET is updated at each scan line, with edges
added or removed based on their intersection points with the current scan line.
The use of the sorted edge table and active edge list allows the algorithm to quickly and efficiently
fill polygons. By sorting the edges by y-coordinate, the algorithm can process the edges one scan line
at a time, which reduces the amount of processing needed. By sorting the edges in the AET by x-
coordinate, the algorithm can quickly determine the start and end points of each horizontal segment
to be filled.
In summary, the sorted edge table and active edge list are essential data structures in the scan line
polygon fill algorithm. The edge table stores information about the edges of the polygon, sorted by
y-coordinate, while the active edge list stores the edges that intersect the current scan line, sorted
by x-coordinate. Together, these data structures allow the algorithm to fill polygons efficiently and
accurately.