![]() Int endX, endY //the ending point of our line segmentĪrray returnPointsInSegment //all points lying on this line segment Int startX, startY //the starting point of our line segment Round each point in the line segment to either the pixel above or below.īefore we implement Bresenham's Algorithm, lets put together a basic line segment class to be used in our engine:. ![]() Determine sx, sy, and error catching properties (I'll show the mathematical definition for these below).Identify a line segment's direction by determining its \(dx\) and \(dy\) properties (\(dx = x_\)).Receive a line segment's beginning and ending points as input.Step by step, Bresenham's Algorithm works like this: ![]() They are represented by two distinct points (one beginning point and one ending point), and the line that connects the two. The most commonly used algorithm in rasterizing a line segment is called Bresenham's Algorithm. Line segments are one of the simplest shapes that can be drawn, and so are often one of the first things covered in any geometry class. Let's start with one of the more simple shapes to rasterize: the line segment. For example, a point can fall onto the co-ordinate \((3.2, 4.6)\) in mathematics, but when we render it, we must nudge it to \((3, 5)\) so it can fit into the pixel structure of our screen.Įach type of shape that we rasterize will have its own algorithm for doing so. Rasterization (or rasterisation, if you like) is the process of taking a shape described in a vector graphics format (or in our case, mathematically) and converting it into a raster image (where the shape is fit onto a pixel structure).īecause math isn't always as precise as we need it to be for computer graphics, we must use algorithms to fit the shapes it describes onto our integer-based screen. Now, let's take a look at some new stuff! You can check out the sample program from the third part of the series to see how they work together. Null drawScene () //draws all needed objects to the screen Vector Scale ( s0, s1, s2 ) //receives a scaling 3-tuple, returns the scaled vectorĪrray objectsInWorld //an array of all existent objects Vector SubtractVectorFromVector ( Vector ) Point SubtractVectorFromPoint ( Vector ) ĭrawPoint //draw a point at its position tuple
0 Comments
Leave a Reply. |