---
title: "正切函数的查表法实现"
author: "thinkact"
date: "2009-06-29T17:25:47Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2010-05-05T09:35:24Z"
id: 417135
url: "https://thinkact.iteye.com/blog/417135"
---

在嵌入式领域，三角函数运算比较影响效率，可以使用查表法提高效率

//1， 正切函数值表，90度时取值1000，这个还是浮点运算的，还是不够
const double TAN = {
		0,0.017,0.035,0.052,0.070,0.087,0.105,0.123,0.141,0.158,0.176,0.194,
		0.213,0.231,0.249,0.268,0.287,0.306,0.325,0.344,0.364,0.384,0.404,
		0.424,0.445,0.466,0.488,0.510,0.532,0.554,0.577,0.601,0.625,0.649,
		0.675,0.700,0.727,0.754,0.781,0.810,0.839,0.869,0.900,0.933,0.966,
		1.000,1.036,1.072,1.111,1.150,1.192,1.235,1.280,1.327,1.376,1.428,
		1.483,1.540,1.600,1.664,1.732,1.804,1.881,1.963,2.050,2.145,2.246,
		2.356,2.475,2.605,2.747,2.904,3.078,3.271,3.487,3.732,4.011,4.331,
		4.705,5.145,5.671,6.314,7.115,8.144,9.514,11.430,14.300,19.081,28.635,
		57.286,1000
	};
// 这个使用位移15位，把浮点运行换成整数乘法和位移，对一个角度 angle（角度，不是弧度） 有
 y = x * ITAN >> 15;
// 为了提高精度，可以加大位移数，本处使用的是： ITAN = TAN * 2的15次幂。90度时的无穷大用一个大数代替
const int ITAN =
	{568,1136,1705,2275,2847,3420,3995,4573,5153,5737,6324,6916,7512,8112,8718,9330,
	9947,10572,11203,11842,12489,13145,13811,14486,15172,15869,16578,17300,18035,18785,
	19550,20331,21129,21946,22782,23639,24518,25420,26347,27301,28283,29296,30340,31420,
	32536,33692,34891,36135,37428,38775,40179,41644,43177,44782,46466,48237,50101,52068,
	54149,56354,58696,61191,63855,66709,69774,73077,76650,80529,84759,89392,94491,100135,
	106420,113466,121425,130494,140928,153069,167382,184520,205423,231504,264982,309556,371883,
	465278,620809,931674,1863846,1863846
	};

--------------------------------------------------------------------
户外低价正品<span style="color:blue">**jfhw360.taobao.com**</span>