程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> Silverlight 引路蜂二維圖形庫示例:坐標變換

Silverlight 引路蜂二維圖形庫示例:坐標變換

編輯:C#入門知識

類AffineTransform用於二維平面上坐標變換。可以對坐標進行平移,縮放,旋轉等變換。下面例子顯示了坐標變換的用法。

[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(); 
  
 m.Rotate(-45 * Math.PI / 180.0, 0, 0); 
 /* Concatenates the m  to the matrix2.
  * [matrix2] =  [matrix2] * [m];
  */ 
 matrix2.Concatenate(m); 
  
 /* Define the matrix3 as
  * "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();
 
 m.Rotate(-45 * Math.PI / 180.0, 0, 0);
 /* Concatenates the m  to the matrix2.
  * [matrix2] =  [matrix2] * [m];
  */
 matrix2.Concatenate(m);
 
 /* Define the matrix3 as
  * "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();
 
 m.Rotate(-45 * Math.PI / 180.0, 0, 0);
 /* Concatenates the m  to the matrix2.
  * [matrix2] =  [matrix2] * [m];
  */
 matrix2.Concatenate(m);
 
 /* Define the matrix3 as
  * "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);
 
}

 

\

 作者:mapdigit
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved