Contents
- 1 What is the algorithm for drawing a line?
- 2 How to create a line of arbitrary thickness?
- 3 What are the pixels on a computer screen?
- 4 How to draw a line using X and Y coordinates?
- 5 How to find a point on a line?
- 6 Which is the most efficient algorithm to find a straight line?
- 7 Which is more efficient a randomized algorithm or an exact algorithm?
What is the algorithm for drawing a line?
Given coordinate of two points A (x1, y1) and B (x2, y2). The task to find all the intermediate points required for drawing line AB on the computer screen of pixels. Note that every pixel has integer coordinates. Below are some assumptions to keep algorithm simple. We draw line from left to right. Slope of the line is between 0 and 1.
How to create a line of arbitrary thickness?
Working and tested C code is available from Github C code . Here a test page including a few sample lines created by this code. The black pixels are the starting points for the algorithm. Here is a paper and Delphi implementation of a modified version of Bresenham’s algorithm for drawing thickened lines.
What kind of algorithm is Bresenham’s line algorithm?
From Wikipedia, the free encyclopedia Bresenham’s line algorithm is a line drawing algorithm that determines the points of an n -dimensional raster that should be selected in order to form a close approximation to a straight line between two points.
What are the pixels on a computer screen?
Computers draw images using pixels. Pixels are the tiny squares that make upthe image you see on computer monitors. If you look carefully at a computerscreen with a magnifying glass, you can see the individual pixels.
How to draw a line using X and Y coordinates?
You could make use of pygame depending on what you are doing it for as it allows a similar: I tried the turtle graphics, but it works using degrees. If you are already using turtle you can use a Tkinter canva : Just a warning, depending on the math library you use, this will probably output in radians.
How to describe a line on the coordinate plane?
Definition: A straight line on the coordinate plane can be described by the equation where m is the slope of the line and Px, Py are the coordinates of a given point on the line. Try this The slider on the right controls the slope (m) of the line. Drag the point P. The equation and the line will change accordingly.
How to find a point on a line?
To locate points on the line. If I wanted to find a point on the same line which has an x-coordinate of say 20, I could insert 20 for x in the equation y=1.2(x-15)+27and find that its y-coordinate is 33. Similarly, if I was given the y-coordinate, I could solve it for x instead.
Which is the most efficient algorithm to find a straight line?
Again an O (n^2) solution with pseudo code. Idea is create a hash table with line itself as the key. Line is defined by slope between the two points, point where line cuts x-axis and point where line cuts y-axis. Solution assumes languages like Java, C# where equals method and hashcode methods of the object are used for hashing function.
What’s the slope of a line in Bresenham algorithm?
We draw line from left to right. Slope of the line is between 0 and 1. We draw a line from lower left to upper right. Let us understand the process by considering the naive way first. Above algorithm works, but it is slow.
Which is more efficient a randomized algorithm or an exact algorithm?
However, if you assume a large number of points lie on the same line (say the probability that a random point in the set of points lie on the line with the maximum number of points is p) and don’t need an exact algorithm, a randomized algorithm is more efficient. maxPoints = 0 Repeat for k iterations: 1.