首页 > 解决方案 > 获取线和x轴之间的角度(屏幕的水平顶部)

问题描述

我创建了一个使用图形上下文绘制形状的基本程序。线对象拥有自己的起点和终点。我希望在构建 java 时使用标准的第一象限值。

我试图创建Point2D给我错误值的对象。我也尝试过arctan2arctan,无论我通过哪一行,它们都会返回相同的值。无论是我的代码还是我的数学,我都找不到我的错误。任何建议将不胜感激。

double slope = (this.getEndY() - this.getyCoordinate()) / (this.getEndX() - this.getxCoordinate());
return MyLine.description + Math.toDegrees(Math.atan(slope));

this is using the Point2D with three points:
        Point2D point = new Point2D(1, 0); // x- axis
        Point2D point1 = new Point2D(this.getxCoordinate(),this.getyCoordinate()); //p1(0,0)
        Point2D point2 = new Point2D(this.endX,this.getEndY());//p2(bottom right corner of window)
        double angle = point1.angle(point, point2);
        return MyLine.description + " " + angle;

第一次尝试是我在已经返回的站点上找到的解决方案NaN。第二个是对我们返回 0.0 的 Point2d API 的尝试。我期待它读取 45.0。

标签: javafx-8

解决方案


推荐阅读