Unformatted text preview:

OUTPUT PRIMITIVES-I1Instructor: Munazza BibiOutline• Line Drawing Algorithms• Incremental Line Drawing• DDA Line Drawing• Bresenham Line Algorithm• Circle Drawing Algorithms• Drawing Circle using Cartesian Coordinates• Drawing Circle using Polar Coordinates• Midpoint Circle Algorithm10/10/20062Output Primitives• The Primitives are the simple geometric functions that are used to generate various Computer Graphics required by the User. • Some most basic Output primitives are point-position(pixel), and a straight line.Computer Screen Coordinates• In video monitors Locations are referenced using Integer Screen coordinates which corresponds to the pixel positions in the frame buffer. • These coordinates gives us the Column Number(x) and Scan Line Number(y).• During screen refreshing the address of pixel along with other information stored in frame buffers are used to generated the pixel on the screen. • A frame buffer stores the pixel location and other information such as intensity, color of the pixel position that is to be generated on the screen.Point•Pixel:• The smallest dot illuminated that can be seen on screen.• A point function contains location using x and y coordinate•Picture: • Composition of pixels makes picture that forms on whole screenLine•A geometrical object that is straight, infinitely long and infinitely thin.•Shortest connection between two points.•Also called straight curve.•A line may have slope of 1 greater than 1 or less than 1.6Line• Given two points, in Euclidean geometry, one can always find exactly one line that passes through the two points; this line provides the shortest connection between the points and is called a straight line.• Two different lines can intersect in at most one point; whereas two different planes can intersect in at most one line.Slope•A line may have three forms with respect to slope•Slope>1•Slope<1•Slope=18• |m|=1 |m|<1• |m|>19Line Drawing Techniques•Incremental Line Drawing•DDA Line Drawing•Bresenham Line Algorithm10Line Drawing Algorithms•Line equation y = m . x + b•slope mY-intercept11Incremental Line Algorithm• This algorithm exploits simple line equation y = m x + b• Where m = dy / dx and b = y – m x• Now check if |m| < 1 then starting at the first point, simply increment x by 1 (unit increment) till it reaches ending point;• whereas calculate y point by the equation for eachx and conversely if |m|>1 then increment y by 1 till it reaches ending point; whereas calculate x point corresponding to each y, by the equation.Incremental Line Algorithm• why these two cases are tested. • First if |m| is less than 1 then it means that for every subsequent pixel on the line there will be unit increment in x direction and there will be less than 1 increment in y direction and vice versa for slope greater than 1.• Let us clarify this with the help of an example:More towards x axis14• Suppose a line has two points p1 (10, 10) and p2 (20, 18)• Now difference between y coordinates that is dy = y2 – y1 = 18 – 10 = 8• Whereas difference between x coordinates is dx = x2 – x1 = 20 – 10 = 10• This means that there will be 10 pixels on the line in which for x-axis there will be• distance of 1 between each pixel and for y-axis the distance will be 0.8.15• Consider the case of another line with points p1 (10, 10) and p2 (16, 20)• Now difference between y coordinates that is dy = y2 – y1 = 20 – 10 = 10• Whereas difference between x coordinates is dx = x2 – x1 = 16 – 10 = 616• This means that there will be 10 pixels on the line in which for x-axis there will be distance of 0.6 between each pixel and for y-axis the distance will be 1.• Now having discussed this concept at length let us learns the algorithm to draw a line using above technique, called incremental line algorithm:Incremental Line Algorithmdx = p2.x – p1.xdy = p2.y – p1.ym = dy / dxx = p1.xy = p1.yb = y – m * x17Incremental Line Algorithm(contd..)if |m| < 1for counter = p1.x to p2.xdrawPixel (x, y)x = x + 1y = m * x + belsefor counter = p1.y to p2.ydrawPixel (x, y)y = y + 1x = ( y – b ) / m18Incremental Line Algorithm•Simple and easy•Involves a lot of mathematical calculation•Works only in incremental direction•Slow19DDA• DDA abbreviated for digital differential analyzer has very simple technique.• Find difference dx and dy between x coordinates and y coordinates respectively ending points of a line.• If |dx| is greater than |dy|, than |dx| will be step and otherwise |dy| will be step.if |dx|>|dy| thenstep = |dx|elsestep = |dy|DDA• Now very simple to say that step is the total number of pixel required for a line.• Next step is to divide dx and dy by step to get xIncrement and yIncrement that is the increment required in each step to find next pixel value.• xIncrement = dx/step• yIncrement = dy/step• Next a loop is required that will run step times. In the loop drawPixel and add xIncrement in x1 by and yIncrement in


View Full Document

Berkeley COMPSCI 184 - OUTPUT PRIMITIVES-I

Documents in this Course
Load more
Download OUTPUT PRIMITIVES-I
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view OUTPUT PRIMITIVES-I and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view OUTPUT PRIMITIVES-I 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?