# [Knocking on the door of C #] For Beginners: Translation Transformation

Source: Internet
Author: User
17.9 Coordinate Transformation

By default, the origin of the coordinate system is located in the upper left corner of the view area. The horizontal direction is the X axis, and the vertical direction is the Y axis. However, sometimes we need to change the position or direction of the coordinate axis. Common coordinate transformations include translation transformation, Rotation Transformation, and scaling transformation.

17.9.1 translation Transformation

Author: Liang binyu is a member of the book C #, which was published in early July.
BeginnerClassroom@163.com
Http://www.cnblogs.com/BeginnerClassroom

Translation transformation refers to translating the origin of the coordinate system from one position to another. We can implement translation transformation through the translatetransform () method of graphics.

The following example shows how to perform translation transformation.

Figure 17-16 "coordinate transformation" Window

Create a project named "transform" and add the control as follows:

Add three buttons, as shown in Figure 1.17-16.

Now add event processing for the "pan transform" buttonProgram.

Try: Translation Transformation

`// Translation TransformationPrivate voidTranslatetransformbutton_click (ObjectSender,EventargsE ){// Rectangle to be drawnRectangle redrectangle =NewRectangle (NewPoint (0, 0 ),NewSize (120, 80 ));// Draw the image in the Original Coordinate SystemGraphics G = creategraphics (); G. fillrectangle (brushes. Red, redrectangle );// Draw a chart in the new Coordinate SystemG. translatetransform (150,120); G. fillrectangle (brushes. Red, redrectangle );} `

In the above procedure, we have drawn the redrectangle rectangle twice. The top left corner of the rectangle is at the origin of the coordinate system, with a width of 120 pixels and a height of 80 pixels.

For the first time, we draw a rectangle in the default coordinate system. At this time, the origin of the coordinate system is in the upper left corner of the window (as shown in the real line). The graphics object draws a rectangle based on this reference, as shown in 17-17.

Figure 17-17 use the translation transformation method to draw the window of a rectangle

Then we use the following statement to perform coordinate translation and transformation. This statement translates the coordinate system to 150 pixels to the right and 120 pixels to the bottom, the origin of the coordinate system is moved from point A to point B (as shown in the dotted line ).

G. translatetransform (150,120 );

Horizontal offset vertical offset

The last time we draw a rectangle for the second time, the graphics object uses the new coordinate system as the reference, so the upper left corner of the rectangle is drawn at point B.

Although the redrectangle of the same rectangle is drawn twice, the actual position of the rectangle varies according to the coordinate system.

Once the coordinate system of the graphics object is changed, the graphics object will be drawn in the new coordinate system in the future. To restore the graphics object to the default coordinate system, use the following statement to clear the transformation.

G. resettransform ();

After the resettransform () method is executed, the coordinate system returns to the default state, and the graphics object returns to the default Coordinate System for plotting.

Author: Liang binyu is a member of the book C #, which was published in early July.
BeginnerClassroom@163.com
Http://www.cnblogs.com/BeginnerClassroom

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.