2
$\begingroup$

I am using a small microcontroller, which has limited processing resources. I need to calculate the three tangents:

tan(theta) tan(hdg + theta) tan(90 - hdg + theta) 

theta is virtually constant (it is a field of view); hdg may change. tan(theta) is provided by doing sin(theta)/cos(theta) (in my library), so that all tangents in total incur six trig function calls... which slows it down a lot.

Is it possible to calculate all of these at once?

  • 0
    You only need to compute `tan(hdg)` and `tan(theta)`; the rest are expressible in terms of these two via the sum/difference of two angles formulae for the tangent. If `tan(theta)` is, as you say, virtually constant, you might get away with not changing it for a number of iterations...2011-05-11
  • 1
    Depending on the resolution/accuracy required, you can calculate a table at start time and store it, then interpolate to avoid all run time trig. I had an application where storing every 5 degrees was sufficient (only 19 lines) and even interpolation wasn't needed. Very fast then.2011-05-11

2 Answers 2