Randomly visit points in a triangle

For the right triangle defined by the equation aX + bY <= c for integers

I want to build each pixel (*) in a triangle once and only once, in a pseudo-random order and without saving a list of previously hit points.

I know how to do this with a line segment between 0 and x

select a random point '' 'along the line,
   pick' p ', which is coprime with x repeat up to x times: O next = (O cur + P) MOD x

To do this for a triangle, I would like 1. We need to count the number of pixels in the list of sans triangles
2. Match integer 0..points to a pair of x, y, which is a valid pixel inside the triangle

I hope that any solution can be generalized to pyramids and higher dimensional shapes.

(*) I use a CG member pixel for a pair of integer points X, Y for which the equation is executed.

+5
source share
5 answers

Since you want to guarantee that each pixel is visited once and only once, it is better to think about pixels rather than real triangles. You can cut triangles horizontally and get a bunch of horizontal scan lines . Connect the scan lines together, and you have turned your “triangle” into a long line. Apply your point visiting algorithm to your long chain of scan lines.

, , , , , (x, y) (t) .

: , Bresenham. , , y. y x. x y- - , x y- - . " ". Google.

+3

.

, () , [0,1] . , . , ; , .

+2

, , ( O (n)), . .

0

, , , , , .

, . "" , . , , . , , , , .

0

, . , , . O , , , .

0
source

All Articles