⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trigu.pas

📁 source a top program in delphi.
💻 PAS
字号:
{********************************************************************************************
 **                                 TestTrig.Pas Unit                                      **
 **  ------------------------------------------------------------------------------------  **
 **	 This unit generates a sine and cosine lookup table.  This is an optimization         **
 **	 technique which greatly speeds up Trig functions, since they use so much Sines,      **
 **   Cosines, etc.  Using this technique, a program generates all of the possible values  **
 **   before hand, and then looks them up in a table when they are needed.  This avoids    **
 **   using the very slow built in Trig functions.                                         **
 ********************************************************************************************}

unit Trigu;

interface

type
    TSineArray = array[0..359] of Real;
    TCosineArray = array[0..359] of Real;

var
   SineArray: ^TSineArray;
   CosineArray: ^TCosineArray;

procedure InitSineArray;
procedure InitCosineArray;
procedure DestroySineArray;
procedure DestroyCosineArray;

implementation

procedure InitSineArray;
var
   Count: Integer;
begin
  {allocate memory for the sine array}
  GetMem(SineArray, SizeOf(TSineArray));

  {generate sines for 360 degrees.  remember, we must convert to radians for the sin function}
  for Count:=0 to 359 do
      SineArray^[Count]:=Sin((Count)*(pi / 180));
end;

procedure InitCosineArray;
var
   Count: Integer;
begin
  {allocate memory for the sine array}
  GetMem(CosineArray, SizeOf(TCosineArray));

  {generate cosines for 360 degrees.  remember, we must convert to radians for the cos function}
  for Count:=0 to 359 do
      CosineArray^[Count]:=Cos((Count)*(pi / 180));
end;

procedure DestroySineArray;
begin
  {deallocate the memory}
  FreeMem(SineArray, SizeOf(TSineArray));
end;

procedure DestroyCosineArray;
begin
  {deallocate the memory}
  FreeMem(CosineArray, SizeOf(TCosineArray));
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -