I have a geometric pattern – say, a cross:
Which I want to repeat with some overlap and tile … easy:
The blue square marks the 100×100 px unit tile.
However, here comes the catch: I want to rotate the image by about 30° and then tile it. This has proved surprisingly hard; of course rotating the image is easy – but finding a perpendicular unit tile (the blue block in the above image) isn’t:
Clearly the 100×100 unit tile won’t cut it. How do I choose the correct unit tile? The position presumably doesn’t matter, only the size is important, but I don’t know how to calculate that. Intuitively I expect that the rotation angle and the dot product will feature heavily but that’s as far as I got1. What’s worse, the rotation for arbitrary angles isn’t exact due to the inherent discreteness of pixels so even if I calculate the mathematically correct size it won’t necessarily result in a seamless tile.
So how can I calculate an optimal angle/size combination given the size of the perpendicular unit cell (here, 100×100) and an approximate desired angle?
1 My thought was that (using Wikipedia notation), since we want the projection of A onto B to be as long as B, we have |B|=|A|·cosϑ, and thus |A|=|B|/cosϑ. Which, in my case, would yield the new length |A|=115.470 but a simple try shows that this cannot be correct by a long shot, besides yielding an ugly non-integral number. In fact, just looking at the above rotated picture we can see that the whole 200×400 picture doesn’t contain a repeating perpendicular unit.
Answer
I found this that might be of help: Create rotated tileable patterns
As you mention, there's math involved that is way beyond my understanding, so I'll only bring some of the principles that have to do with designing it.
Basically, the 'solution' would be:
- Take an unrotated, tileable texture that repeats horizontally and vertically.
- Tile it to a large image.
- Rotate the large image by the desired angle.
- Find the size of the smallest repeatable unit of this rotated texture (using the math below).
- Crop the large image to the size of the repeatable unit.
The image below shows a rotated texture that was formed by tiling the original unrotated pattern and then rotating the resulting mosaic. The basic unrotated texel is highlighted and has width w and height h. The angle of rotation is the acute angle formed by the w line with the horizontal:
Since we want acute angles, if you are rotating in the other direction, then the diagram above looks like this:
The image size (w' x h') necessary to make the texture tileable can be found as follows:
The explanation goes on a little bit more, so if you found it useful please feel free to edit the answer (or post a new one).
No comments:
Post a Comment