PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFXTrigonometric
Class which performs high-speed trigonometric calculation using the trigonometric table.
#include <SFXTrigonometric.h.hpp>
class SFXTrigonometric;
SFMTYPEDEFCLASS(SFXTrigonometric)

Description

The SFXTrigonometric class performs high-speed trigonometric calculation using the trigonometric table.

First of all, create the trigonometric table with the n equal parts of the radian section [0, FLOAT64_PI / 2] and their corresponding cosine values using the SFXTrigonometric::Initialize function. (FLOAT64_PI: the ratio of the circumference of a circle to its diameter)

And then, quickly calculate the cosine, sine, or tangent for the specified angle in radians using the SFXTrigonometric::Cos, SFXTrigonometric::Sin, or SFXTrigonometric::Sin function. In these functions, the above trigonometric table is internally used.

[Note] Trade-off of between calculation frequency and performance

In general, trigonometric functions usually take much time. When trigonometric functions are frequently called, performance might be improved by using the SFXTrigonometric class.

[Note] Trade-off of between calculation accuracy and memory consumption

Calculation accuracy is improved as the number of the equal parts of the radian section [0, FLOAT64_PI / 2] increases. And the values which the trigonometric table contains also increases. Therefore heap memory will be needed all the more. (The consumption of heap memory is N * 8 bytes, where N is the number of the equal parts of the radian section [0, FLOAT64_PI / 2].)

Example

Create the trigonometric table by with the 180 equal parts of the radian section [0, pi / 2], and perform high-speed trigonometric calculation.

Float64 x, y;
Float64 e = 1.0e-10;             // asymptotic accuracy
Float64 pi = 3.14159265358979;   // the ratio of the circumference of a circle to its diameter

SFXTrigonometric tri;
tri.Initialize(180, e);          // initialize trigonometric table

x = tri.Cos(pi / 3);
y = tri.Sin(pi / 3);

Member

Constructor/Destructor
SFXTrigonometric( Void )
Constructor of the SFXTrigonometric class.
~SFXTrigonometric( Void )
Destructor of the SFXTrigonometric class.
Public Functions
Float64 Cos( Float64 param )
Calculate the cosine of a specific angle in radians.
static
Float64
DegreeToGradian( Float64 param )
Convert a specific angle in degrees to an angle in gradians.
static
Float64
DegreeToRadian( Float64 param )
Convert a specific angle in degrees to an angle in radians.
static
Float64
GradianToDegree( Float64 param )
Convert a specific angle in gradians to an angle in degrees.
static
Float64
GradianToRadian( Float64 param )
Convert a specific angle in gradians to an angle in radians.
SFCError Initialize( SInt16 division = 90 )
Initialize the trigonometric table.
static
Float64
RadianToDegree( Float64 param )
Convert a specific angle in radians to an angle in degrees.
static
Float64
RadianToGradian( Float64 param )
Convert a specific angle in radians to an angle in gradians.
Float64 Sin( Float64 param )
Calculate the sine of a specific angle in radians.
Float64 Tan( Float64 param )
Calculate the tangent of a specific angle in radians.
Void Terminate( Void )
Destroy the trigonometric table.

SFXTrigonometric::SFXTrigonometric
Constructor of the SFXTrigonometric class.
[ public, explicit ]
SFXTrigonometric(Void);

Description

To create a trigonometric table, call the SFXTrigonometric::Initialize function.

[Note] Note
No trigonometric table is generated in this constructor.

Reference

SFXTrigonometric::Initialize


SFXTrigonometric::~SFXTrigonometric
Destructor of the SFXTrigonometric class.
[ public ]
~SFXTrigonometric(Void);

Description

Heap memory used by the trigonometric table is released.


SFXTrigonometric::Cos
Calculate the cosine of a specific angle in radians.
[ public, const ]
Float64 Cos(
    Float64 param   // angle in radians
);

Description

The SFXTrigonometric::Cos function calculates the cosine of an angle in radians using the trigonometric table.

[Note] Note
The trigonometric table needs to be created using the SFXTrigonometric::Initialize function before calling the SFXTrigonometric::Cos function.

Example

Float64 c;
SFXTrigonometric tri;

tri.Initialize();         // initialize trigonometric table
c = tri.Cos(FLOAT64_PI);  // c = -1;

Reference

SFXTrigonometric::Initialize


SFXTrigonometric::DegreeToGradian
Convert a specific angle in degrees to an angle in gradians.
[ public, static ]
Float64 DegreeToGradian(
    Float64 param   // angle in degrees
);

Reference

SFXTrigonometric::RadianToGradian | SFXTrigonometric::RadianToDegree | SFXTrigonometric::GradianToRadian | SFXTrigonometric::GradianToDegree | SFXTrigonometric::DegreeToRadian


SFXTrigonometric::DegreeToRadian
Convert a specific angle in degrees to an angle in radians.
[ public, static ]
Float64 DegreeToRadian(
    Float64 param   // angle in degrees
);

Example

Float64 n = SFXTrigonometric::DegreeToRadian(180);    // n = 3.1415... 

Reference

SFXTrigonometric::RadianToGradian | SFXTrigonometric::RadianToDegree | SFXTrigonometric::GradianToRadian | SFXTrigonometric::GradianToDegree | SFXTrigonometric::DegreeToGradian


SFXTrigonometric::GradianToDegree
Convert a specific angle in gradians to an angle in degrees.
[ public, static ]
Float64 GradianToDegree(
    Float64 param   // angle in gradians
);

Reference

SFXTrigonometric::RadianToGradian | SFXTrigonometric::RadianToDegree | SFXTrigonometric::GradianToRadian | SFXTrigonometric::DegreeToRadian | SFXTrigonometric::DegreeToGradian


SFXTrigonometric::GradianToRadian
Convert a specific angle in gradians to an angle in radians.
[ public, static ]
Float64 GradianToRadian(
    Float64 param   // angle in gradians
);

Reference

SFXTrigonometric::RadianToGradian | SFXTrigonometric::RadianToDegree | SFXTrigonometric::GradianToDegree | SFXTrigonometric::DegreeToRadian | SFXTrigonometric::DegreeToGradian


SFXTrigonometric::Initialize
Initialize the trigonometric table.
[ public ]
SFCError Initialize(
    SInt16 division = 90   // radian section [0, FLOAT64_PI / 2]
);

Argument

division

Specify the number of the equal parts of the radian section [0, FLOAT64_PI / 2] The greater the value of this parameter, the larger the consumption of heap memory.

Return value

  • If succeeds: SFERR_NO_ERROR
  • If argument is invalid: SFERR_INVALID_PARAM
  • If insufficient memory: SFERR_NO_MEMROY

Description

The SFXTrigonometric::Initialize function creates the trigonometric table for performing high-speed trigonometric calculation.

[Caution] Notes

The SFXTrigonometric::Initialize function destroys the previous trigonometric table.

Example

Execute the SFXTrigonometric::Initialize function immediately after the constructor is called.

SFXTrigonometric tri;
tri.Initialize(180);

Reference

SFXTrigonometric::Terminate


SFXTrigonometric::RadianToDegree
Convert a specific angle in radians to an angle in degrees.
[ public, static ]
Float64 RadianToDegree(
    Float64 param   // angle in radians
);

Example

Float64 n = SFXTrigonometric::RadianToDegree(6.2831); // n = 359.99... 

Reference

SFXTrigonometric::RadianToGradian | SFXTrigonometric::GradianToRadian | SFXTrigonometric::GradianToDegree | SFXTrigonometric::DegreeToRadian | SFXTrigonometric::DegreeToGradian


SFXTrigonometric::RadianToGradian
Convert a specific angle in radians to an angle in gradians.
[ public, static ]
Float64 RadianToGradian(
    Float64 param   // angle in radians
);

Reference

SFXTrigonometric::RadianToDegree | SFXTrigonometric::GradianToRadian | SFXTrigonometric::GradianToDegree | SFXTrigonometric::DegreeToRadian | SFXTrigonometric::DegreeToGradian


SFXTrigonometric::Sin
Calculate the sine of a specific angle in radians.
[ public, const ]
Float64 Sin(
    Float64 param   // angle in radians
);

Description

The SFXTrigonometric::Sin function calculates the sine of an angle in radians using the trigonometric table.

[Note] Note
The trigonometric table needs to be created using the SFXTrigonometric::Initialize function before calling the SFXTrigonometric::Sin function.

Example

Float64 c;
SFXTrigonometric tri;

tri.Initialize();            // initialize trigonometric table
c = tri.Sin(FLOAT64_PI / 2); // c = 1;

Reference

SFXTrigonometric::Initialize


SFXTrigonometric::Tan
Calculate the tangent of a specific angle in radians.
[ public, const ]
Float64 Tan(
    Float64 param   // angle in radians
);

Description

The SFXTrigonometric::Tan function calculates the tangent of an angle in radians using the trigonometric table.

[Note] Note
The trigonometric table needs to be created using the SFXTrigonometric::Initialize function before calling the SFXTrigonometric::Tan function.

Example

Float64 c;
SFXTrigonometric tri;

tri.Initialize();            // initialize trigonometric table
c = tri.Tan(FLOAT64_PI / 4); // c = 1;

Reference

SFXTrigonometric::Initialize


SFXTrigonometric::Terminate
Destroy the trigonometric table.
[ public ]
Void Terminate(Void);

Description

The SFXTrigonometric::Terminate function is automatically called by the destructor.