daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Point[] points = new Point[3] { left, top, right };
  2.    
  3. DrawField();DrawCoordinateSystem();
  4.    
  5. graph.FillPolygon(Brushes.ForestGreen, points);
  6.    
  7. Point[] pointsCopy = (Point[]) points.Clone();
  8.    
  9. x = A.x + (A.x - P0.x)
  10. y = A.y + (A.y - P0.y)
  11.    
  12. |B*P0.x + C*P0.y,  C|
  13.       |C*P1.x - B*P1.y, -B|
  14.  A.x = --------------------- ,
  15.           -B*B - C*C
  16.  
  17.       |B,  B*P0.x + C*P0.y|
  18.       |C,  C*P1.y - B*P1.y|
  19.  A.y = ---------------------
  20.           -B*B - C*C
  21.  
  22.  B = P2.x - P1.x
  23.  C = P2.y - P1.y
  24.    
  25. A
  26.    
  27. Point A = new Point( -width, -(a / b) * -width - c / b );
  28. Point B = new Point( width, -(a / b) * width - c / b );
  29.    
  30. float[,] L = new float[2, 3] {
  31.     { A.X, A.Y, 1 },
  32.     { B.X, B.Y, 1 }
  33. };
  34.    
  35. float[,] X = new float[3, 3] {
  36.     { points[0].X, points[0].Y, 1 },
  37.     { points[1].X, points[1].Y, 1 },
  38.     { points[2].X, points[2].Y, 1 }
  39. };
  40.    
  41. private static float[,] MultiplyMatrix(float[,] a, float[,] b)
  42. {
  43.     float[,] product = new float[a.GetLength(0), b.GetLength(1)];
  44.  
  45.     for (int row = 0; row  product.GetLength(0); row++)
  46.         for (int col = 0; col  product.GetLength(1); col++)
  47.             // Multiply the row of A by the column of B
  48.             for (int inner = 0; inner  a.GetLength(1); inner++)
  49.                 product[row, col] += a[row, inner] * b[inner, col];
  50.  
  51.     return product;
  52. }
  53.    
  54. float ys = -(a / b) * 0 - c / b;
  55.    
  56. float[,] T = new float[3, 3] {
  57.     { 1, 0, 0 },
  58.     { 0, 1, 0 },
  59.     { 0, -ys, 1 }
  60. };
  61.  
  62. L = MultiplyMatrix(L, T);
  63. X = MultiplyMatrix(X, T);
  64.    
  65. double radians = Math.Atan(-(a / b));
  66.    
  67. float[,] R = new float[3, 3] {
  68.     { Math.Cos(radians), -Math.Sin(radians), 0 },
  69.     { Math.Sin(radians), Math.Cos(radians), 0 },
  70.     { 0, 0, 1 }
  71. };
  72.  
  73. L = MultiplyMatrix(L, R);
  74. X = MultiplyMatrix(X, R);
  75.    
  76. float[,] Rr = new float[3, 3] {
  77.     { 1, 0, 0 },
  78.     { 0, -1, 0 },
  79.     { 0, 0, 1 }
  80. };
  81.  
  82. X = MultiplyMatrix(X, Rr);
  83.    
  84. float[,] Rh = new float[3, 3] {
  85.     { Math.Cos(radians), Math.Sin(radians), 0 },
  86.     { -Math.Sin(radians), Math.Cos(radians), 0 },
  87.     { 0, 0, 1 }
  88. };
  89.  
  90. L = MultiplyMatrix(L, Rh);
  91. X = MultiplyMatrix(X, Rh);
  92.    
  93. float[,] Th = new float[3, 3] {
  94.     { 1, 0, 0 },
  95.     { 0, 1, 0 },
  96.     { 0, ys, 1 }
  97. };
  98.  
  99. L = MultiplyMatrix(L, Th);
  100. X = MultiplyMatrix(X, Th);
  101.    
  102. for (int i = 0; i  p.Length; i++)
  103. {
  104.     points[i].X = X[i, 0];
  105.     points[i].Y = X[i, 1];
  106. }
  107.    
  108. graph.FillPolygon(Brushes.RoyalBlue, points);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top