急 急 急 ~~~j2me 中物体圆形移动

来源:百度知道 编辑:UC知道 时间:2024/05/10 11:36:38
public class Math {

static int data[] = {
0, 286, 572, 857, 1143, 1428, 1713, 1997, 2280, 2563,
2845, 3126, 3406, 3686, 3964, 4240, 4516, 4790, 5063,
5334,
5604, 5872, 6138, 6402, 6664, 6924, 7182, 7438, 7692,
7943,
8192, 8438, 8682, 8923, 9162, 9397, 9630, 9860, 10087,
10311,
10531, 10749, 10963, 11174, 11381, 11585, 11786, 11982,
12176, 12365,
12551, 12733, 12911, 13085, 13255, 13421, 13583, 13741,
13894, 14044,
14189, 14330, 14466, 14598, 14726, 14849, 14968, 15082,
15191, 15296,
15396, 15491, 15582, 15668, 15749, 15826, 15897, 15964,
16026,

Math.sqrt() 是J2SE中求平方根的函数,J2ME没有的话,写个小循环,在0~r之间循环100次,比较x*x+y*y和r*r, 找个最接近的近似值就可以了。

>>>>>>
得,是我xiang错了。馊主意。允许不允许用Math库?看下面的源码,getCoordinates给你返回360个坐标(TestCircle.Coordinate类):

public class TestCircle {

public double radius = 100; // the radius of the circle.

public Coordinate[] getCoordinates() {
// set steps=360 to get 360 coordinates
Coordinate[] result = new Coordinate[360];

// starting from right-most point (r,0)
double xCurrent = radius;
double yCurrent = 0;
double delta = radius/90;//each move on x-axis

for (int i = 0; i < 360; i++) {
//control direction (counter-clock)
int xFactor = (i < 180 ? -1 : 1);
int yFactor = (i < 180 ? 1 : -1);

xCurrent = xCurrent + xFactor * delta;
yCurrent = yFactor * getY(xCurrent, radius);

Coordinate thisCoordinate = new Coordinate(xCurrent, yCurrent);