ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Macros | Functions | Variables
cordic.c File Reference

Cordic Routines Handle angle outside of the first quadrant Added standalone test to verify CORDIC against math library Add Documentation and references. More...

#include "user_config.h"
#include <stdint.h>
#include <string.h>
#include "printf/mathio.h"
#include <math.h>
#include "cordic2c_inc.h"
#include "cordic.h"

Go to the source code of this file.

Macros

#define CORDIC_TABLE   /* include the generated Cordic table */
 

Functions

MEMSPACE double deg2rad (double deg)
 Convert Degrees to Rads. More...
 
MEMSPACE double angle_quad (double quads, int *quad)
 Compute quadrant of angle and the quadrant modulus Note: Integer part is quadrant. More...
 
void Circular (Cordic_T x, Cordic_T y, Cordic_T z)
 
MEMSPACE void cordic_quad (double angle, double *s, double *c)
 Compute Sin and Cos from angle in quads using Cordic. More...
 
MEMSPACE void cordic_deg (double deg, double *s, double *c)
 Compute Sin and Cos from angle in degrees using Cordic. More...
 
MEMSPACE void cordic_rad (double rad, double *s, double *c)
 Compute Sin and Cos from angle in Rads using Cordic. More...
 
MEMSPACE void scale_point (point *P, double scale)
 Scale x,y,z by scale factor. More...
 
MEMSPACE void shift_point (point *P, point *shift)
 Shift x,y,z by shift. More...
 
MEMSPACE void rotate (point *P, point *V)
 Rotate point P by View point. More...
 
MEMSPACE void PerspectiveProjection (point *P, double scale, int x, int y)
 

Variables

Cordic_T X
 Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers, where 1.0=Cordic_One cordic.h. More...
 
Cordic_T Y
 
Cordic_T Z
 

Detailed Description

Cordic Routines Handle angle outside of the first quadrant Added standalone test to verify CORDIC against math library Add Documentation and references.

Cordic Code Modified by Mike Gore 2015 to generate C Cordic tables The code has been adjusted to quads (Where 90 degrees = 1.0) The angle is just the fractional part of a floating point number The integer part is the quadrant. This makes computations for code using the tables much faster.

See also
http://en.wikipedia.org/wiki/CORDIC
cordic.h, we use fixed point numbers, where 1.0=Cordic_One Note: 1.0 = 90 degrees
Copyright © 2015 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Original Documentation

CORDIC algorithms. The original code was published in Doctor Dobbs Journal issue ddj9010. The ddj version can be obtained using FTP from SIMTEL and other places.

Converted to ANSI-C (with prototypes) by P. Knoppers, 13-Apr-1992.

The main advantage of the CORDIC algorithms is that all commonly used math Functions ([a]sin[h] [a]cos[h] [a]tan[h] atahh ln exp sqrt) are Implemented using only shifts, add, subtract and compare. All values are treated as integers. Actually they are fixed point values. The position of the fixed point is a compile time constant (Cordic_T_FractionBits). I don't believe that this can be easily fixed...

Some initialization of internal tables and constants is necessary before all functions can be used. The constant "Cordic_HalfPI" must be determined before compile time, all others are computed during run-time - see main() below.

Of course, any serious implementation of these functions should probably have all constants determined sometime before run-time and most functions might be written in assembler.

The layout of the code is adapted to my personal preferences. PK.

Definition in file cordic.c.

Macro Definition Documentation

#define CORDIC_TABLE   /* include the generated Cordic table */

Definition at line 35 of file cordic.c.

Function Documentation

MEMSPACE double angle_quad ( double  quads,
int *  quad 
)

Compute quadrant of angle and the quadrant modulus Note: Integer part is quadrant.

See also
cordic.h, we use fixed point numbers, where 1.0=Cordic_One Note: 1.0 = 90 degrees
Parameters
[in]quads1.0 = 90 degrees
[out]quadquadrant 0 = 0 .. 89.9999, 1 = 90 ... 179.999 ..., etc
Returns
fractional part of quads

Definition at line 71 of file cordic.c.

Referenced by cordic_quad().

void Circular ( Cordic_T  x,
Cordic_T  y,
Cordic_T  z 
)

Definition at line 103 of file cordic.c.

Referenced by cordic_quad().

MEMSPACE void cordic_deg ( double  deg,
double *  s,
double *  c 
)

Compute Sin and Cos from angle in degrees using Cordic.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in]degangle in degrees
[in,out]*ssin
[in,out]*ccos
Returns
void

Definition at line 215 of file cordic.c.

Referenced by PerspectiveProjection(), and rotate().

MEMSPACE void cordic_quad ( double  angle,
double *  s,
double *  c 
)

Compute Sin and Cos from angle in quads using Cordic.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in]angleangle in quads ( 1 quad = 90 degrees)
[out]*ssin
[out]*ccos
Returns
void

Definition at line 144 of file cordic.c.

Referenced by cordic_deg(), and cordic_rad().

MEMSPACE void cordic_rad ( double  rad,
double *  s,
double *  c 
)

Compute Sin and Cos from angle in Rads using Cordic.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in]radangle in radians
[out]*ssin
[out]*ccos
Returns
void

Definition at line 228 of file cordic.c.

MEMSPACE double deg2rad ( double  deg)

Convert Degrees to Rads.

Parameters
[in]degdegrees
Returns
radians

Definition at line 57 of file cordic.c.

MEMSPACE void PerspectiveProjection ( point P,
double  scale,
int  x,
int  y 
)

Definition at line 310 of file cordic.c.

Referenced by wire_draw().

MEMSPACE void rotate ( point P,
point V 
)

Rotate point P by View point.

Parameters
[in]*Px,y,z point
[in]*VView point
Returns
void

Definition at line 265 of file cordic.c.

Referenced by wire_draw().

MEMSPACE void scale_point ( point P,
double  scale 
)

Scale x,y,z by scale factor.

Parameters
[in]*Px,y,z point
[in]scalescale factor
Returns
void

Definition at line 239 of file cordic.c.

MEMSPACE void shift_point ( point P,
point shift 
)

Shift x,y,z by shift.

Parameters
[in]*Px,y,z point
[in]shiftshift to apply to x,y,z
Returns
void

Definition at line 252 of file cordic.c.

Variable Documentation

Main Cordic routine - used for basic trig and vector rotations We use fixed point numbers, where 1.0=Cordic_One cordic.h.

See also
http://en.wikipedia.org/wiki/CORDIC
Parameters
[in,out]xin: Cordik_K, out: Cos of z
[in,out]yin: 0, out: Sin of z
[in,out]zin: fixed point version of angle in quads, out: not used
Returns
void

Definition at line 102 of file cordic.c.

Referenced by AdjustFontTable(), Circular(), cordic_quad(), FontAdjustSmall(), tft_Bezier2(), tft_Bezier3(), tft_clip_xy(), and user_loop().

Definition at line 102 of file cordic.c.

Referenced by Circular().