Graphical transformation generally refers to generating a new image after the geometric information of an object is amplified, reduced, translated, and rotated. It is always closely linked to the relevant coordinate system. From the point of view of relative motion, the graphic transformation can be seen as a change between the image and the coordinate system, that is, the coordinate system is fixed and the coordinate value of the object in the coordinate system changes; it can also be seen that the image does not move, but the coordinate system changes relative to the image, so that the object has a new coordinate value under the new coordinate system. Generally, graphical transformations only change the geometric shape and size of an object, but do not change its topological structure.
To output a graph on a computer screen or plotter, you must specify the part or whole to be displayed in a graph and the output position of the device. Only one area can be displayed on the computer screen, or several areas can be displayed, which are placed in different display locations. You can perform geometric operations such as translation, rotation, and scaling on the image during display or output. If the image is out of the range specified by the display area, you must crop the image.
This chapter includes:
Observe the process introduction;2d geometric TransformationChange from window to view area2d CroppingAlgorithm |
We will introduce how to transform and observe 3D images in the following sections.
3.1 observation process
In computer graphics, a series of coordinate systems are introduced to facilitate the observation and display of geometric shapes and images:
A world coordinate system:
Generally, the world coordinate system is a three-dimensional Cartesian coordinate system. It is a global coordinate system, usually the right coordinate system. This coordinate system is mainly used for Space Positioning of all graphic objects in a graphic scenario, the position of the observer (viewpoint), and the definition of the line of sight. Other coordinate systems involved in computer graphics systems are basically defined by reference to it.
B local coordinate system:
For the convenience of geometric modeling and object observation, the two-dimensional or three-dimensional Cartesian coordinate system defined independently in the world coordinate system is called the local coordinate system. The "local" object defined in the local coordinate system can be transformed to the world coordinate system by specifying the orientation of the local coordinate system in the world coordinate system, it is upgraded to an object in the world coordinate system.
C observation coordinate system:
The observation coordinate system is usually a coordinate system defined by a user-specified upward observation vector based on the origin of the viewpoint. The default value is the left-hand coordinate system. The observation coordinate system is mainly used to observe graphical objects in the whole world coordinate system from the observer's perspective, so as to simplify the mathematical calculation of geometric objects in the visual plane (which becomes an imaging plane or a projection plane.
D video plane (imaging plane) Coordinate System:
It is a two-dimensional Cartesian coordinate system used to calculate the projection of an object on an imaging plane. Generally, the imaging plane (projection plane) is defined by specifying the distance between the visual direction and the viewpoint to the imaging plane ). You can further define a rectangular area called a window on the projection plane to achieve partial imaging.
E screen coordinate system:
The screen coordinate system is also called the device coordinate system. It is mainly used to define the points on the surface of a specific computer graphics display device (such as a grating display. In most cases, each specific display device has a separate device coordinate system.
When an imaging window is defined, a bounded area called the view area can be further defined in the screen coordinate system. Imaging in the view area is the actual observed image object. In other words, the area to be displayed in the world coordinate system is called a window, and the corresponding graphic output area on the display is called a view area (or a view area ). The process of ing a scenario in a part of the world coordinate system to a device coordinate system is called an observation transformation. A two-dimensional observation transformation is simply called a window-to-view transformation. You can perform the following steps (see Figure 3.1 ):
During scenario modeling, you often need to define the local coordinate system (or modeling coordinate system), or perform geometric transformations such as translation, rotation, and scaling on the object. To facilitate window size and orientation, we can define a two-dimensional observation coordinate system in the world coordinate system and a window in the observation coordinate system (see Figure 3.2 ).
Figure 3.2 world coordinate system xwoyw and observation coordinate system xvoyv
Figure 3.3 normalized device coordinate system
In addition, we define the area of view in the normalized coordinate system (value range: 0 to 1), as shown in Figure 3.3. You can define multiple zones. If only one view area is defined, the view area is filled with the entire unit square. By using two-dimensional cropping and window view transformation, the scenario in the window is mapped to the view area. The normalized coordinate system ensures that the observation and transformation are independent from the output device. Once the scenario is transformed to a standardized coordinate system, you can map the images in each view area to the drawing area of a specific device.
Proportional Transformation
Proportional conversion is a conversion that enables the image to zoom in or out of the X and Y axes by the proportional factor SX and SY respectively. It can change the image size and shape.
Set the coordinate of a point P on the plane to (x, y,). The coordinate after proportional transformation is (x'', y''), as shown in 3.3. The formula is as follows:
SX and SY are proportional factors. The above formula can be expressed in the form of a matrix:
(3-2-1)
.
Coordinates of different coordinate systemsConversion
Coordinate Transformation from window to view area
The actual window size is often different from that of the view area (3.7 and 3.8). To correctly display the ry in the view area, you must change it from the window to the view area.
Figure 3.7 window
Figure 3.8 area View
(XW, YW) is any point in the window, and (XV, YV) is a point in the view area. The relationship is as follows:
Simplified:
(3-3-1)
Where:
(3-3-1) TypeToRepresented
Crop
Crop
In the process of computer graphics displayWhich parts (including points, line segments, text, polygon, and so on) fall into the display area (I .e., the display area) and which part falls outside the display area, to display only those images in the display area. The essence of cropping is to decide which part of the image is located in the specified area. This requires geometric processing to remove parts that fall outside the specified region and retain the parts that fall within the specified region. This process is called cropping. The most intuitive method of cropping is to separate various geometric elements into a set of points through scanning and conversion techniques, and then determine whether they are located in the specified area point by point. This method is simple but inefficient and generally unavailable.
3. Crop Line Segments
For a given line segment, the cropping process generally includes the following parts: First, test and determine whether it falls completely within the cropping area? If not, then determine whether it is completely out of the cropping area? Then, for a line segment that is neither completely within the cropping area nor completely beyond the cropping area, the intersection of the line segment and one or more cropping boundaries must be calculated. Finally, we will test the endpoint of a line segment. We will store the line segments that both ends fall into the cropping area. Otherwise, we will remove them, that is, we will crop them.
For line segments whose endpoints are (x1, Y1) and (X2, Y2), you can use the parameter equation:
When one or two endpoints of a line segment are located outside the cropping area, the value of parameter t can be obtained through the intersection of the Line Segment and the cropping boundary. If the tvalue of the intersection is not between 0 and 1, the line segment does not enter the cropping area from the cropping boundary. Otherwise, the line segment is crossed or crossed the cropping area. You can crop a line segment by removing parts other than the cropping area. In order to reduce the calculation result, improve the efficiency of selecting and recognizing internal or external line segments, it is very important to design an effective cropping algorithm.
Below is what I found onlineArticleTo help you understand.
Computing, computer graphics is a bit difficult,
Fortunately, I have advanced mathematics, linear algebra,Probability: College Physics is good. Otherwise, it is really a bit
I don't understand.
3D Coordinate System
Understanding Coordinate System Transformation in computer 3D graphics
In terms of coordinate system transformation, what are the coordinate systems? There are: Object coordinate system, world coordinate system, camera coordinate system, projection coordinate system, and screen coordinate system. What I want to discuss is the conversion between these coordinate systems.
These coordinate systems are not just created out of thin air. They are all created to fulfill the most basic goal of computer 3D graphics.
The most basic goal of computer 3D graphics is:Display the constructed 3D object on the 2D screen coordinate.
At first glance, it seems that we can convert the original object coordinate system to the screen coordinate system. Why is there an extra world coordinate system, camera coordinate system, and projection coordinate system. This is because: there are multiple objects in a big world, and each object has its own coordinate system. How to express the relative relationship between these objects is more of a world coordinate system; if you only need to see a part of the world, there is an extra camera coordinate system. As for the projection coordinate system, it is very complicated to directly convert 3D coordinates into screen coordinates (because they are not only different dimensions, different measurements (screen coordinates are generally measured in pixels, while in 3D space, we can see meters in the real world and centimeters as units). XY has different directions, in 2D space, the coordinate system must be changed). Therefore, 3D coordinates are first reduced to 2D coordinates, and then 2D coordinates are converted to screen coordinates.
Step 1: Understand the left-hand coordinate system and the right-hand Coordinate System
Why is there a left-hand coordinate system or a right-hand coordinate system?
In 3D space (yes! In 3D), all 2D coordinate systems are equivalent (that is, they can be converted through a series of affine transformations)
The 3D coordinate system is not equivalent. Through the affine transformation, the left-hand coordinate system cannot be converted to the right-hand coordinate system. That is to say, the object coordinate system uses the left-hand coordinate system and the world coordinate system uses the right-hand coordinate system, then the object may not be what we want, it may be an upside down, or it may be back to us, so we need to distinguish the left-hand coordinate system from the right-hand coordinate system. Maybe in the 4D space, the left and right hand coordinate systems can change each other.
Go to the topic:
First, we will discuss Object coordinate system-> world coordinate system
In order to describe the relative relationship between multiple objects, the world coordinate system is introduced here, so the world coordinate system is a reference coordinate system.
The purpose of this step is to transfer the points of all objects to the world coordinate system, which mainly involves rotation, scaling, and translation.
However, I will explain in detail why and how to use matrices to describe these transformations.
For example, if there are two coordinate systems C and C ', C is obtained by rotating θ around the Z axis. The following is the transformation of each coordinate axis:
If it is the point P (x, y, z) in the c Coordinate System
How can we create a matrix? The answer is to differentiate whether you are using a row vector or a column vector. Maybe someone will ask why is it not a left-hand or right-hand coordinate system? Because C can be changed to c ', they must be in the same left-hand or right-hand coordinate system. The transformation can only be performed between the coordinate systems that can be converted to each other.
If you use a row vector: Because the row vector can only be left multiplied by a matrix (note the difference between multiplication and multiplication)
So the matrix form should be like this
Only in this way can the above P form be obtained in the left multiplication matrix.
If you use a column vector: Because the column vector can only be a right multiplication matrix (note the difference between multiplication and multiplication)
So the matrix form should be like this
Only in this way can the above P form be obtained in the right multiplication matrix.
As for how to rotate, scale, and pan, I will not say much.
....................................... I felt like I was running the question. Fortunately, the two coordinate system transformations were very simple.
Let's discuss it again. World coordinate system-> camera coordinate system
The purpose of introducing a camera is to simply see a part of the world, and to screen which ones can be seen in the camera. Convert an object to the camera coordinate system, which makes filtering much easier. The focus here is to build the camera coordinate system.
The object coordinate system. The world coordinate system is defined by the artist during painting. The camera coordinate system requires real-time construction of programs. (Of course, this is usually the case. If you want to build a world, the world is around you, and you need to change the coordinate system of all objects in real time, fixed the camera coordinate system (in fact, the camera coordinate system is the world coordinate system at this time). I can't help building a world in which the Earth is said, and your thinking is too different .)
How to build a camera coordinate system? First, we need to clarify the goal: we need to build a 3D coordinate system (as if it were nonsense), and the three axes should be perpendicular to each other (or as nonsense ).
We generally use uvn cameras. For example, d3d d3dxmatrixlookatlh, d3dxmatrixlookatrh, and OGL glulookat (right-hand coordinate system ).
How can we create a uvn camera? We need to use the cross product tool: the cross product of two non-parallel and non-overlapping vectors can obtain the vectors perpendicular to each other.
If we have the camera position and the target position, we can determine a Z axis (someone asks why the Z axis is used to represent the object's distance and closeness ). When calculating the Z axis, pay attention to the left-hand coordinate system or the right-hand coordinate system. The XY axis of the left-hand coordinate system is the same direction, and the Z axis is the opposite direction. Therefore, the left-hand coordinate system is the target position minus the camera position, while the right-hand coordinate system is the camera position minus the target position. Remember Normalize
This is what we want to get the X and Y axes. How to calculate the X and Y axes?
The general method is:
1. Select a temporary Y axis,
2. Perform cross product on the temporary Y and Z axes to obtain an X axis
3. Perform cross product on the X axis and the Z axis to obtain a Y axis.
With xyz, you can find the rotating camera matrix.
How do I select a Y axis? In most cases (0, 1, 0), but if the camera position e is perpendicular to the target position T, that is (E-T = (0, + ), in this case, (0, 1, 0) cannot be used. Because the cross product of two parallel vectors is a zero vector, We need to select another Y axis.
But I think we can change the method.
If the Y axis cannot be selected, we select a temporary X axis, which is (, 0 ).
Then, a Y axis is obtained by cross product between the temporary X axis and the Z axis.
Finally, the Y axis is prefixed with the Z axis to obtain the X axis.
In this way, the XYZ axis is obtained.
At last, the camera matrix is created based on the row vector and column vector, and then translated.
Camera coordinate system-> projection Coordinate System.
The purpose of projection is to reduce the dimension.
Two projection methods: orthogonal projection and Perspective Projection.
I have already written this article in our team, so I won't say much about it. Let's go and read his article.
Projection coordinate system-> screen Coordinate System
This is the simplest. 2d coordinate transformation. Not to mention.
Reprinted Article 2: http://www.xingousi.com/computer/computergraphics.htm
Computer Graphics note (Part 1): Principle of computer graphics Perspective Projection Transformation and one-point and two-point perspective
1. Parallel Division
Wu Yingfan wrote the new method of perspective drawing-the intersection method system. The parallel mutual method mentioned in it makes sense.
In fact, simply put, it is the two parallel lines in the original space on the perspective view (the perspective projection on the screen is the intersection of vertices ), draw a parallel line of another perspective projection line through the endpoint of one perspective projection line, which must be parallel to the screen; the third line's Perspective Projection point must be in another perspective projection line.
Ii. Study Summary of Perspective Projection Transformation
1. Use multi-dimensional series to represent the coordinates of low-dimensional space, and deepen understanding of the homogeneous coordinate representation.
The homogeneous coordinate representation can be easily used for computation without changing the shape. [X, y, z, 0] indicates an infinite point.
2. The perspective projection transformation formula can be regarded as the product of two matrices, one of which is perspective transformation and the other is positive projection.
The exact meaning of the reserved Z' value: Refers to a line after the Perspective Projection before the perspective projection transformation is completed completely.
For its geometric significance, see page 44th of Li Jianping's tutorial on computer graphics principles.
3. Coordinate Transformation between the left-hand and right-hand Coordinate Systems
"The Viewpoint coordinate system is different from the world coordinate system where an ordinary object is located. It follows the left-hand principle, that is, the left-hand thumb points to the Z positive axis, and the four vertical fingers points to the X positive axis, the Y axis is bent 90 degrees in four directions. The world coordinate system follows the Right Hand Rule ."
4. The pivoting transformation formula of the viewpoint coordinate system is very important !! Wang Fei: 65 pages of computer graphics books
5. the exact meaning of the Z' value refers to a line after the Perspective Projection before the perspective projection transformation is complete.
Iii. Transformation Matrix of Two-point perspective:
The principle of Wang Fei's computer graphics basics is:
The transformation matrix of the Two-point perspective is derived from the translation, rotation, and miscutting of a plane image:
The object itself has an object coordinate system-XW, YW, ZW. The viewpoint, as the origin, forms another viewpoint coordinate system-Xe, ye, ze. The Coordinate System of the object faces up on the Z axis, and the Y axis faces far away; the Y axis of the viewpoint coordinate system is facing up, And the Z axis is facing up to a distance.
In this way, the final two-point perspective state can be obtained in this way. First, the object coordinate system representation of the object location is converted to the viewpoint coordinate system representation (the first matrix ), then rotate around the Y axis of the viewpoint coordinate system (the second matrix), then translate (the third Matrix) in the X, Y, and Z directions, and finally perform the perspective transformation (the fourth matrix ), in its original article, the translation was placed in the second step. Before the translation, I turned to ensure that the axis of the object was not far from it:
The matrix transformation I used is as follows. In the original article, the translation is placed in step 2:
[XW, YW, ZW, 1] ****
The final result is a new matrix,
[Xe ye ze 1] = [cos * XW-sin * YW + l zw + M 2sin * XW + 2cos * YW + 2n-d (sin * XW + cos * YW + n)/D]
Change the last item1, Available
= [(COS * XW-sin * YW + l) * D/(sin * XW + cos * YW + N (ZW + M) * D/(sin * XW + cos * YW + n)(2sin * XW + 2cos * YW + 2n-d)* D/(sin * XW + cos * YW + n) 1]
That is:
Xe = (COS * XW-sin * YW + l) * D/(sin * XW + cos * YW + n)
Ye = (ZW + M) * D/(sin * XW + cos * YW + n)
Ze = (2sin * XW + 2cos * YW + 2 * n-d) * D/(sin * XW + cos * YW + n)
Actually myDelphiProgramThis is the case:
Xe: = trunc (COS (angle) * EEE [II] [K]. x-sin (angle) * EEE [II] [K]. Y + l) * D/(sin (angle) * EEE [II] [K]. X + cos (angle) * EEE [II] [K]. Y + n ));
Ye: = trunc (hhh [II] [k] + M) * D/(sin (angle) * EEE [II] [K]. X + cos (angle) * EEE [II] [K]. Y + n ));//Perspective transformation
// ZeIt can be used as an anti-Password service.
Ze: = trunc (2 * sin (angle) * XW + 2 * Cos (angle) * YW + 2 * n-d) * D/(sin (angle) * XW + cos (angle) * YW + n ));
Iv. Results of transformed two-point pivoting XE, ye, ZW, and*Returns the coordinates of the original object XW and YW.
That is, XE, ye, ZW, andKnown, XW, YW
According:
Xe = (COS * XW-sin * YW + l) * D/(sin * XW + cos * YW + n)(1)
Ye = (ZW + M) * D/(sin * XW + cos * YW + n)(2)
Ze =(2sin * XW + 2cos * YW + 2n-d)* D/(sin * XW + cos * YW + n)(3)
(1) divide by (2)
Xe/Ye =(COS * XW-sin * YW + l)/(ZW + M)
(Xe *(ZW + M ))/Ye =Cos * XW-sin * YW + L
(Xe *(ZW + M ))/(Ye *Cos) = XW-tan * YW + L/cos
XW =(Xe *(ZW + M ))/(Ye *Cos)-(ye * l )/(Ye *Cos) + (sin * YW * Ye )/(Ye *Cos)
XW = (Xe *(ZW + M) + sin * YW * Ye-ye * l )/(Ye *Cos) (4)
By (2) Get
Ye * (sin * XW + cos * YW + n) = (ZW + M) * d
Ye * (sin * XW) + ye * Cos * YW + N * Ye = (ZW + M) * d
Put (4).
Ye * sin *(Xe *(ZW + M) + sin * YW * Ye-ye * l )/(Ye *Cos)+ Ye * Cos * YW + N * Ye = (ZW + M) * d
About to goYe
Sin *(Xe *(ZW + M) + sin * YW * Ye-ye * l)/cos+ Ye * Cos * YW + N * Ye = (ZW + M) * d
Tan*(Xe *ZW + Xe * m + sin * YW * Ye-ye * l)+ Ye * Cos * YW + N * Ye = (ZW + M) * d
Tan*Xe *ZW + Xe * m *Tan-Ye * l *Tan+ Sin *Tan*YW* Ye+ Ye * Cos * YW + N * Ye = (ZW + M) * d
(Sin *Tan* Ye+ Ye * Cos) * YW +Tan *Xe *ZW+ Xe * m *Tan-Ye * l *Tan+ N * Ye = (ZW + M) * d
Last
YW = [(ZW + M) * d-Tan *Xe *ZW-Xe * m *Tan+ Ye * l *Tan-N * Ye]/(Sin *Tan* Ye+ Ye * Cos)(5)
The preceding figure shows that
XW = (Xe *(ZW + M) + sin * YW * Ye-ye * l )/(Ye *Cos) (4)
Actually equivalentOpenGLTo determine the position in the corresponding 3D space from the screen position selected by the mouse,OpenGLUseGluunprojectAndGluunproject4.