SHOW:
|
|
- or go back to the newest paste.
| 1 | unit Unit1; | |
| 2 | ||
| 3 | interface | |
| 4 | ||
| 5 | uses | |
| 6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
| 7 | Dialogs, StdCtrls, ExtCtrls; | |
| 8 | const PointsCount = 25; | |
| 9 | rPoint = 3; | |
| 10 | type | |
| 11 | // Ñòðóêòóðà îïèñûâàþùàÿ òî÷êó â ïðîñòðàíñòâå | |
| 12 | ||
| 13 | TPoint3D = record | |
| 14 | X: Real; | |
| 15 | Y: Real; | |
| 16 | Z: Real; | |
| 17 | end; | |
| 18 | ||
| 19 | type | |
| 20 | TForm1 = class(TForm) | |
| 21 | Image1: TImage; | |
| 22 | Button1: TButton; | |
| 23 | Timer1: TTimer; | |
| 24 | Button2: TButton; | |
| 25 | procedure Button1Click(Sender: TObject); | |
| 26 | procedure FormCreate(Sender: TObject); | |
| 27 | procedure FormClose(Sender: TObject; var Action: TCloseAction); | |
| 28 | procedure Timer1Timer(Sender: TObject); | |
| 29 | procedure Button2Click(Sender: TObject); | |
| 30 | { Private declarations }
| |
| 31 | private | |
| 32 | // Êîîðäèíàòû öåíòðà ýêðàíà | |
| 33 | oX: Integer; | |
| 34 | oY: Integer; | |
| 35 | ||
| 36 | ScaleX,ScaleY:real; | |
| 37 | DrawBuffer: TBitMap; // Áóôåð äëÿ ðèñîâàíèÿ | |
| 38 | BufferColor: TColor; // Öâåò áóôåðà | |
| 39 | X0,Y0,Xn,Yn,dX,dY : Real; | |
| 40 | zMin, zMax: real; | |
| 41 | Alpha: Real; | |
| 42 | AlphaP: Real; | |
| 43 | Points3D: array[0..PointsCount,0..PointsCount] of TPoint3D; // Ìàññèâ òðåõìåðíûõ òî÷åê | |
| 44 | Points2D: array[0..PointsCount,0..PointsCount] of TPoint; | |
| 45 | subAxis3D_X: array[0..13] of TPoint3D; | |
| 46 | subAxis3D_Y: array[0..13] of TPoint3D; | |
| 47 | subAxis3D_Z: array[0..13] of TPoint3D; | |
| 48 | subAxis2D_X: array[0..13] of TPoint; | |
| 49 | subAxis2D_Y: array[0..13] of TPoint; | |
| 50 | subAxis2D_Z: array[0..13] of TPoint; | |
| 51 | Axis3D: array[0..8] of TPoint3D; | |
| 52 | Axis2D: array[0..8] of TPoint; | |
| 53 | procedure ClearBuffer; // Î÷èñòêà áóôåðà ðèñîâàíèÿ | |
| 54 | procedure DrawPoints; // Ïðîöåäóðà ðèñîâàíèÿ òî÷åê | |
| 55 | public | |
| 56 | { Public declarations }
| |
| 57 | end; | |
| 58 | ||
| 59 | var | |
| 60 | Form1: TForm1; | |
| 61 | ||
| 62 | implementation | |
| 63 | ||
| 64 | {$R *.dfm}
| |
| 65 | ||
| 66 | procedure TForm1.Button1Click(Sender: TObject); | |
| 67 | var i,j : integer; | |
| 68 | begin | |
| 69 | X0:=-3.14; Xn:=3.14; | |
| 70 | Y0:=-3.14; Yn:=3.14; | |
| 71 | dX:= (Xn-X0)/PointsCount; | |
| 72 | dY:= (Yn-Y0)/PointsCount; | |
| 73 | Axis3d[0].X:=0; | |
| 74 | Axis3d[0].Y:=0; | |
| 75 | Axis3d[0].Z:=0; | |
| 76 | ||
| 77 | Axis3d[1].X:=-4; | |
| 78 | Axis3d[1].Y:=0; | |
| 79 | Axis3d[1].Z:=0; | |
| 80 | Axis3d[2].X:=4; | |
| 81 | Axis3d[2].Y:=0; | |
| 82 | Axis3d[2].Z:=0; | |
| 83 | ||
| 84 | Axis3d[3].X:=0; | |
| 85 | Axis3d[3].Y:=-4; | |
| 86 | Axis3d[3].Z:=0; | |
| 87 | ||
| 88 | Axis3d[4].X:=0; | |
| 89 | Axis3d[4].Y:=4; | |
| 90 | Axis3d[4].Z:=0; | |
| 91 | ||
| 92 | Axis3d[5].X:=0; | |
| 93 | Axis3d[5].Y:=0; | |
| 94 | Axis3d[5].Z:=-4; | |
| 95 | ||
| 96 | Axis3d[6].X:=0; | |
| 97 | Axis3d[6].Y:=0; | |
| 98 | Axis3d[6].Z:=4; | |
| 99 | for i:=0 to 6 do | |
| 100 | begin | |
| 101 | subAxis3D_X[2*i].X:=Trunc(X0)+i; | |
| 102 | subAxis3D_X[2*i].Y:=-0.2; | |
| 103 | subAxis3D_X[2*i].Z:=0; | |
| 104 | subAxis3D_X[2*i+1].X:=Trunc(X0)+i; | |
| 105 | subAxis3D_X[2*i+1].Y:=0.2; | |
| 106 | subAxis3D_X[2*i+1].Z:=0; | |
| 107 | end; | |
| 108 | for i:=0 to 6 do | |
| 109 | begin | |
| 110 | subAxis3D_Y[2*i].X:=-0.2; | |
| 111 | subAxis3D_Y[2*i].Y:=Trunc(Y0)+i; | |
| 112 | subAxis3D_Y[2*i].Z:=0; | |
| 113 | subAxis3D_Y[2*i+1].X:=0.2; | |
| 114 | subAxis3D_Y[2*i+1].Y:=Trunc(Y0)+i; | |
| 115 | subAxis3D_Y[2*i+1].Z:=0; | |
| 116 | end; | |
| 117 | for i:=0 to 6 do | |
| 118 | begin | |
| 119 | subAxis3D_Z[2*i].X:=0; | |
| 120 | subAxis3D_Z[2*i].Y:=-0.2; | |
| 121 | subAxis3D_Z[2*i].Z:=-3+i; | |
| 122 | subAxis3D_Z[2*i+1].X:=0; | |
| 123 | subAxis3D_Z[2*i+1].Y:=0.2; | |
| 124 | subAxis3D_Z[2*i+1].Z:=-3+i; | |
| 125 | end; | |
| 126 | ||
| 127 | for i:=0 to PointsCount do | |
| 128 | for j:=0 to PointsCount do | |
| 129 | begin | |
| 130 | Points3D[i][j].X:=X0+i*dX; | |
| 131 | Points3D[i][j].Y:=Y0+j*dY; | |
| 132 | Points3D[i][j].Z:=cos(Points3D[i][j].X+sin(Points3D[i][j].Y)); | |
| 133 | end; | |
| 134 | ||
| 135 | zMin:=Points3D[0][0].Z; | |
| 136 | zMax:=zMin; | |
| 137 | for i:=0 to PointsCount do | |
| 138 | for j:=0 to PointsCount do | |
| 139 | begin | |
| 140 | if (zMin>Points3D[i][j].Z) then | |
| 141 | zMin:= Points3D[i][j].Z; | |
| 142 | if (zMax<Points3D[i][j].Z) then | |
| 143 | zMax:= Points3D[i][j].Z; | |
| 144 | end; | |
| 145 | ScaleX:=50;//(Xn-X0); | |
| 146 | ScaleY:=100;//(zMax-zMin); | |
| 147 | //ScaleY:=100; | |
| 148 | DrawPoints; | |
| 149 | end; | |
| 150 | ||
| 151 | procedure TForm1.FormCreate(Sender: TObject); | |
| 152 | begin | |
| 153 | // Âû÷èñëÿåì öåíòð ýêðàíà | |
| 154 | oX := Image1.Width div 2; | |
| 155 | oY := Image1.Height div 2; | |
| 156 | ||
| 157 | Alpha:=0; | |
| 158 | AlphAP:=ArcTan(1)/4; | |
| 159 | ||
| 160 | // ScaleX:=50; | |
| 161 | // ScaleY:=25; | |
| 162 | // Óñòàíàâëèâàåì öâåò ôîíà (áóôôåðà ðèñîâàíèÿ) | |
| 163 | ||
| 164 | BufferColor := clWhite; | |
| 165 | ||
| 166 | // Ñîçäàåì áóôôåðà ðèñîâàíèÿ | |
| 167 | ||
| 168 | DrawBuffer := TBitMap.Create; | |
| 169 | DrawBuffer.Width := Image1.Width; | |
| 170 | DrawBuffer.Height := Image1.Height; | |
| 171 | ||
| 172 | // Î÷èùàåì áóôôåð | |
| 173 | ||
| 174 | ClearBuffer; | |
| 175 | end; | |
| 176 | ||
| 177 | procedure TForm1.DrawPoints; | |
| 178 | var | |
| 179 | tX: Real; | |
| 180 | tY: Real; | |
| 181 | i,j: Integer; | |
| 182 | ||
| 183 | begin | |
| 184 | if DrawBuffer <> nil then | |
| 185 | begin | |
| 186 | ClearBuffer; | |
| 187 | for i:=0 to 6 do | |
| 188 | begin | |
| 189 | tX:=(Axis3D[i].X+Axis3D[i].Y*cos(AlphaP))*ScaleX; | |
| 190 | tY:=(Axis3D[i].Z+Axis3D[i].Y*sin(AlphaP))*ScaleY; | |
| 191 | Axis2D[i].X:=ROUND(oX+tX); | |
| 192 | Axis2D[i].Y:=ROUND(oY-tY); | |
| 193 | end; | |
| 194 | ||
| 195 | for i:=0 to 13 do | |
| 196 | begin | |
| 197 | tX:=(subAxis3D_X[i].X+subAxis3D_X[i].Y*cos(AlphaP))*ScaleX; | |
| 198 | tY:=(subAxis3D_X[i].Z+subAxis3D_X[i].Y*sin(AlphaP))*ScaleY; | |
| 199 | subAxis2D_X[i].X:=ROUND(oX+tX); | |
| 200 | subAxis2D_X[i].Y:=ROUND(oY-tY); | |
| 201 | ||
| 202 | tX:=(subAxis3D_Y[i].X+subAxis3D_Y[i].Y*cos(AlphaP))*ScaleX; | |
| 203 | tY:=(subAxis3D_Y[i].Z+subAxis3D_Y[i].Y*sin(AlphaP))*ScaleY; | |
| 204 | subAxis2D_Y[i].X:=ROUND(oX+tX); | |
| 205 | subAxis2D_Y[i].Y:=ROUND(oY-tY); | |
| 206 | ||
| 207 | tX:=(subAxis3D_Z[i].X+subAxis3D_Z[i].Y*cos(AlphaP))*ScaleX; | |
| 208 | tY:=(subAxis3D_Z[i].Z+subAxis3D_Z[i].Y*sin(AlphaP))*ScaleY; | |
| 209 | subAxis2D_Z[i].X:=ROUND(oX+tX); | |
| 210 | subAxis2D_Z[i].Y:=ROUND(oY-tY); | |
| 211 | end; | |
| 212 | ||
| 213 | for i := 0 to PointsCount do | |
| 214 | for j := 0 to PointsCount do | |
| 215 | begin | |
| 216 | tX:=(Points3D[i][j].X+Points3D[i][j].Y*cos(AlphaP))*ScaleX; | |
| 217 | tY:=(Points3D[i][j].Z+Points3D[i][j].Y*sin(AlphaP))*ScaleY; | |
| 218 | Points2D[i][j].X:=ROUND(oX+tX); | |
| 219 | Points2D[i][j].Y:=ROUND(oY-tY); | |
| 220 | end; | |
| 221 | ||
| 222 | ||
| 223 | DrawBuffer.Canvas.Pen.Width:=3; | |
| 224 | DrawBuffer.Canvas.Pen.Color := clBlue; | |
| 225 | DrawBuffer.Canvas.Brush.Color := clGreen; | |
| 226 | ||
| 227 | ||
| 228 | DrawBuffer.Canvas.MoveTo(Axis2D[1].X,Axis2D[1].Y); | |
| 229 | DrawBuffer.Canvas.LineTo(Axis2D[2].X,Axis2D[2].Y); | |
| 230 | ||
| 231 | DrawBuffer.Canvas.MoveTo(Axis2D[3].X,Axis2D[3].Y); | |
| 232 | DrawBuffer.Canvas.LineTo(Axis2D[4].X,Axis2D[4].Y); | |
| 233 | ||
| 234 | DrawBuffer.Canvas.MoveTo(Axis2D[5].X,Axis2D[5].Y); | |
| 235 | DrawBuffer.Canvas.LineTo(Axis2D[6].X,Axis2D[6].Y); | |
| 236 | ||
| 237 | ||
| 238 | DrawBuffer.Canvas.Pen.Width :=2; | |
| 239 | DrawBuffer.Canvas.Pen.Color := clBlue; | |
| 240 | ||
| 241 | for i:=0 to 6 do | |
| 242 | begin | |
| 243 | DrawBuffer.Canvas.MoveTo(subAxis2D_X[2*i].X, subAxis2D_X[2*i].Y); | |
| 244 | DrawBuffer.Canvas.LineTo(subAxis2D_X[2*i+1].X, subAxis2D_X[2*i+1].Y); | |
| 245 | DrawBuffer.Canvas.MoveTo(subAxis2D_Y[2*i].X, subAxis2D_Y[2*i].Y); | |
| 246 | DrawBuffer.Canvas.LineTo(subAxis2D_Y[2*i+1].X, subAxis2D_Y[2*i+1].Y); | |
| 247 | DrawBuffer.Canvas.MoveTo(subAxis2D_Z[2*i].X, subAxis2D_Z[2*i].Y); | |
| 248 | DrawBuffer.Canvas.LineTo(subAxis2D_Z[2*i+1].X, subAxis2D_Z[2*i+1].Y); | |
| 249 | end; | |
| 250 | // Ðèñóåì íàø ïîëèãîí. | |
| 251 | ||
| 252 | DrawBuffer.Canvas.Pen.Width :=1; | |
| 253 | DrawBuffer.Canvas.Pen.Color := clBlack; | |
| 254 | DrawBuffer.Canvas.Brush.Color := clGreen; | |
| 255 | for i := 0 to PointsCount do | |
| 256 | begin | |
| 257 | DrawBuffer.Canvas.MoveTo(Points2D[i][0].X, Points2D[i][0].Y); | |
| 258 | for j := 1 to PointsCount do | |
| 259 | DrawBuffer.Canvas.LineTo(Points2D[i][j].X, Points2D[i][j].Y); | |
| 260 | end; | |
| 261 | ||
| 262 | for i := 0 to PointsCount do | |
| 263 | begin | |
| 264 | DrawBuffer.Canvas.MoveTo(Points2D[0][i].X, Points2D[0][i].Y); | |
| 265 | for j := 1 to PointsCount do | |
| 266 | DrawBuffer.Canvas.LineTo(Points2D[j][i].X, Points2D[j][i].Y); | |
| 267 | end; | |
| 268 | ||
| 269 | //DrawBuffer.Canvas.Polygon(Points2D); | |
| 270 | Image1.Canvas.Draw(0, 0, DrawBuffer); | |
| 271 | end; | |
| 272 | end; | |
| 273 | ||
| 274 | procedure TForm1.ClearBuffer; | |
| 275 | begin | |
| 276 | DrawBuffer.Canvas.Pen.Color := BufferColor; | |
| 277 | DrawBuffer.Canvas.Brush.Color := BufferColor; | |
| 278 | DrawBuffer.Canvas.Rectangle(0, 0, Image1.Width, Image1.Height); | |
| 279 | end; | |
| 280 | ||
| 281 | procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); | |
| 282 | begin | |
| 283 | if DrawBuffer <> nil then | |
| 284 | begin | |
| 285 | DrawBuffer.Free; | |
| 286 | DrawBuffer := nil; | |
| 287 | end; | |
| 288 | end; | |
| 289 | ||
| 290 | procedure TForm1.Timer1Timer(Sender: TObject); | |
| 291 | var i,j:integer; | |
| 292 | begin | |
| 293 | //https://ru.wikipedia.org/wiki/%D0%9C%D0%B0%D1%82%D1%80%D0%B8%D1%86%D0%B0_%D0%BF%D0%BE%D0%B2%D0%BE%D1%80%D0%BE%D1%82%D0%B0 | |
| 294 | Alpha:=Alpha+0.05; | |
| 295 | X0:=-3.14; Xn:=3.14; | |
| 296 | Y0:=-3.14; Yn:=3.14; | |
| 297 | dX:= (Xn-X0)/PointsCount; | |
| 298 | dY:= (Yn-Y0)/PointsCount; | |
| 299 | for i:=0 to PointsCount do | |
| 300 | for j:=0 to PointsCount do | |
| 301 | begin | |
| 302 | Points3D[i][j].X:=(X0+i*dX)*cos(Alpha)-(Y0+j*dY)*sin(Alpha); | |
| 303 | Points3D[i][j].Y:=(X0+i*dX)*sin(Alpha)+(Y0+j*dY)*cos(Alpha); | |
| 304 | Points3D[i][j].Z:=Points3D[i][j].Z*1; | |
| 305 | end; | |
| 306 | DrawPoints; | |
| 307 | end; | |
| 308 | ||
| 309 | procedure TForm1.Button2Click(Sender: TObject); | |
| 310 | begin | |
| 311 | Timer1.Enabled:= not Timer1.Enabled; | |
| 312 | end; | |
| 313 | ||
| 314 | end. |