Drawing Lines in 2 Dimensions

Similar documents
MAT 155: Describing, Exploring, and Comparing Data Page 1 of NotesCh2-3.doc

Lecture 14: Minimum Spanning Tree I

Quadrilaterals. Learning Objectives. Pre-Activity

KS3 Maths Assessment Objectives

ES205 Analysis and Design of Engineering Systems: Lab 1: An Introductory Tutorial: Getting Started with SIMULINK

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

An Intro to LP and the Simplex Algorithm. Primal Simplex

A SIMPLE IMPERATIVE LANGUAGE THE STORE FUNCTION NON-TERMINATING COMMANDS

Universität Augsburg. Institut für Informatik. Approximating Optimal Visual Sensor Placement. E. Hörster, R. Lienhart.

CSE 250B Assignment 4 Report

Course Updates. Reminders: 1) Assignment #13 due Monday. 2) Mirrors & Lenses. 3) Review for Final: Wednesday, May 5th

Topics. Lecture 37: Global Optimization. Issues. A Simple Example: Copy Propagation X := 3 B > 0 Y := 0 X := 4 Y := Z + W A := 2 * 3X

Delaunay Triangulation: Incremental Construction

Polygon Side Lengths NAME DATE TIME

Algorithmic Discrete Mathematics 4. Exercise Sheet

Motivation: Level Sets. Input Data Noisy. Easy Case Use Marching Cubes. Intensity Varies. Non-uniform Exposure. Roger Crawfis

Representations and Transformations. Objectives

Performance of a Robust Filter-based Approach for Contour Detection in Wireless Sensor Networks

DAROS: Distributed User-Server Assignment And Replication For Online Social Networking Applications

Routing Definition 4.1

Areas of Regular Polygons. To find the area of a regular polygon. The Solve It involves the area of a polygon.

1 The secretary problem

else end while End References

AN ALGORITHM FOR RESTRICTED NORMAL FORM TO SOLVE DUAL TYPE NON-CANONICAL LINEAR FRACTIONAL PROGRAMMING PROBLEM

IMPLEMENTATION OF AREA, VOLUME AND LINE SOURCES

Stochastic Search and Graph Techniques for MCM Path Planning Christine D. Piatko, Christopher P. Diehl, Paul McNamee, Cheryl Resch and I-Jeng Wang

TAM 212 Worksheet 3. Solutions

Multi-Target Tracking In Clutter

The norm Package. November 15, Title Analysis of multivariate normal datasets with missing values

Laboratory Exercise 2

Advanced Encryption Standard and Modes of Operation

xy-monotone path existence queries in a rectilinear environment

Log1 Contest Round 2 Theta Geometry. 4 points each 1 What is the area of an isosceles right triangle with legs of length 3?

Planning of scooping position and approach path for loading operation by wheel loader

VLSI Design 9. Datapath Design

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

See chapter 8 in the textbook. Dr Muhammad Al Salamah, Industrial Engineering, KFUPM

ALIASING AND ALPHA Introduction to Graphics, Lecture 3. Anthony Steed , Jan Kautz

Localized Minimum Spanning Tree Based Multicast Routing with Energy-Efficient Guaranteed Delivery in Ad Hoc and Sensor Networks

Karen L. Collins. Wesleyan University. Middletown, CT and. Mark Hovey MIT. Cambridge, MA Abstract

SIMIT 7. Component Type Editor (CTE) User manual. Siemens Industrial

Interface Tracking in Eulerian and MMALE Calculations

Diffraction I Version 1.0 : March 12, 2019

Maneuverable Relays to Improve Energy Efficiency in Sensor Networks

Motion Control (wheeled robots)

SLA Adaptation for Service Overlay Networks

CENTER-POINT MODEL OF DEFORMABLE SURFACE

Laboratory Exercise 6

Analysis of slope stability

Mid-term review ECE 161C Electrical and Computer Engineering University of California San Diego

A Boyer-Moore Approach for. Two-Dimensional Matching. Jorma Tarhio. University of California. Berkeley, CA Abstract

Generic Traverse. CS 362, Lecture 19. DFS and BFS. Today s Outline

Minimum congestion spanning trees in bipartite and random graphs

On successive packing approach to multidimensional (M-D) interleaving

Variable Resolution Discretization in the Joint Space

Hassan Ghaziri AUB, OSB Beirut, Lebanon Key words Competitive self-organizing maps, Meta-heuristics, Vehicle routing problem,

UC Berkeley International Conference on GIScience Short Paper Proceedings

Laboratory Exercise 6

Cutting Stock by Iterated Matching. Andreas Fritsch, Oliver Vornberger. University of Osnabruck. D Osnabruck.

How to Select Measurement Points in Access Point Localization

A METHOD OF REAL-TIME NURBS INTERPOLATION WITH CONFINED CHORD ERROR FOR CNC SYSTEMS

Gray-level histogram. Intensity (grey-level) transformation, or mapping. Use of intensity transformations:

Image authentication and tamper detection using fragile watermarking in spatial domain

Power Aware Location Aided Routing in Mobile Ad-hoc Networks

Loop Forming Snake-like Robot ACM-R7 and Its Serpenoid Oval Control

Trainable Context Model for Multiscale Segmentation

3D MODELLING WITH LINEAR APPROACHES USING GEOMETRIC PRIMITIVES

Z-transformation in simulation of continuous system

Towards an Efficient Optimal Trajectory Planner for Multiple Mobile Robots

Increasing Throughput and Reducing Delay in Wireless Sensor Networks Using Interference Alignment

Lecture Outline. Global flow analysis. Global Optimization. Global constant propagation. Liveness analysis. Local Optimization. Global Optimization

Chapter 13 Non Sampling Errors

Part 1 A New Number Format: The Unum

Shortest Path Routing in Arbitrary Networks

Lecture 8: More Pipelining

TAM 212 Worksheet 3. The worksheet is concerned with the design of the loop-the-loop for a roller coaster system.

Computer Arithmetic Homework Solutions. 1 An adder for graphics. 2 Partitioned adder. 3 HDL implementation of a partitioned adder

ML85C. Data Sheet. Press fit monitoring module. Special features. Block. diagram PLC. B en

On combining Learning Vector Quantization and the Bayesian classifiers for natural textured images

Course Project: Adders, Subtractors, and Multipliers a

Possible application of fractional order derivative to image edges detection. Oguoma Ikechukwu Chiwueze 1 and Alain Cloot 2.

The Comparison of Neighbourhood Set and Degrees of an Interval Graph G Using an Algorithm

UNIT -8 IMPLEMENTATION

A note on degenerate and spectrally degenerate graphs

NUMERICAL MODELING ON THE DAMPING CONTROL OF TLD STRUCTURE

Rasterization: Geometric Primitives

Laboratory Exercise 6

The Crank-Nicholson method for a nonlinear diffusion equation

Aalborg Universitet. Published in: Proceedings of the Working Conference on Advanced Visual Interfaces

Lecturer: Ivan Kassamakov, Docent Assistants: Risto Montonen and Anton Nolvi, Doctoral

Midterm 2 March 10, 2014 Name: NetID: # Total Score

Modeling of underwater vehicle s dynamics

Uninformed Search Complexity. Informed Search. Search Revisited. Day 2/3 of Search

Shortest Paths Problem. CS 362, Lecture 20. Today s Outline. Negative Weights

Kinematics Programming for Cooperating Robotic Systems

Exercise 4: Markov Processes, Cellular Automata and Fuzzy Logic

arxiv: v3 [cs.cg] 1 Oct 2018

Points and lines. x x 1 + y 1. y = mx + b

A NEW APPROACH IN MEASURING OF THE ROUGHNESS FOR SURFACE CONSTITUTED WITH MACHINING PROCESS BY MATERIAL REMOVAL

Transcription:

Drawing Line in 2 Dimenion Drawing a traight line (or an arc) between two end point when one i limited to dicrete pixel require a bit of thought. Conider the following line uperimpoed on a 2 dimenional 7x7 pixel grid The pixel are indexed with the uual creen convention of x running from left to right and y running from top to bottom. Which pixel hould be et in order to repreent the line? If we increment our way vertically downward through the y value, etting the pixel in the appropriate x column a we go, we get The pixellated line ha gap in it. If, on the other hand, we increment our way horizontally acro through the x value, etting the pixel in the appropriate y can-line a we go, we get Thi i clearly a much more atifactory olution. We note, however, that had the line been longer in y than in x then the firt olution would have delivered the better reult. The magnitude of the lope of the line i the ey here. If the x range exceed the y range then the magnitude of the lope i le than 1 and we hould increment our way through x (and vice vera). - 1 -

In fact, there are 4 cae to conider when electing which pixel hould be ued to contruct a continuou line 1. Poitive lope le than 1 2. Poitive lope greater than or equal to 1 3. Negative lope le than or equal to -1 4. Negative lope greater than -1 If we now the end point of the line to be drawn we can alway calculate the lope y e y m = x e x A poitive lope (in creen co-ordinate) mean that the line i monotonic increaing (a x increae o doe y) whilt a negative lope indicate the oppoite (a x increae y decreae). The intercept, where the line meet (or would meet if long enough) the y axi i alo readily obtained c= y m x Of coure, thi relationhip hold for all pair of x and y value on the line o we can determine a y value for any x value and vice vera or, y = c + m x x = = y c y c m m m Now, if we conider only change in x and y we don t need to worry about the intercept except when determining the firt pixel to be plotted and, y = m x x = y m We hall conider two algorithm for drawing a 2D line on a diplay creen baed on the above principle; the Digital Differential Analyer and Breenham algorithm. - 2 -

The Digital Differential Analyer (DDA) Algorithm The DDA i a can-converion algorithm which ample a line at unit interval along one axi and determine integer value nearet the line for the other axi. Conider the line we have been looing at. The DDA will ample along the x axi in thi cae determining y value a it goe y y m + 1 = + If our line had a lope whoe magnitude wa greater than 1 (45º) then the DDA would need to ample along the y axi determining x value uing x = + 1 x + 1 m Thee equation will wor whether the lope i poitive or negative. When the lope i negative the x and y value will vary inverely but m will have the oppoite ign o all will be well Note that m i not necearily an integer, o the DDA require floating point arithmetic and rounding of the reult. Thi will low up the drawing proce even if implemented in hardware. - 3 -

Breenham Algorithm Breenham algorithm can-convert line more efficiently than the DDA by uing only integer arithmetic. It can alo be adapted to diplay curve. Conider, once again, a line with poitive lope le than 1 o we ample along x determining which y to plot. If we have jut plotted the pixel (x, y ) we now need to decide whether to plot (x +1, y ) or (x +1, y +1 ) a the next pixel on the line. Note that x +1 = x +1 and y +1 = y +1. Let the vertical diparitie of the pixel poition from the actual mathematical line be given by d 1 and d 2. Then, and, ( ) d y y m x c y 1 = = + 1 + ( ) ( ) d2 = y + 1 y = y + 1 m x + 1 c Conider now the difference between thee two value ( ) d1 d2 = 2m x + 1 2y + 2c 1 If we let the difference between the x and y co-ordinate of the end point of the line be given by and, x = x x e y = y y e and if we init that thee endpoint co-ordinate are integer (which they will be if they are pecified a pixel) then we can write the lope of the line a a ratio of two integer m y = x If we now ubtitute thi ratio for m above we get and o, y d1 d 2 = 2 ( x + 1) 2 y + 2c 1 x - 4 -

where the term in quare bracet i contant and independent of the pixel poition. We hall call thi term b from now on. If we now define a deciion parameter a follow Then when p i poitive we hould chooe (x +1, y +1) a the pixel to plot and when it i negative we hould chooe (x +1, y ). Everything apart from the contant, b, in thi deciion can be calculated uing integer arithmetic o if we cam eliminate the need for b we have a method for plotting line uing integer arithmetic only. Conider the difference ( ) ( ) x d1 d2 = 2 y x 2 x y + 2 y + x 2c 1 ( ) p = x d d 1 2 = 2 y x 2 x y + b We have already noted that x +1 = x +1 o we can re-write thi a and where (y +1 -y ) i either 0 or 1 depending on the ign of p. So we have a recurrence equation which involve only integer calculation and all that i left i to determine a tarting value p 0 for it. Uing the tarting point of the line (x, y ) we can determine the intercept ( ) ( ) p p = 2 y x x 2 x y y + 1 + 1 + 1 ( ) p = p + 2 y 2 x y y + 1 + 1 y c = y mx = y x x and ubtituting thi into the equation for p we obtain p0 = 2 y x ============== - 5 -

Aliaing and Anti-aliaing When we produce line with Breenham algorithm, whilt we might be quite impreed with the peed at which we can generate them, we will not be overly enamoured with the way they loo. In general they will appear jagged, tepped, rateried. Thi effect i nown a aliaing, a term derived from ampling ignal at dicrete point in time and thu loing any information conveyed between thoe dicrete time. Our mathematically ideal line decribe a function whoe range i continuou but which our pixellated rater creen require to become dicrete. In effect we are ampling at dicrete point along the line and plotting the mot appropriate pixel for each ample. We have no choice of coure; the creen reolution contrain our ampling rate o aliaing i inevitable. Furthermore, our ideal mathematical line ha zero thicne but the line we wih to diplay mut have a thicne to be een. Indeed, we mae a virtue of thi requirement and put line of varying thicne to good ue. In computer graphic a traight line i, in reality, a thin rectangle and we mut treat it a uch. Conider the following line uperimpoed on a 2 dimenional 7x7 pixel grid Thi line ha a very clear thicne and i quite obviouly a filled rectangle. If we pixellate it, a we did with our mathematically ideal line previouly, we get The pixellated line diplay clear evidence of aliaing. Can we mae it more aethetically appealing? Of coure, the anwer i ye. We can anti-alia it. Anti-aliaing algorithm wor by partially illuminating pixel which are adjacent to thoe plotted by the line drawing algorithm (e.g. the DDA or Breenham algorithm). Thi mean that anti-aliaed line will be wider than wa probably intended. The two mot common method for anti-aliaing are filtering and uperampling. - 6 -

Filtering Thi technique i baed on the concept that each pixel ha an area of influence around it. If our rectangular-haped line overlap the area of influence of a pixel then that pixel hould be illuminated by an amount proportional to the degree of overlap. Thi amount i determined by a filter function. One popular filtering cheme i baed on circular area of influence which are one pixel in radiu. I.e. the area of influence of each pixel extend a far a the centre of it four nearet neighbour The filter function i defined to be a cone with it bae being the area of influence and it apex lying directly above the pixel centre, at a height which produce an overall volume for the cone of unity. The interection of a pixel area of influence with the rectangular line i then determined and the volume of the cone directly above that interection yield the amount of illumination to be applied to that pixel. Clearly the amount of illumination applied to any pixel will range from 0 (pixel area of influence totally outwith the line) up to 1 (pixel totally within the line). Thi i clearly a computationally expenive proce. In order to eep the computation time down it i normal to pre-calculate table of value for the filter function. The downide to thi i that the reulting algorithm are not very flexible the filter function, area of influence and palette ize are all fixed in a given table and any change to thee value will require a new table to be produced. - 7 -

Superampling Another technique for anti-aliaing ue the concept of ub-pixel. Each pixel i divided into, ay nine, ub-pixel We then count the number of ub-pixel that the line overlap. We need a reference point within each ub-pixel to ue in thi counting proce. It doen t matter where it i a long a we ue it conitently for all ub-pixel. A corner, uch a the top-left, i a popular choice. Centre would produce a more aethetically pleaing reult but at the cot of computational efficiency. The proportion of ub-pixel which the line overlap i then ued to determine the illumination, in dicrete tep from 0 through to 1. Clearly the larger the number of ub-pixel which the pixel i divided into, the finer the reolution that can be accomplihed in the illumination. Once again we have to trie a balance between aethetic and computation time. Thi will be determined by the need of the particular application. - 8 -