Some further speedup improvements on calculating sine and cosine of the same value.

This commit is contained in:
utak3r 2005-09-11 20:59:57 +00:00
parent 81d7acf723
commit 0013bdf1c7

View File

@ -308,14 +308,16 @@ procedure TXForm.Disc;
var var
nx, ny, r: double; nx, ny, r: double;
rPI: double; rPI: double;
sinr, cosr: extended;
begin begin
rPI := 0.31830989; rPI := 0.31830989;
nx := FTx * PI; nx := FTx * PI;
ny := FTy * PI; ny := FTy * PI;
r := sqrt(nx * nx + ny * ny); r := sqrt(nx * nx + ny * ny);
FPx := FPx + vars[8] * sin(r) * FAngle * rPI; SinCos(r, sinr, cosr);
FPy := FPy + vars[8] * cos(r) * FAngle * rPI; FPx := FPx + vars[8] * sinr * FAngle * rPI;
FPy := FPy + vars[8] * cosr * FAngle * rPI;
end; end;
@ -323,12 +325,14 @@ end;
procedure TXForm.Spiral; procedure TXForm.Spiral;
var var
r, rr: double; r, rr: double;
sinr, cosr: extended;
begin begin
// r := sqrt(FTx * FTx + FTy * FTy) + 1E-6; // r := sqrt(FTx * FTx + FTy * FTy) + 1E-6;
r := Flength + 1E-6; r := Flength + 1E-6;
rr := 1 / r; rr := 1 / r;
FPx := FPx + vars[9] * (FCosA + sin(r)) * rr; SinCos(r, sinr, cosr);
FPy := FPy + vars[9] * (FsinA - cos(r)) * rr; FPx := FPx + vars[9] * (FCosA + sinr) * rr;
FPy := FPy + vars[9] * (FsinA - cosr) * rr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -344,12 +348,14 @@ end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
procedure TXForm.Square; procedure TXForm.Square;
//var var
// r: double; // r: double;
sinr, cosr: extended;
begin begin
// r := sqrt(FTx * FTx + FTy * FTy); // r := sqrt(FTx * FTx + FTy * FTy);
FPx := FPx + vars[11] * FSinA * cos(Flength); SinCos(Flength, sinr, cosr);
FPy := FPy + vars[11] * FCosA * sin(Flength); FPx := FPx + vars[11] * FSinA * cosr;
FPy := FPy + vars[11] * FCosA * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -371,11 +377,13 @@ end;
procedure TXForm.Julia; procedure TXForm.Julia;
var var
a,r: double; a,r: double;
sinr, cosr: extended;
begin begin
r := Math.power(FTx * FTx + FTy * FTy, 0.25); r := Math.power(FTx * FTx + FTy * FTy, 0.25);
a := FAngle*0.5 + Trunc(random * 2) * PI; a := FAngle*0.5 + Trunc(random * 2) * PI;
FPx := FPx + vars[13] * r * cos(a); SinCos(a, sinr, cosr);
FPy := FPy + vars[13] * r * sin(a); FPx := FPx + vars[13] * r * cosr;
FPy := FPy + vars[13] * r * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -442,11 +450,13 @@ end;
procedure TXForm.Exponential; procedure TXForm.Exponential;
var var
dx, dy: double; dx, dy: double;
sinr, cosr: extended;
begin begin
dx := exp(FTx)/ 2.718281828459045; dx := exp(FTx)/ 2.718281828459045;
dy := PI * FTy; dy := PI * FTy;
FPx := FPx + vars[18] * cos(dy) * dx; SinCos(dy, sinr, cosr);
FPy := FPy + vars[18] * sin(dy) * dx; FPx := FPx + vars[18] * cosr * dx;
FPy := FPy + vars[18] * sinr * dx;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -468,9 +478,11 @@ end;
procedure TXForm.Cosine; procedure TXForm.Cosine;
var var
nx, ny: double; nx, ny: double;
sinr, cosr: extended;
begin begin
nx := cos(FTx * PI) * cosh(FTy); SinCos(FTx * PI, sinr, cosr);
ny := -sin(FTx * PI) * sinh(FTy); nx := cosr * cosh(FTy);
ny := -sinr * sinh(FTy);
FPx := FPx + vars[20] * nx; FPx := FPx + vars[20] * nx;
FPy := FPy + vars[20] * ny; FPy := FPy + vars[20] * ny;
end; end;
@ -480,13 +492,15 @@ procedure TXForm.Rings;
var var
r: double; r: double;
dx: double; dx: double;
sinr, cosr: extended;
begin begin
dx := sqr(c20) + EPS; dx := sqr(c20) + EPS;
r := FLength; r := FLength;
r := r + dx - System.Int((r + dx)/(2 * dx)) * 2 * dx - dx + r * (1-dx); r := r + dx - System.Int((r + dx)/(2 * dx)) * 2 * dx - dx + r * (1-dx);
SinCos(FAngle, sinr, cosr);
FPx := FPx + vars[21] * r * cos(FAngle); FPx := FPx + vars[21] * r * cosr;
FPy := FPy + vars[21] * r * sin(FAngle); FPy := FPy + vars[21] * r * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -494,6 +508,7 @@ procedure TXForm.Fan;
var var
r,t,a : double; r,t,a : double;
dx, dy, dx2: double; dx, dy, dx2: double;
sinr, cosr: extended;
begin begin
dy := c21; dy := c21;
dx := PI * (sqr(c20) + EPS); dx := PI * (sqr(c20) + EPS);
@ -506,9 +521,10 @@ begin
a := FAngle - dx2 a := FAngle - dx2
else else
a := FAngle + dx2; a := FAngle + dx2;
SinCos(a, sinr, cosr);
FPx := FPx + vars[22] * r * cos(a); FPx := FPx + vars[22] * r * cosr;
FPy := FPy + vars[22] * r * sin(a); FPy := FPy + vars[22] * r * sinr;
end; end;
@ -517,6 +533,7 @@ procedure TXForm.Triblob;
var var
r : double; r : double;
Angle: double; Angle: double;
sinr, cosr: extended;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); r := sqrt(FTx * FTx + FTy * FTy);
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
@ -525,9 +542,10 @@ begin
Angle := 0.0; Angle := 0.0;
r := r * (0.6 + 0.4 * sin(3 * Angle)); r := r * (0.6 + 0.4 * sin(3 * Angle));
SinCos(Angle, sinr, cosr);
FPx := FPx + vars[23] * r * cos(Angle); FPx := FPx + vars[23] * r * cosr;
FPy := FPy + vars[23] * r * sin(Angle); FPy := FPy + vars[23] * r * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -535,6 +553,7 @@ procedure TXForm.Daisy;
var var
r : double; r : double;
Angle: double; Angle: double;
sinr, cosr: extended;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); r := sqrt(FTx * FTx + FTy * FTy);
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
@ -544,9 +563,10 @@ begin
// r := r * (0.6 + 0.4 * sin(3 * Angle)); // r := r * (0.6 + 0.4 * sin(3 * Angle));
r := r * ( 1 - Sqr(sin(5 * Angle))); r := r * ( 1 - Sqr(sin(5 * Angle)));
SinCos(Angle, sinr, cosr);
FPx := FPx + vars[24] * r * cos(Angle); FPx := FPx + vars[24] * r * cosr;
FPy := FPy + vars[24] * r * sin(Angle); FPy := FPy + vars[24] * r * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -568,6 +588,7 @@ procedure TXForm.CRot;
var var
r : double; r : double;
Angle: double; Angle: double;
sinr, cosr: extended;
begin begin
r := sqrt(FTx * FTx + FTy * FTy); r := sqrt(FTx * FTx + FTy * FTy);
if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then
@ -577,11 +598,12 @@ begin
if r < 3 then if r < 3 then
Angle := Angle + (3 - r) * sin(3 * r); Angle := Angle + (3 - r) * sin(3 * r);
SinCos(Angle, sinr, cosr);
// r:= R - 0.04 * sin(6.2 * R - 1) - 0.008 * R; // r:= R - 0.04 * sin(6.2 * R - 1) - 0.008 * R;
FPx := FPx + vars[26] * r * cos(Angle); FPx := FPx + vars[26] * r * cosr;
FPy := FPy + vars[26] * r * sin(Angle); FPy := FPy + vars[26] * r * sinr;
end; end;
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////