Mumba Individual Algos

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

MIDLANDS STATE UNIVERSITY

DEPARTMENT OF INFORMATION AND MARKETING


SCIENCES

INDIVIDUAL ASSIGNMENT 2
NAME: CHARITY MUMBA

REGISTRATION NUMBER: R1912359A

PROGRAMME: BCOMM HONOURS IN INFORMATION


SYSTEMS

MODE OF ENTRY: VISITING

MODULE: COMPUTER GRAPHICS

MODULR CODE: INFO 411


LECTURER: MR R GUMBO

DUE DATE: 20 JULY 2022


Question1a: Write steps for Midpoint Circle Algorithm [10]

It is based on the function for testing the spatial relationship between the arbitrary point
(x, y) and a circle of radius r centered at the origin:

Step1: Put x =0, y =r in equation 2. We have p=1-r.

Input the radius r and the circle center (xc,yc)r to get the initial point on the circumference of
a circle centered on the origin: (x0, y0) = (0, r).

Step2: Repeat steps while x ≤ y. Plot (x, y) If (p<0) Then set p = p + 2x + 3. Else. p = p + 2(x-y)
+5. y =y - 1 (end if) x =x+1 (end loop)

Now, consider the coordinates of the point halfway between pixel T and pixel S. This is

called midpoint (xi+1,yi- ) and we use it to define a decision parameter:

            Pi=f (xi+1,yi- ) = (xi+1)2+(yi- )2-r2 ...............equation 2

Step3: After end of loop then:

If Pi is negative then midpoint is inside the circle and we choose pixel T

If Pi ispositive then midpoint is outside the circle (or on the circle)and we choose pixel S.

The decision parameter for the next step is:

Pi+1=(xi+1+1)2+(yi+1- )2- r2............equation 3

Step4: xi+1=xi+1, we have therefore

If pixel T is choosen ⟹Pi<0 then yi+1=yi


If pixel S is choosen ⟹Pi≥0 then yi+1=yi-1

Step5: We can continue to simplify this in n terms of (xi,yi) until getting the initial value of Pi
(0,r)from equation 2 where r is an integer

Step 6: Output

Thus P1=1-r

Thus in brief the steps are written as follows and there can be many equations until the
initial value of P becomes an integer.

Step1: Put x =0, y =r in equation 2


            We have p=1-r

Step2: Repeat steps while x ≤ y


            Plot (x, y)
            If (p<0)
Then set p = p + 2x + 3
Else
            p = p + 2(x-y)+5
            y =y - 1 (end if)
            x =x+1 (end loop)

Step3: End

Question1b.Given a radius r = 10, demonstrate the midpoint circle algorithm be


determining positions along the circle octant in the first quadrant from x = 0 to x = y[10]

In this situation, the decision parameter's starting value is p0 = 1 - r = -9.

The initial point for the circle centered on the coordinate origin is (x0, y0) - (0, 10), and the first
increment terms for calculating the choice parameters are: 2x0 = 0, 2y0 = 20.

The midpoint approach is used to calculate successive decision parameter values and positions
along the circle path as follows:
K Pk (Xk+1, Yk+1) 2Xk+1 2Yk+1
0 -9 (1,10) 2 20
1 -6 (2,10) 4 20
2 -1 (3,10) 6 20
3 6 (4,9) 8 18
4 -3 (5,9) 10 18
5 8 (6,8) 12 16
6 5 (7,7) 14 14

TWO DIMENSIONAL viewing functions

i) Write a function to set up element of window-to-viewpoint mapping matrix (5)

The process of converting a two-dimensional, world-coordinate scene to device coordinates is


known as window-to-viewport transformation or mapping. Objects within the world or clipping
window, in particular, are mapped to the viewport. The viewport is displayed on the screen in the
interface window. In other words, the clipping window is used to choose which part of the scene
to display. The scene is then positioned on the output device by the viewport.

This transformation entails creating formulas that begin with a point in the world window, such
as (x, y)

(xwmin, xwmax, ywmin, ywmax,


xvmin, xvmax, yvmin, yvmax, error, viewMappingMatrix)…

where the viewing coordinate limitations are determined by the parameters xwmin, xwmax,
ywmin, and ywmax, while the viewport limits are determined by the normalised coordinate
positions xvmin, xvmax, yvmin, and yvmax.

Coordinate transformation for any pointcan be: xv−xvmin xvmax−xvmin = xw−xwmin


xwmax−xwmin xv=xvmin+(xw-xwmin) xvmax−xvmin xwmax−xwmin yv−yvmin
yvmax−yvmin = yw−ywmin ywmax−ywmin yv=yvmin+(yw-ywmin) yvmax−yvmin
ywmax−ywmin

ii) Write a function to store combinations of viewing and window-viewpoint mapping for
various workstations (5)

To save viewing and window-viewport mapping combinations for different workstations, we use
the following function:

setViewRepresentation
(ws, viewIndex, viewMatrix, viewMappingMatrix,
xclipmin, xclipmax, yclipmin, yclipmax, clipxy)

Where argument ws represent the workstation's output device and parameter viewIndex specifies
image identification for this specific window-viewport pair.

iii) Write a function to apply a work station transformation by selecting a workstation


window-viewport point. (5)

The maximum size of a workstation window is (0.0,1.0)x (0.0,1.0). The maximum workstation
viewport is the workstation's entire display surface. There is a simple approach to ensure that an
application uses the entire workstation display surface, regardless of the type of output device it
is using. The function Inquire display space size (GQDSP) returns the maximum x and y ranges
for DC units, among other things. The largest of these should be chosen, and the aspect ratio of
the NDC workstation window is selected to be the same as the aspect ratio of the display surface.
The graphics image will then be mapped to the entire display surface via the workstation
transformation. This can be illustrated as follows:

SET WINDOW (2, 0.0, 100.0, 0.0, 100.0)


INQUIRE DISPLAY SPACE SIZE (wtype, error,
dcunits, xdevice, ydevice, xraster, yraster)
if xdevice > ydevice
then scale = xdevice
else scale = ydevice
xndc = xdevice/scale
yndc = ydevice/scale
SET VIEWPORT (2, 0.0, xndc, 0.0, yndc)
SET WORKSTATION WINDOW (wkid, 0.0, xndc, 0.0,
yndc)
SET WORKSTATION VIEWPORT (wkid, 0.0, xdevice,
0.0, ydevice)

Comment: This approach can be used to make use of the complete display surface in an
application.

You might also like