10
Computer Graphics(ecomputernotes.com ) Page 1 of 10 Scan Conversion The video output devices display images in the Form of Binary values those are in the Form of on and off and this also display images in the form of pixels on and off. The computer produces all the images in the Form of dots or Pixels those are arranged in the Form of Matrixes. The Process of Representing a Graphics Object as Collections of dots is called as Scan Conversion. 1) Scan Conversion a Point: - As in the mathematical we know that a point is represented as a real number and in the scan conversion we convert the real number into the Floor of a point. The floor is the smallest and equals to a number when we converts a number. Suppose there is a point have (x,y) coordinates then we convert into the floor then this will be (x,y). For example xfloor(x) and yfloor(y) etc. For example there are the points of p1(1.7,0.8), p2(2.2,1.3) and p3(2.8,1.9) those are represented after finding floor of those points like P1(1,0) , P2(2,1) , and p3(2,1). And second approach is by using the Alignment Method When we Wants to Convert Coordinates into the Pixels then Simply We Align the Points into the Pixels and after that We Will Find the Positions of Pixels in which Points are Lie. There is an Example in which we can represent the points in the pixels. Scan Conversion of a Straight Line :- As We Know that a Straight Line is 1

computer notes - Scan Conversion

Embed Size (px)

DESCRIPTION

Computer Graphics(ecomputernotes.com)http://ecomputernotes.com - Computer Notes on Object orient Programming What is How Use it Explain with Example.Page 1 of 7Scan ConversionThe video output devices display images in the Form of Binary values those are in the Form of on and off and this also display images in the form of pixels on and off. The computer produces all the images in the Form of dots or Pixels those are arranged in the Form of Matrixes. The Process of Representing a Graphics Object as Collections of dots is called as Scan Conversion. 1) Scan Conversion a Point: - As in the mathematical w

Citation preview

Page 1: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 1 of 7

Scan Conversion

The video output devices display images in the Form of Binary values those are in the Form of on and off and this also display images in the form of pixels on and off. The computer produces all the images in the Form of dots or Pixels those are arranged in the Form of Matrixes. The Process of Representing a Graphics Object as Collections of dots is called as Scan Conversion.

1) Scan Conversion a Point: - As in the mathematical we know that a point is represented as a real number and in the scan conversion we convert the real number into the Floor of a point. The floor is the smallest and equals to a number when we converts a number. Suppose there is a point have (x,y) coordinates then we convert into the floor then this will be (x,y). For example xfloor(x) and yfloor(y) etc. For example there are the points of p1(1.7,0.8), p2(2.2,1.3) and p3(2.8,1.9) those are represented after finding floor of those points like P1(1,0) , P2(2,1) , and p3(2,1). And second approach is by using the Alignment Method When we Wants to Convert Coordinates into the Pixels then Simply We Align the Points into the Pixels and after that We Will Find the Positions of Pixels in which Points are Lie. There is an Example in which we can represent the points in the pixels.

Scan Conversion of a Straight Line :- As We Know that a Straight Line is Represented as a Set of Points those are (x1,y1) and (x2,y2) and The Equation of a Line Which Lies in X and y Coordinates is y=mx+b in this m is called as the Slope of a Line and b is the Intercept point on the y Axis For Example there is a Line whose Points are as P1(x1,y1)) and P2(x2,y2).

Direct use of the Line Equation :- This is the Simple Approach to Scan Convert a Line, in this first p1 and p2 are Scanned According to their Coordinates i.e. (x1,y1) and (x2,y2) and also set m=y2-y1/x2-x1 and also Calculate b=y1-mx1 and in this if |m| <=1 then find the value of y coordinate by using the value which lies between x1 and x2 using the equation but if |m| > 1 then find the value of x coordinate by calculating the integer value which lies between the y1 and y2 axis. As this Approach is mathematical in all aspects because it involves the floating point operations like addition and subtraction.

1

Page 2: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 2 of 7

DDA Algorithm:- The Digital Differential Analyzer is an incremental Approach In this Previous values of a points are also consider. In this calculations are performed in the manner of increments For Example a point which we have calculated on the line is (Xi,Yi) and then when we increment to the next point this will becomes (Xi+1,Yi+1) and we calculate the value of m by using y/x and in this

y=Yi+1-Yi and x=Xi+1-Xi In this we can calculate the values of x and y by using the incremental Approach Like this First if the value of |m| <=1 then assume that X1<X2 and Y=Y1 and also set x=1 and also perform unit increment in the x direction and when|m| > 1 then assume that Y1<Y2 and X=X1 and also set Y=1 and also perform unit increment in the Y direction. These Points are Incremented until the X1 doesn’t’ closest to X2 and Y1 doesn’t Closest to Y2.

Scam Converting a Circle: - A Circle is also called as a Symmetrical Figure which can be found by plotting eight points those are around 45 axis and in the Circle These Eight Points are found with the help of Reflection. There is a Figure which Contains Eight Points

Reflection is obtained by using the reversing in the coordinates of x and y as you see in this figure a circle is defined by using the Reversing of Eight points just see the coordinates of x and y as they are Reflected or Simply reverse the previous values. So that in Summarize Form we can represent eight points of Circle as

P1 =(x,y) P5=(-x,-y)P2=(y,x) P6=(-y,-x)P3=(y,-x) P7=(-y,x)P4=(-x,y) P8(x,-y)

Defining a Circle :- There are two Methods for defining a Circle 1) By using Polynomial Method 2) By using Trigonometric Method

1) Using Polynomial Method: - The First Method is Polynomial Equation for defining a Circle such as r2=x2+y2 in this x, y are Coordinates and r is the Radius of the Circle. in this Each X Coordinate is found by stepping from 90 to 45 or from 0 to r/2 and Each y coordinate is found by evaluating y=r2-x2 and in this value of y Coordinate will be Equals to r2-x2 which can be Represented as

2

Page 3: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 3 of 7

2) Using Trigonometric Method :- The Second Method for Defining a Circle is by using Trigonometric Functions in this

X=rCosand y=rsinIn this is the Current Angle and r is the radius of the Circle and x and y are the Coordinates of the Circle. And in this is Stepped from 0 to This is very complex Method because this will Consume more time to Calculate the values of Sin and Cos

1) Algorithm to draw a Circle by using Polynomial Method1) Set the variables like r=Radius of Circle and (h,k) =Coordinates of the

Circle and set x=0 and xend =r/22) Check Whether the Circle has been Scanned and Check if x > xend then

stop. 3) Compute the value of y by using y=r2-x2

4) Then After that Plot the Eight Points with Respect to Center (h,k) those are

Plot (x+h,y+k) Plot ( -x+h,-y+k)Plot(y+h,x+k) Plot ( -y+h,x+k)Plot(-y+h,x+k) Plot ( y+h,-x+k) Plot(-x+h,y+k) Plot(x+h,-y+k)

5) Then Increment value of x with 1 as x=x+16) Then Go to Step 2

2) Algorithm to draw a Circle by using Trigonometric MethodSet the variables like r=Radius of Circle and (h,k) =Coordinates of the

Circle and set =0 and max =451) Check Whether the Circle has been Scanned and Check if > max then

stop. Compute the value of x and y by using X=rCosand y=rsin

2) Then After that Plot the Eight Points with Respect to Center (h,k) those are

Plot (x+h,y+k) Plot ( -x+h,-y+k)Plot(y+h,x+k) Plot ( -y+h,x+k)Plot(-y+h,x+k) Plot ( y+h,-x+k) Plot (-x+h,y+k) Plot(x+h,-y+k)

3) Then Increment value of with 1 as =+14) Then Go to Step 2

BRESENHAM’s Line Algorithm :- BRESENHAM’s Line Algorithm is a also a incremental Method which is highly efficient for Scan converting lines and it produces Accurate Results only in Integer Form by using only integer Mathematical

3

Page 4: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 4 of 7

Operations like additions, Subtractions, multiplication by 2 which can be Accomplished by simple Arithmetic shift operations.

Suppose when we wants to Scan a line then its next Step will be the increment to its previous axis but always Remember a Line may increase by a point by using the horizontal axis or on x axis or in the right direction and either a line may increase at y axis or in the up direction. When the Line Moves to its X Direction then its y axis will be Same and When a Line Moves in y Axis then this will increment in both x and y axis . See this Figure in this a Point P1 is the first point and P2 is the second Point and s is the horizontal distance and T is vertical distance from point p1 to p2 .

Our Main task is to Choose the next Pixel by using its Previous Pixel by Simply Adding 1 in its Previous Positions as you see in this Figure First the Point will be drawn on P1 which Contains xi,yi points and When it moves in the Horizontal then x axis will becomes xi+1. And yi+1=yi because it moves in the horizontal direction and same for vertical direction. And we can also write these next steps into this form as xi+1=xi+1 and yi+1=yi+1 . Now the Coordinates of the Line at x=xi+1 is y=mxi+1+b and this can be Represented as m (xi+1)+b

When we consider the difference between these two Directions like s and t . When s-t is less than zero or s<t then Closest Pixel will be S and When s-t is greater than zero or when S>T then Closest Pixel will be T and When Difference is Equals to zero then difference is

S-T= [y-yi-[(yi+1)-y)] ] =y-yi-yi-1+y=2y-2yi-1

Then put the value of y =m (xi+1)+b then =2(m(xi+1)+b)-2yi-1=2m(xi+1)+2b-2yi-1 //value of (S-T)

Now at this Step put the value of m i.e y/x also introduce a new decision variable di=x (S-T) because x is positive. Now solve it.

4

Page 5: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 5 of 7

BRESENHAM’s Circle Algorithm:-

If you want to Plot a Circle in a Efficient Manner then use of Trigonometric and Polynomial Method Must be Avoided. But BRESENHAM’s provide a Very Efficient Method for Drawing a Circle With the help of Least Distance in this, the Points will be drawn by calculating the Distance from its previous point to its new point.

When we draw a Circle , the Circle will moves from 90 to 45 so that Every time When this will move the x Coordinate will be Positive and y Coordinate will be goes negative. For Better understanding see this example in this the First point is (Xi,Yi), when this will move to the x Coordinate then this will increase the value of X Coordinate and decrease the value of y Coordinate ,

In this the distance of T from Origin to the point T and the Distance of S Point from Origin to Point S is Calculated as :-

D(T)=(xi+1)2+yi2-r2

D(S)= (xi+1)2+(yi-1)2-r2

As you Noted in this D (T) will always be Positive and in this Circle is always be outside from a Center Point and D(S) Will Always be Negative and this will lies inside a Center. In this D is a decision which will provides you the Total distance from its previous point to its current point variable which can be calculated as

Di=D (T) +D(S)

5

Page 6: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 6 of 7

Midpoint Circle Algorithm: - This is another incremental Approach which is Similar to BRESENHAM’s and this is also based on the following function. For testing a Relationship between a Point and Radius of a Circle r which is centered at the Origin.

F(x,y)=X2+Y2-r2 < 0 (X,Y) Lies Inside a Circle = 0 (X,Y) Lies on a Circle> 0 (X,Y) Lies Outside a Circle

6

Page 7: computer notes - Scan Conversion

Computer Graphics(ecomputernotes.com) Page 7 of 7

Scan Converting an Ellipse

Ellipse is same like Circle, but the main difference between the Circle and Ellipse is that, Circle uses Eight Points but an Ellipse uses four points. For Representing an Ellipse there are two methods for drawing, first is the polynomial methods and trigonometric methods.

1) Using Polynomial Methods 2) Using Trigonometric Methods.

Using Polynomial Methods: - The Polynomial Equation of Ellipse on the Origin is which has points is

7