Haversine example – VXI VT1422A User Manual

Page 490

Advertising
background image

488 Generating User Defined Functions

Appendix F

approximation. Remember, the entire range is broken up into only 128
segments of Mx+B operations. If accuracy is desired, the range MUST be
limited over which calculations are made. Many transcendental functions
are simply used as a scaling multiplier. For example, a sine wave function is
typically created over a range of 360 degrees or 2

π

radians. After which, the

function repeats itself. It's a simple matter to make sure the 'x' term is scaled
to this range before calculating the result. This concept should be used
almost exclusively to obtain the best results.

Haversine Example

The following is an example of creating a haversine function (a sine wave
over the range of -

π

/2 to

π

/2). The resulting function represents a fairly

accurate approximation of this non-linear waveform when the range is
limited as indicated. Since the tables must be built upon binary boundaries
(i.e., 0.125, 0.25, 0.5, 1, 2, 4, etc.) and since

π

/2 is a number greater than 1

but less than 2, the next binary interval to include this range will be 2.
Another requirement for building the table is that the waveform range
MUST be centered around 0 (i.e., symmetrical about the X-axis). If the
desired function is not defined on one side or the other of the Y-axis, then
the table is right or left shifted by the offset from X=0 and the table values
are calculated correctly, but the table is built as though it were centered
about the X-axis. For the most part, the last couple sentences can be ignored
if they are not understood. This is only brought up because the accuracy may
suffer the farther away from the X=0 point the center is unless the resolution
available is understood and how much non-linearity is present in the
waveform. This is discussed later in the "Limitations" section.

Figure F-1 shows the haversine function as stated above. This type of
waveform is typical of the kind of acceleration and deceleration one wants
when moving an object from one point to another. The desired beginning
point would be the location at -

π

/2 and the ending point would be at

π

/2.

With the desired range spread over ±

π

/2, the 128 segments are actually

divided over the range of ±2. Therefore, the 128 Mx+B line segments are
divided equally on both sides of X=0: 64 segments for 0..2 and 64 segments
for -2..0.

Advertising
This manual is related to the following products: