MATH FOR TILEABLE IMAGES WITH POVRAY


Hints, tricks and general aspects



The hard math

So, you are trying to create a tileable scene ... sit back for a while and draw a skecth of it ... this is NOT going to be easy, you know. Keep in mind that your model must be repetitive, whatever there is at the right edge must be also at the left edge. And don't forget the bottom and the top edges ...

The ray that is cast from the lower left corner will go through the point <0,0,0> in your model space. Now you should identify two other points in your model space whose surrounding are exactly the same as for point <0,0,0>. These points will specify your view of the model, call these points P1 and P2. The ray that is cast from the lower right corner of the image will go through the point P1 and the ray for the upper left corner of the image will go through the point P2. Because we are using projection (orthographic camera) the ray cast for the upper right corner will go through the point P1+P2 in your model space. The other way saying this is that the point P1 is projected to lower right corner and point P2 is projected to upper left corner. You should also decide the aspect ratio R of the desired image.

Now simply calculate alpha^2, beta^2, gamma, image width W, and image height H=RW. Calculate the square roots and pick the signs so that alpha times beta is of the same sign as the dot-product of P1 and P2. If now alpha+beta is negative, swap the signs for both of them. The equation alpha+beta >0 simply means that the upper right corner is further away from the camera than the corner <0,0,0>.

Next, calculate the transformation matrix A. You should be able to use this transformation matrix to rotate your camera to correct angle, or you can calculate the rotation angles from the elements of the matrix as given below. (X, Y, and Z).

Now insert these values into this template and create your scenery ...

Here you can find the same image in EPS-format:
And a short MATLAB-program povmath.m for calculating the image size and the rotation angles.

An example

Okay, let's try to create something in order to clarify things a bit ...

So, as an example we'll create a set of infinitely ascending steps. Here is a sketch of the target image where you can see the orientation of the axis (remember that POVRAY has a left-handed coordinate system) as well as the dimensions and the points P1 and P2.

As you can see from the sketch, the faces of the steps are 1 times 1 units and are parallel to X-Y plane. When moving in X-direction the offset to the next step is <1,-0.1,-0.1> and in Y-direction the offset is <0,1,-0.4>.

Now we have to select the two points P1 and P2. As one can see, the point P1 is selected from the step that is one row below the <0,0,0> corner-point and 5 steps to the right of it, giving the coordinates 5*<1,-0.1,-0.1> - <0,1,-0.4> = <5,-1.5,-0.1>. The point P2 is located 3 rows above and 2 steps to positive X-direction giving: 2*<1,-0.1,-0.1> + 3*<0,1,-0.4> = <2,2.8,-1.4>. For the aspect ratio R (image height/image width) we select a value 0.5 as the width of the sketch seems to be about twice the height.

Now we get:

alpha^2 = 4.3684
beta^2 = 8.0771
P1*P2 = 5.9400 (dot-product)
alpha = 2.0901
beta = 2.8420
alpha*beta <-> P1*P2 (are of the same sign)
alpha+beta > 0.0 (We don't need to swap signs)
W = 4.7845
H = 2.3923
gamma = 340.9044
A =
0.7668-0.6237-0.1520
0.0792 0.3269-0.9417
0.6370 0.7100 0.3001
X = -72.3252 deg
Y = 8.7423 deg
Z = -39.1248 deg
Now we can insert the values W, H, X, Y, and Z with the POV-code for the steps into the POV-template to get example.pov. Then we render the file in size 400x200 (aspect ratio was 0.5) to get a tileable image.