javafx-8 - 获取线和x轴之间的角度(屏幕的水平顶部)
问题描述
我创建了一个使用图形上下文绘制形状的基本程序。线对象拥有自己的起点和终点。我希望在构建 java 时使用标准的第一象限值。
我试图创建Point2D
给我错误值的对象。我也尝试过arctan2和arctan,无论我通过哪一行,它们都会返回相同的值。无论是我的代码还是我的数学,我都找不到我的错误。任何建议将不胜感激。
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。
解决方案
推荐阅读
- python - 从不同层次结构中导入 Python 模块
- spring - 覆盖托管版本 json maven 依赖项
- excel - excel SUMIFS,两行有 3 个条件
- php - 显示自定义会话的 SweetAlert?
- android - 从 RecyclerView 检索数据
- laravel - 如何在 Laravel-Vue.js 应用中使用 Storybook
- javascript - 将本机 UI 集成到本机反应中?
- javascript - Function to show/hide menu not working in iOS
- angular - Angular:直接导入 json 文件在生产构建中不起作用
- django - Django 2 systemd/journalctl runserver 日志未按预期工作