<p>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, <strong>as long as they are within my 2D coordinate space</strong>.</p>

<p>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 <strong>how one might implement an infinite (or perceptually infinite) coordinate space</strong> to take into account lines that go outside the range of my pixel array.</p>

<p>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.</p>

CC BY-SA 4.0
2019-11-09T09:04:56.013Z
You find the intersection of your line, with the edge of your pixel array, and draw only the visible part.
lightxbulb
CC BY-SA 4.0
2019-11-09T14:41:13.727Z
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
CC BY-SA 4.0
2019-11-09T14:44:53.943Z
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
CC BY-SA 4.0
2019-11-11T09:17:52.903Z
+1 to @Rahul 's answer - you want to look up up _clipping_.  (**BTW**  did you really mean "**1** dimensional array?")
Simon F
CC BY-SA 4.0
2019-11-11T16:26:05.500Z
@SimonF Yes. I meant 1 dimensional array. The first element in the array is the upper left hand corner, and the last element is the lower right hand corner. I use x + width * y to place pixels in the correct element.
rikitikitavi
<2d-graphics><pixels>
Infinite 2D Coordinate Space
rikitikitavi
# Infinite 2D Coordinate Space

(Asked by: username_0 on 2019-11-09)

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.

**Tags:** 2d-graphics, pixels

> **Comments:**
> **username_1**: You find the intersection of your line, with the edge of your pixel array, and draw only the visible part.  
> **username_0**: 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.  
> **username_1**: 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.  
> **username_2**: +1 to @Rahul 's answer - you want to look up up _clipping_.  (**BTW**  did you really mean "**1** dimensional array?")  
> **username_0**: @username_2 Yes. I meant 1 dimensional array. The first element in the array is the upper left hand corner, and the last element is the lower right hand corner. I use x + width * y to place pixels in the correct element.  

---

## 0 answers

