Infinite 2D Coordinate Space

I am working with a 1 dimensional array of an RGBA struct composed of unsigned 8-bit integers. I have implemented a very basic line algorithm, and can draw lines from one point to another accurately, as long as they are within my 2D coordinate space.

For cases where one of my end points is outside of the range of my image, my system breaks down. I am trying to understand conceptually in computer graphics how one might implement an infinite (or perceptually infinite) coordinate space to take into account lines that go outside the range of my pixel array.

For example, consider that my pixel array represents a 500x500 pixel space. If I draw a line from (0, 250) to (7000, 100), I would ideally like the line would be drawn to that coordinate that is out of view with the accurate slope of the line maintained.

• You find the intersection of your line, with the edge of your pixel array, and draw only the visible part. – lightxbulb Nov 9 '19 at 9:04
• This solution works for the line example, but does not scale up well. For example, I would have to have a separate approach for every type of shape and its interaction with the edge of the pixel array. If I were to apply a transformation, such as a rotation to the array, shapes that are slightly off screen may not appear correctly. There needs to be some kind of buffer. – rikitikitavi Nov 9 '19 at 14:41
• You will have to find intersections fir any shape, yes. The other option is to have a condition whether to draw a pixel - so that if it is outside the array, it does not do anything. Rotating that array is equivalent to applying the inverse rotation to the shapes too. – lightxbulb Nov 9 '19 at 14:44
• "I would have to have a separate approach for every type of shape and its interaction with the edge of the pixel array." If all your shapes are polygons, you only need to implement a single polygon clipping algorithm. – user106 Nov 9 '19 at 16:03
• +1 to @Rahul 's answer - you want to look up up clipping. (BTW did you really mean "1 dimensional array?") – Simon F Nov 11 '19 at 9:17