Example of two-dimensional graph library of Silverlight web tracking bee: Coordinate Transformation

Source: Internet
Author: User

Class AffineTransform is used for Coordinate Transformation on two-dimensional plane. Coordinates can be translated, scaled, or rotated. The following example shows the usage of coordinate transformation.

[Csharp]
Private void Transform ()
{
Path path;

/* The first matrix */
AffineTransform matrix1 = new AffineTransform ();
/* The second matrix */
AffineTransform matrix2 = new AffineTransform ();
/* The third matrix */
AffineTransform matrix3 = new AffineTransform ();

/** Colors */
Color blackColor = new Color (0xff000000, false );
Color redColor = new Color (0xffff0000, false );
Color greenColor = new Color (0xff00ff00, false );
Color blueColor = new Color (0xff0000ff, false );
Color fillColor = new Color (0x4f0000ff, true );
/* Define the path */
Path = new Path ();
Path. MoveTo (50, 0 );
Path. LineTo (0, 0 );
Path. LineTo (0, 50 );

/* Define the matrix1 as "translate (50, 50 )"*/
Matrix1.Translate (50, 50 );

/* Define the matrix2 as "translate (50, 50) + rotate (-45 )"*/
Matrix2 = new AffineTransform (matrix1 );
AffineTransform m = new AffineTransform ();

MB. Rotate (-45 * Math. PI/180.0, 0, 0 );
/* Concatenates the m to the matrix2.
* [Matrix2] = [matrix2] * [m];
*/
Matrix2.Concatenate (m );

/* Define the matrix3
* "Translate (50, 50) + rotate (-45) + translate (-20, 80 )"*/
/* Copy the matrix2 to the matrix3 */
Matrix3 = new AffineTransform (matrix2 );
M = new AffineTransform ();

M. Translate (-20, 80 );
/* Concatenates the m to the matrix3.
* [Matrix3] = [matrix3] * [m]
*/
Matrix3.Concatenate (m );
// Clear the canvas with white color.
Graphics2D. Clear (Color. White );

Graphics2D. AffineTransform = (matrix1 );
SolidBrush brush = new SolidBrush (fillColor );
Pen pen = new Pen (redColor, 4 );

Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );

Graphics2D. AffineTransform = (matrix2 );

Pen = new Pen (greenColor, 4 );

Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
Graphics2D. AffineTransform = (matrix3 );

Pen = new Pen (blueColor, 4 );

Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );

}
Private void Transform ()
{
Path path;
 
/* The first matrix */
AffineTransform matrix1 = new AffineTransform ();
/* The second matrix */
AffineTransform matrix2 = new AffineTransform ();
/* The third matrix */
AffineTransform matrix3 = new AffineTransform ();
 
/** Colors */
Color blackColor = new Color (0xff000000, false );
Color redColor = new Color (0xffff0000, false );
Color greenColor = new Color (0xff00ff00, false );
Color blueColor = new Color (0xff0000ff, false );
Color fillColor = new Color (0x4f0000ff, true );
/* Define the path */
Path = new Path ();
Path. MoveTo (50, 0 );
Path. LineTo (0, 0 );
Path. LineTo (0, 50 );
 
/* Define the matrix1 as "translate (50, 50 )"*/
Matrix1.Translate (50, 50 );
 
/* Define the matrix2 as "translate (50, 50) + rotate (-45 )"*/
Matrix2 = new AffineTransform (matrix1 );
AffineTransform m = new AffineTransform ();
 
MB. Rotate (-45 * Math. PI/180.0, 0, 0 );
/* Concatenates the m to the matrix2.
* [Matrix2] = [matrix2] * [m];
*/
Matrix2.Concatenate (m );
 
/* Define the matrix3
* "Translate (50, 50) + rotate (-45) + translate (-20, 80 )"*/
/* Copy the matrix2 to the matrix3 */
Matrix3 = new AffineTransform (matrix2 );
M = new AffineTransform ();
 
M. Translate (-20, 80 );
/* Concatenates the m to the matrix3.
* [Matrix3] = [matrix3] * [m]
*/
Matrix3.Concatenate (m );
// Clear the canvas with white color.
Graphics2D. Clear (Color. White );
 
Graphics2D. AffineTransform = (matrix1 );
SolidBrush brush = new SolidBrush (fillColor );
Pen pen = new Pen (redColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
 
Graphics2D. AffineTransform = (matrix2 );
 
Pen = new Pen (greenColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
Graphics2D. AffineTransform = (matrix3 );
 
Pen = new Pen (blueColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
 
}

Private void Transform ()
{
Path path;
 
/* The first matrix */
AffineTransform matrix1 = new AffineTransform ();
/* The second matrix */
AffineTransform matrix2 = new AffineTransform ();
/* The third matrix */
AffineTransform matrix3 = new AffineTransform ();
 
/** Colors */
Color blackColor = new Color (0xff000000, false );
Color redColor = new Color (0xffff0000, false );
Color greenColor = new Color (0xff00ff00, false );
Color blueColor = new Color (0xff0000ff, false );
Color fillColor = new Color (0x4f0000ff, true );
/* Define the path */
Path = new Path ();
Path. MoveTo (50, 0 );
Path. LineTo (0, 0 );
Path. LineTo (0, 50 );
 
/* Define the matrix1 as "translate (50, 50 )"*/
Matrix1.Translate (50, 50 );
 
/* Define the matrix2 as "translate (50, 50) + rotate (-45 )"*/
Matrix2 = new AffineTransform (matrix1 );
AffineTransform m = new AffineTransform ();
 
MB. Rotate (-45 * Math. PI/180.0, 0, 0 );
/* Concatenates the m to the matrix2.
* [Matrix2] = [matrix2] * [m];
*/
Matrix2.Concatenate (m );
 
/* Define the matrix3
* "Translate (50, 50) + rotate (-45) + translate (-20, 80 )"*/
/* Copy the matrix2 to the matrix3 */
Matrix3 = new AffineTransform (matrix2 );
M = new AffineTransform ();
 
M. Translate (-20, 80 );
/* Concatenates the m to the matrix3.
* [Matrix3] = [matrix3] * [m]
*/
Matrix3.Concatenate (m );
// Clear the canvas with white color.
Graphics2D. Clear (Color. White );
 
Graphics2D. AffineTransform = (matrix1 );
SolidBrush brush = new SolidBrush (fillColor );
Pen pen = new Pen (redColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
 
Graphics2D. AffineTransform = (matrix2 );
 
Pen = new Pen (greenColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
Graphics2D. AffineTransform = (matrix3 );
 
Pen = new Pen (blueColor, 4 );
 
Graphics2D. SetPenAndBrush (pen, brush );
Graphics2D. Draw (null, path );
 
}

 

Author: mapdigit
 

Related Article

Contact Us

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.