📜 ⬆️ ⬇️

Krita: Four-Point Perspective Transformations


About a month ago, the project of Crete successfully completed the fundraising campaign on Kickstarter (see previous post ), now the developers are completely immersed in the process of writing the promised buns. The first goal realized was four-point perspective transformations. In this article I will talk about their implementation and application.

In general, “three-dimensional-looking” transformations existed in Crete for a long time, but it was inconvenient to use them. The fact is that the standard transformation tool only allowed to rotate the object around three axes. What is very bad for the most demanded custom script: add texture to an object drawn from the perspective. The simplest example is to place windows on the walls of a building.

The simplest solution to this problem is to set perspective on four points: select the window, drag its corners to the desired position, and you're done! This method has been implemented.
')


Math transform


As is known, a perspective transformation on a plane is defined by a homogeneous coordinate transformation matrix .



This matrix consists of eight significant elements (scale-turns ( ), offset ( ), perspective ( )) and one scale factor. Thus, in order to uniquely define a transformation, we need to have 8 equations relating these values. Four points, each with two coordinates, just set these equations, provided that any three of them do not lie on one straight line.

Let there be four points (x1, y1) ... (x4, y4) in the coordinates of the original image. Express the fourth point through a linear combination of the first three:



We solve the system and write the transformation matrix, which will translate (1,0,0) into a multiple (x1, y1,1), (0,1,0) into a multiple (x2, y2,1), (0,0,1 ) in (x3, y3,1) and (1,1,1) in (x4, y4,1)



Now, we repeat these steps for the coordinates of points in a finite space and obtain the matrix B in primed coordinates.



Then the desired transformation matrix will be



Matrix will convert the original coordinates of the points to intermediate dummy points (1,0,0), (0,1,0), (0,0,1) and (1,1,1), and the matrix in turn converts them to the desired values.

The required matrix is ​​received!

Conversion of vanishing points


The vanishing point is the point at which the parallel lines of the object converge on the perspective image. One of the requirements of artists was the ability to drag these points directly. At first it was not entirely clear how to implement such a functional, however, it soon became clear that vanishing points in homogeneous coordinates are expressed elementarily:



Further transformations do not change.

Instead of conclusion


The described functionality is available in the latest builds of Crites under Windows and in the Krita Lime repositories for Ubuntu. You can update and draw!

Finally, a video from Pavel Geraskin, demonstrating the capabilities of a new instrument:

Source: https://habr.com/ru/post/232019/


All Articles