反正切函数中正切值可能是无穷大结果丢失
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]
你至少应该把无穷大的情况单独拿出来看看,确定是不是有问题。把一个地方造成的错误误认为是另外一个地方造成的是很常见的情况。浮点数计算都是按国际标准走的,这个不太可能出问题。
|