我的最后一个问题涉及正确的语法,这个问题是:
我应该如何最好地展示2点之间的线的3D表示?我已经计算了斜率,现在我只想制作一个窗口并显示如下的立方体:http://www.wolframalpha.com/input/?i=slope+between+%282%2C6%2C1%29+and+%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);
}
答案 0 :(得分:0)
这是一个大问题,你将不得不使用一些第三方库来获取3D图形,因为java本身并不支持它*。我建议你看一下jmonkey引擎,但这只是我的个人偏好:http://jmonkeyengine.com/。
*从技术上讲java3D确实存在,但它仍然没有附带java作为标准,它是一个很大程度上被遗弃的项目