gpt4 book ai didi

math - 在 Blackberry 4.2 JDE 上调用 atan 函数

转载 作者:行者123 更新时间:2023-12-02 07:54:54 26 4
gpt4 key购买 nike

我需要从我的 Blackberry Java 应用程序计算反正切值。不幸的是,黑莓 4.2 api 没有 Math.atan() 函数。 Blackberry JDE 的 4.6 版有它,但 4.2 版没有。

有人知道计算 atan 的解决方法吗?

最佳答案

来自 Arctan in J2ME by Stephen Zimmerman :

// 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;
}
}

关于math - 在 Blackberry 4.2 JDE 上调用 atan 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1455292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com