0

 我们如何将 Int 值转换为角度。

 int speed = remoteService.getSpeed();

我从远程服务获取速度值,我想将其转换为角度。

我怎样才能做到这一点?任何想法?

4

2 回答 2

2

public void getGenginePos(int state,float force, double AOD){ double AODrad=(AOD*0.017444);

   switch(state){
       case BOAT_IDLE:
                //System.out.println("Before Vx = " + vx + ", vy = " + vy + ", f = " + force + ", AOD = " + AOD);
                vx = (float)(force * Math.cos(AODrad));
                px = px + (vx * dt);
                vy = (float) (force * Math.sin(AODrad));
                //System.out.println("After Vx = " + vx + ", vy = " + vy);

                py = py - (vy * dt);

                break;
        case BOAT_ACCEL:
                temp = force *dt;
                vx = (float) (force * Math.cos(AODrad) + temp);//(force * dt));
                vy = (float) (force * Math.sin(AODrad) + temp);//(force * dt));
                px = px + (vx * dt);
                py = py - (vy * dt);
                break;
        case BOAT_DECEL:
                temp = force *dt;
                vx = (float) (force * Math.cos(AODrad) - temp);//(force * dt));
                vy = (float) (force * Math.sin(AODrad) - temp);//(force * dt));
                px = px + (vx * dt);
                py = py - (vy * dt);
                break;
       default: break;

   }
}

public void setMeterPos(int rpx,int rpy,int epx,int epy){
   RefX= rpx;
   RefY= rpy;

   EndX = epx;
   EndY = epy;

   screenwidth=BoatRider.screenWidth;
   screenheight=BoatRider.screenHeight;
}

public void setArrowEndX(int x){
    EndX = x;
}
public void setArrowEndY(int y){
    EndY = y;
}
public float getArrowEndX(){
    return EndX;
}

public float getArrowEndY(){
    return EndY;
}

public void getGMeterArrowPos(double AOD,float radius){
    double AODrad=(AOD*0.017444);
    vx=(float)(radius*Math.cos(AODrad));
    vy=(float)(radius*Math.sin(AODrad));

    float height=screenheight-RefY;

    EndX = vx+RefX;
    EndY=screenheight-(vy+height);

}

public float getBorderEndX(){
   return EndX;
}
public float getBorderEndY(){
    return EndY;
}
public void getGBoatBorderPos(double AOD,float radius,float boderRefX,float boderRefY){
    double AODrad=(AOD*0.017444);
    vx=(float)(radius*Math.cos(AODrad));
    vy=(float)(radius*Math.sin(AODrad));

    float height=screenheight-boderRefY;

    EndX = vx+boderRefX;
    EndY=screenheight-(vy+height);

}

} 这将非常有用

于 2012-07-31T05:46:07.970 回答
1
int speed = 90;
double degrees = speed ;
double angle = degrees * 2 * Math.PI / 360.0;

或者你可以使用

int speed = 30;
 double degrees = speed;
 double toDegree = Math.toDegrees(radians);
于 2012-07-31T05:49:09.870 回答