AOT計算で呼び出し自体を早くする三角関数
AOTTrigon.h@2:d8c9637a5f09, 2014-12-23 (annotated)
- Committer:
- kb10uy
- Date:
- Tue Dec 23 05:32:28 2014 +0000
- Revision:
- 2:d8c9637a5f09
- Parent:
- 1:f1e55d228f6a
- Child:
- 3:ba78a1dd8b55
inlinize
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kb10uy | 0:2888f1d9a23e | 1 | #pragma once |
kb10uy | 0:2888f1d9a23e | 2 | #include "math.h" |
kb10uy | 0:2888f1d9a23e | 3 | |
kb10uy | 0:2888f1d9a23e | 4 | /** AOTTrigon class |
kb10uy | 0:2888f1d9a23e | 5 | * AOT計算によって三角関数の計算を高速化します。 |
kb10uy | 0:2888f1d9a23e | 6 | */ |
kb10uy | 0:2888f1d9a23e | 7 | class AOTTrigon |
kb10uy | 0:2888f1d9a23e | 8 | { |
kb10uy | 0:2888f1d9a23e | 9 | public: |
kb10uy | 0:2888f1d9a23e | 10 | /** AOTTrigon コンストラクター |
kb10uy | 0:2888f1d9a23e | 11 | * @param divide 分割数 |
kb10uy | 0:2888f1d9a23e | 12 | */ |
kb10uy | 0:2888f1d9a23e | 13 | AOTTrigon(int divide=256); |
kb10uy | 0:2888f1d9a23e | 14 | |
kb10uy | 2:d8c9637a5f09 | 15 | inline double sine(double x) { |
kb10uy | 2:d8c9637a5f09 | 16 | return t_sin[(int)(fmod(x,3.14159265358979323846264*2.0)*rate)]; |
kb10uy | 2:d8c9637a5f09 | 17 | } |
kb10uy | 2:d8c9637a5f09 | 18 | inline double cosine(double x) { |
kb10uy | 2:d8c9637a5f09 | 19 | return sine(x+3.14159265358979323846264/2.0); |
kb10uy | 2:d8c9637a5f09 | 20 | } |
kb10uy | 2:d8c9637a5f09 | 21 | inline double tangent(double x) { |
kb10uy | 2:d8c9637a5f09 | 22 | return sine(x)/cosine(x); |
kb10uy | 2:d8c9637a5f09 | 23 | } |
kb10uy | 0:2888f1d9a23e | 24 | |
kb10uy | 0:2888f1d9a23e | 25 | private: |
kb10uy | 0:2888f1d9a23e | 26 | double *t_sin; |
kb10uy | 0:2888f1d9a23e | 27 | int division; |
kb10uy | 0:2888f1d9a23e | 28 | double rate; |
kb10uy | 1:f1e55d228f6a | 29 | }; |