Advertisement
Guest User

Untitled

a guest
May 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using t3d;
  11. using punkt;
  12.  
  13. namespace WindowsFormsApplication5
  14. {
  15.  
  16. public partial class Form1 : Form
  17. {
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. DoubleBuffered = true;
  22. }
  23. private double R = 10, fi = 45, teta = 80;
  24. diament d1 = new diament(new Punkt(0, 0, 0), Color.Black, Color.White);
  25.  
  26. private void Form1_Paint(object sender, PaintEventArgs e)
  27. {
  28.  
  29.  
  30. Graphics g = e.Graphics;
  31. int szer = ClientRectangle.Width;
  32. int wys = ClientRectangle.Height;
  33.  
  34. double x, y, z;
  35. double a = Math.PI / 180.0;
  36. double b = R * Math.Sin(a * teta);
  37. x = b * Math.Cos(a * fi);
  38. y = b * Math.Sin(a * fi);
  39. z = R * Math.Cos(a * teta);
  40.  
  41. Punkt obserwator = new Punkt(x,y,z);
  42.  
  43. T3d projektor = new T3d(obserwator,0,0,szer,wys,0.5,0,0);
  44. d1.rysuj(g, ref projektor);
  45. //Punkt zero = new Punkt(0, 0, 0);
  46. /*
  47. Punkt p1 = new Punkt(1, 1, 0);
  48. Punkt p2 = new Punkt(-1, 1, 0);
  49. Punkt p3 = new Punkt(1, -1, 0);
  50. Punkt p4 = new Punkt(-1, -1, 0);
  51. Punkt p5 = new Punkt(0, 0, Math.Sqrt(5.0));
  52. Punkt p6 = new Punkt(0, 0, -Math.Sqrt(5.0));
  53. int xe, ye;
  54. int xe1, ye1;
  55. int xe2, ye2;
  56. int xe3, ye3;
  57. int xe4, ye4;
  58. int xe5, ye5;
  59. int xe6, ye6;
  60. */
  61. /*
  62. if (projektor.punkt_3d(out xe, out ye, zero) && projektor.punkt_3d(out xe1, out ye1, p1) && projektor.punkt_3d(out xe2, out ye2, p2)
  63. && projektor.punkt_3d(out xe3, out ye3, p3) && projektor.punkt_3d(out xe4, out ye4, p4) && projektor.punkt_3d(out xe5, out ye5, p5)
  64. && projektor.punkt_3d(out xe6, out ye6, p6))
  65. {
  66. int r = 2;
  67. g.FillEllipse(Brushes.Blue, xe - r, ye - r, 2*r, 2*r);
  68. g.FillEllipse(Brushes.Blue, xe1 - r, ye1 - r, 2 * r, 2 * r);
  69. g.FillEllipse(Brushes.Blue, xe2 - r, ye2 - r, 2 * r, 2 * r);
  70. g.FillEllipse(Brushes.Blue, xe3 - r, ye3 - r, 2 * r, 2 * r);
  71. g.FillEllipse(Brushes.Blue, xe4 - r, ye4 - r, 2 * r, 2 * r);
  72. g.FillEllipse(Brushes.Blue, xe5 - r, ye5 - r, 2 * r, 2 * r);
  73. g.FillEllipse(Brushes.Blue, xe6 - r, ye6 - r, 2 * r, 2 * r);
  74.  
  75.  
  76. g.DrawLine(Pens.Red, xe1, ye1, xe2, ye2);
  77. g.DrawLine(Pens.Red, xe1, ye1, xe3, ye3);
  78. g.DrawLine(Pens.Red, xe2, ye2, xe4, ye4);
  79. g.DrawLine(Pens.Red, xe3, ye3, xe4, ye4);
  80.  
  81. g.DrawLine(Pens.Red, xe1, ye1, xe6, ye6);
  82. g.DrawLine(Pens.Red, xe2, ye2, xe6, ye6);
  83. g.DrawLine(Pens.Red, xe4, ye4, xe6, ye6);
  84. g.DrawLine(Pens.Red, xe3, ye3, xe6, ye6);
  85.  
  86. g.DrawLine(Pens.Red, xe1, ye1, xe5, ye5);
  87. g.DrawLine(Pens.Red, xe2, ye2, xe5, ye5);
  88. g.DrawLine(Pens.Red, xe3, ye3, xe5, ye5);
  89. g.DrawLine(Pens.Red, xe4, ye4, xe5, ye5);
  90.  
  91. }
  92. */
  93.  
  94.  
  95.  
  96. }
  97.  
  98. private void Form1_Resize(object sender, EventArgs e)
  99. {
  100. Invalidate();
  101. }
  102.  
  103. private void timer1_Tick(object sender, EventArgs e)
  104. {
  105. double dfi = 1.0;
  106. fi += dfi;
  107. if(fi > 360)
  108. {
  109. fi -= 360;
  110. }
  111. Invalidate();
  112. }
  113.  
  114. }
  115.  
  116.  
  117. class diament
  118. {
  119. private Punkt[] rogi = new Punkt[4];
  120. private double bok = 0.8;
  121. private Brush b;
  122. private Pen p;
  123.  
  124. public diament(Punkt p0, Color k1, Color k2)
  125. {
  126.  
  127. double b2 = bok / Math.Sqrt(2);
  128. rogi[0] = new Punkt(p0.x, p0.y + b2, p0.z + b2);
  129. rogi[1] = new Punkt(p0.x, p0.y + b2, p0.z - b2);
  130. rogi[2] = new Punkt(p0.x, p0.y - b2, p0.z - b2);
  131. rogi[3] = new Punkt(p0.x, p0.y - b2, p0.z + b2);
  132. b = new SolidBrush(k1);
  133. p = new Pen(k2);
  134. }
  135.  
  136. public void rysuj(Graphics g, ref T3d projektor)
  137. {
  138. Point[] points = new Point[4];
  139. int[] xe = new int[4];
  140. int[] ye = new int[4];
  141.  
  142. for (int i = 0; i < 4; ++i)
  143. {
  144. projektor.punkt_3d(out xe[i], out ye[i], rogi[i]);
  145. points[i].X = xe[i];
  146. points[i].Y = ye[i];
  147. }
  148.  
  149. g.FillPolygon(b, points);
  150. g.DrawPolygon(p, points);
  151. }
  152.  
  153. }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement