0

我的最后一个问题涉及正确使用语法,这个问题是:

我应该如何最好地显示 2 点之间的线的 3D 表示?我已经计算了斜率,现在我只想让一个窗口出现并显示一个像这样的立方体:http ://www.wolframalpha.com/input/?i=slope+between+%282%2C6%2C1%29+和+%283%2C5%2C0%29

        public static double calcSlope(Point p1, Point p2){
        //math to calculate the slope
        double slope1 = (p2.getY()- p1.getY())/(p2.getX()-p1.getX());
        double angle1 = Math.atan(slope1);
        double distance1 = (p2.getY()-p1.getY())/Math.sin(angle1);
        System.out.println("distance: " + distance1);

        double slopeFinal = 1/distance1;

        return slopeFinal;
    }

    public static void main(String[]args){

        double x1, x2, y1, y2, z1, z2;

        x1 = 5;
        x2 = 7.5;
        y1 = 3.25;
        y2 = 4;
        z1 = 0;
        z2 = 1;

        Point point1 = new Point(x1, y1, z1);
        //declaring new variables of class Point
        Point point2 = new Point(x2, y2, z2);
        //in Point y2 is = y, but y1 is also = y Point (x,y,z) serves as a placeholder where "x" is just
        //a placeholder

        double slope = calcSlope(point1, point2);
        double angle = Math.atan(slope);

        System.out.println("Your Slope is " + slope);
        System.out.println("Angle of entry is " + angle);
    }
4

1 回答 1

0

这是一个很大的问题,您将不得不使用一些 3D 图形库,因为 Java 本身并不支持它*。我建议您查看 jmonkey 引擎,但这只是我个人的偏好:http: //jmonkeyengine.com/

*从技术上讲,java3D 确实存在,但它仍然没有以 java 作为标准,而且它是一个很大程度上被废弃的项目

于 2013-05-01T14:25:20.660 回答