关于反正切函数中正切值可能是无穷大的情况时
public ArrayList slode(List<store> lists) //找斜率
{
ArrayList array = new ArrayList();
float k;
for (int i = 4; i < lists.Count; i += 4)
{
k = (float)(lists[i].y - lists[i - 4].y) / (float)(lists[i].x - lists[i - 4].x);此处k有可能是无穷大,但是无穷大的结果都丢失了
array.Add(k);
}
return array;
}
public ArrayList findNum(ArrayList array , double s, boolean t)//根据斜率判断笔画序列
{
Log.i("array represent slode of bihua in finNum",String.valueOf(array.toString()));
Log.i("s represent the lengthof bihua in finNum",String.valueOf(s));
Log.i("t represent direction of bihua in finNum",String.valueOf(t));
ArrayList bihuaNum=new ArrayList();
int x=1;
for(int i=0;i<array.size();i++)
{
Float a=(Float)array.get(i);
if(s<60)
{
x=9;
}
else
{
double b=Math.atan((double)a)*180/Math.PI;//斜率转换成角度 a有可能为无穷大但结果中 Log.i("a:"+String.valueOf(a),"b:"+String.valueOf(b));
if (b >= 0 && b < 20 || b > 160 && b <= 180)
{
x = 1; //横
}
else if (b > 70 && b < 110)
{
x = 2; //竖
}
else if (b >= 20 && b <= 70)
{
if (!t) //方向向右下
{
x = 4; //捺
}
else //方向向左上
x = 5; //钩
}
else if (b > -70 && b < -20)
{
if (t) //方向向左下
{ Log.i("pie of bihua in finNum",String.valueOf(b));
x = 3; //撇
}
else //方向向右上
x = 6; //提
}
bihuaNum.add(new Integer(x));
}
}Log.i("list1 in findNum",String.valueOf(bihuaNum.toString()));
return bihuaNum;
}
logcat中的部分信息
05-03 09:03:17.515: I/k:y,x: 33(832): 1.0
05-03 09:03:17.515: I/k:y,x: 97(832): 3.0
05-03 09:03:17.515: I/k:y,x: 102(832): -1.0
05-03 09:03:17.515: I/k:y,x: 86(832): 1.0
05-03 09:03:17.545: I/loc in Feature(832): [Point(216, 133), Point(216, 135), Point(216, 146), Point(217, 155), Point(217, 166), Point(218, 183), Point(220, 219), Point(220, 240), Point(220, 263), Point(219, 295), Point(218, 331), Point(219, 358), Point(219, 365), Point(219, 387), Point(219, 419), Point(219, 439), Point(220, 451), Point(220, 452)]
05-03 09:03:17.555: I/alist in Feature and return alist(832): [33.0, 32.333332, -102.0, 86.0]
05-03 09:03:17.555: I/the size of lists in direction(832): 18
05-03 09:03:17.555: I/System.out(832): 216*220
05-03 09:03:17.555: I/c in direction(832): -4
05-03 09:03:17.555: I/in direction(832): false
05-03 09:03:17.555: I/array represent slode of bihua in finNum(832): [33.0, 32.333332, -102.0, 86.0]
05-03 09:03:17.555: I/s represent the lengthof bihua in finNum(832): 319.02507738420815
05-03 09:03:17.555: I/t represent direction of bihua in finNum(832): false
05-03 09:03:17.555: I/a:33.0(832): b:88.2642954110716
05-03 09:03:17.555: I/a:32.333332(832): b:88.22853019034413
05-03 09:03:17.555: I/a:-102.0(832): b:-89.43829466743345
05-03 09:03:17.555: I/a:86.0(832): b:89.33380002981686
05-03 09:03:17.555: I/list1 in findNum(832): [2, 2, 2, 2]
{
ArrayList array = new ArrayList();
float k;
for (int i = 4; i < lists.Count; i += 4)
{
k = (float)(lists[i].y - lists[i - 4].y) / (float)(lists[i].x - lists[i - 4].x);此处k有可能是无穷大,但是无穷大的结果都丢失了
array.Add(k);
}
return array;
}
public ArrayList findNum(ArrayList array , double s, boolean t)//根据斜率判断笔画序列
{
Log.i("array represent slode of bihua in finNum",String.valueOf(array.toString()));
Log.i("s represent the lengthof bihua in finNum",String.valueOf(s));
Log.i("t represent direction of bihua in finNum",String.valueOf(t));
ArrayList bihuaNum=new ArrayList();
int x=1;
for(int i=0;i<array.size();i++)
{
Float a=(Float)array.get(i);
if(s<60)
{
x=9;
}
else
{
double b=Math.atan((double)a)*180/Math.PI;//斜率转换成角度 a有可能为无穷大但结果中 Log.i("a:"+String.valueOf(a),"b:"+String.valueOf(b));
if (b >= 0 && b < 20 || b > 160 && b <= 180)
{
x = 1; //横
}
else if (b > 70 && b < 110)
{
x = 2; //竖
}
else if (b >= 20 && b <= 70)
{
if (!t) //方向向右下
{
x = 4; //捺
}
else //方向向左上
x = 5; //钩
}
else if (b > -70 && b < -20)
{
if (t) //方向向左下
{ Log.i("pie of bihua in finNum",String.valueOf(b));
x = 3; //撇
}
else //方向向右上
x = 6; //提
}
bihuaNum.add(new Integer(x));
}
}Log.i("list1 in findNum",String.valueOf(bihuaNum.toString()));
return bihuaNum;
}
logcat中的部分信息
05-03 09:03:17.515: I/k:y,x: 33(832): 1.0
05-03 09:03:17.515: I/k:y,x: 97(832): 3.0
05-03 09:03:17.515: I/k:y,x: 102(832): -1.0
05-03 09:03:17.515: I/k:y,x: 86(832): 1.0
05-03 09:03:17.545: I/loc in Feature(832): [Point(216, 133), Point(216, 135), Point(216, 146), Point(217, 155), Point(217, 166), Point(218, 183), Point(220, 219), Point(220, 240), Point(220, 263), Point(219, 295), Point(218, 331), Point(219, 358), Point(219, 365), Point(219, 387), Point(219, 419), Point(219, 439), Point(220, 451), Point(220, 452)]
05-03 09:03:17.555: I/alist in Feature and return alist(832): [33.0, 32.333332, -102.0, 86.0]
05-03 09:03:17.555: I/the size of lists in direction(832): 18
05-03 09:03:17.555: I/System.out(832): 216*220
05-03 09:03:17.555: I/c in direction(832): -4
05-03 09:03:17.555: I/in direction(832): false
05-03 09:03:17.555: I/array represent slode of bihua in finNum(832): [33.0, 32.333332, -102.0, 86.0]
05-03 09:03:17.555: I/s represent the lengthof bihua in finNum(832): 319.02507738420815
05-03 09:03:17.555: I/t represent direction of bihua in finNum(832): false
05-03 09:03:17.555: I/a:33.0(832): b:88.2642954110716
05-03 09:03:17.555: I/a:32.333332(832): b:88.22853019034413
05-03 09:03:17.555: I/a:-102.0(832): b:-89.43829466743345
05-03 09:03:17.555: I/a:86.0(832): b:89.33380002981686
05-03 09:03:17.555: I/list1 in findNum(832): [2, 2, 2, 2]
...全文
相关推荐
vb.net求三角函数值
记得在编写代码时,对可能出现的错误进行适当的处理,确保程序的稳定性和健壮性。
浅谈JavaScript中的Math.atan()方法的使用
正切函数的特点是,它的值域没有上限和下限,而是在-∞到+∞之间变化。在JavaScript中,由于没有办法表示无穷大,因此Math.atan()方法将正切值转换成了对应的弧度值。
C 代码 提供各种数学函数的测试值.rar
**atan2(y, x)**:返回二维坐标系中点(x, y)的反正切值,结果介于-pi到pi之间,比单独的**atan(x)**更全面。8.
利用查表法实现反正切值计算角度
利用查表法实现反正切值计算角度,适合那些没有浮点运算功能的单片机
反正切反正弦查表法.rar
本主题聚焦于“反正切反正弦查表法”,它涉及到如何利用预先计算好的表格来快速有效地计算反正切(atan2)和反正弦(asin)函数的值。首先,我们来看反正切函数(atan2)。


