有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java炮弹游戏数学

我必须用Java编写一个使用以下数学公式的游戏:

x = x1 + vt(cos(theta))
y = y1 - vt(sin(theta)) – 0.5gt2

模拟从地面“发射”的对象的运动。保存在名为“佳能游戏”的文件夹中。 问题是任何与数学有关的事情。。。。它不起作用

// The "Cannongame" class.
import java.awt.*;
import hsa.Console;
import java.lang.Math;

public class Cannongame
{

 static Console c;       // The output console

    public static void main (String[] args)
    {
        c = new Console ();
        c.println("Enter intial angle(0-90): ");
        c.println("Enter velocity(10-40): ");

        c.fillRoundRect(50,125,80,25,20,50); 
        c.fillRect(70,103,30,25);
        c.fillRect(100,105,60,15);
        double xreal, yreal, v;
        double the,theta;
        long x,y;
        v = c.readInt();
        the = c.readInt();
        theta = (the * 0.017453292);
        double cos = Math.cos(Math.toRadians(v)); 
        double sin = Math.sin(Math.toRadians(v));  
        for (int  t = 1; t <= 100; t++)
        {
            xreal = 100+(v*t*cos(theta));
            yreal = 200-(v*t*sin(theta)-0.5*1*t*t);
            x = Math.round(xreal);
            y = Math.round(yreal);
            c.setColor (Color.black);
            c.fillOval(x, y, 5, 5);
        }
        // Place your program here.  'c' is the output console
    } // main method
} // Cannongame class

共 (1) 个答案

  1. # 1 楼答案

    对于所有角度,请尝试使用:

    Math.toDegrees(yourAngle);

    在这里,你期望有规则的“度”角。正常的sin、cos、tan函数以java返回弧度表示