AOT計算で呼び出し自体を早くする三角関数
AOTTrigon.h@11:19594eeb6f2b, 2015-03-11 (annotated)
- Committer:
- kb10uy
- Date:
- Wed Mar 11 14:35:12 2015 +0000
- Revision:
- 11:19594eeb6f2b
- Parent:
- 10:5bccb4bc4f33
??
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 | 10:5bccb4bc4f33 | 3 | #include "mbed.h" |
kb10uy | 0:2888f1d9a23e | 4 | |
kb10uy | 0:2888f1d9a23e | 5 | /** AOTTrigon class |
kb10uy | 0:2888f1d9a23e | 6 | * AOT計算によって三角関数の計算を高速化します。 |
kb10uy | 0:2888f1d9a23e | 7 | */ |
kb10uy | 0:2888f1d9a23e | 8 | class AOTTrigon |
kb10uy | 0:2888f1d9a23e | 9 | { |
kb10uy | 0:2888f1d9a23e | 10 | public: |
kb10uy | 11:19594eeb6f2b | 11 | AOTTrigon(int c) { |
kb10uy | 11:19594eeb6f2b | 12 | pi = 3.14159265358979323846264; |
kb10uy | 11:19594eeb6f2b | 13 | rate = 40.743665431525205956834243423364; |
kb10uy | 11:19594eeb6f2b | 14 | for(int i = 0; i < 256; i++) |
kb10uy | 11:19594eeb6f2b | 15 | t_sin[i] = sin(i / 256.0 * (pi * 2.0)); |
kb10uy | 11:19594eeb6f2b | 16 | } |
kb10uy | 0:2888f1d9a23e | 17 | |
kb10uy | 11:19594eeb6f2b | 18 | double fsin(double x) { |
kb10uy | 11:19594eeb6f2b | 19 | return x * rate;//t_sin[((int)(x * rate)) % 256]; |
kb10uy | 11:19594eeb6f2b | 20 | } |
kb10uy | 11:19594eeb6f2b | 21 | |
kb10uy | 11:19594eeb6f2b | 22 | double fcos(double x) { |
kb10uy | 11:19594eeb6f2b | 23 | return fsin(x + pi / 2.0f); |
kb10uy | 11:19594eeb6f2b | 24 | } |
kb10uy | 11:19594eeb6f2b | 25 | |
kb10uy | 11:19594eeb6f2b | 26 | double ftan(double x) { |
kb10uy | 11:19594eeb6f2b | 27 | return fsin(x) / fcos(x); |
kb10uy | 11:19594eeb6f2b | 28 | } |
kb10uy | 0:2888f1d9a23e | 29 | |
kb10uy | 0:2888f1d9a23e | 30 | private: |
kb10uy | 11:19594eeb6f2b | 31 | double t_sin[256]; |
kb10uy | 10:5bccb4bc4f33 | 32 | double rate; |
kb10uy | 11:19594eeb6f2b | 33 | double pi; |
kb10uy | 1:f1e55d228f6a | 34 | }; |
kb10uy | 3:ba78a1dd8b55 | 35 |