在BlackBerry JDE 4.2 ATAN调用函数 [英] Calling atan function on Blackberry 4.2 JDE

查看:148
本文介绍了在BlackBerry JDE 4.2 ATAN调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的黑莓的Java应用程序计算反正切值。不幸的是,黑莓4.2 API不具备Math.atan()函数。天知道为什么,但是这就是黑莓API为您服务。黑莓JDE的4.6版本有它,而不是4.2。

I need to calculate the arc tan value from my Blackberry Java app. Unfortunately, the blackberry 4.2 api doesn't have the Math.atan() function. Heaven knows why, but that's the Blackberry API for you. Version 4.6 of the Blackberry JDE has it, but not 4.2.

有谁知道一个解决方法来计算反正切?

Does anyone know of a workaround to calculate atan?

推荐答案

从的反正切由斯蒂芬·齐默尔曼 J2ME:

// calculation functions
public class Calculation {

    // Because J2ME has no floating point numbers,
    // some sort of fixed point math is required.
    // My implementation is simply to shift 10 places.
    // for example, 1024 (>> 10) = 1
    // and 512 (>> 10) = 0.5


public static final int[] AtanTable = { 0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12,
    		13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 
    		30, 30,31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 40, 41, 
    		42, 43, 43, 44, 45 };

    // / returns angle 0->359 in degrees
    public static int atan(int Y, int X) {
    	boolean swap = false;

    	int top = Math.abs(Y);
    	int bottom = Math.abs(X);
    	if (top > bottom) {
    		int btemp = bottom;
    		bottom = top;
    		top = btemp;
    		swap = true;
    	} else if (bottom == 0)
    		return -300;

    	// this should keep index inbounds [0, 45]
    	int index = (top * 45) / bottom;
    	int angle = AtanTable[index];

    	if (swap)
    		angle = 90 - angle;

    	// X & Y += 180
    	// X & !Y = ...90
    	// !X & Y = ... 270
    	if ((X < 0) && (Y < 0))
    		angle += 180;
    	else if (Y < 0) {
    		angle = 90 - angle;
    		angle += 270;
    	} else if (X < 0) {
    		angle = 90 - angle;
    		angle += 90;
    	}

    	if (angle == 360)
    		angle = 0;

    	return angle;
    }
}

这篇关于在BlackBerry JDE 4.2 ATAN调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆