找到与枢轴相关的点的角度 [英] find the angle of point related to pivot
问题描述
已经有几天我在做一个项目,我必须在其中使用凸包,以及特定的graham扫描方法.问题一直解决到我要对点进行排序为止. 故事就是我从Point类型中收集了一堆点,它们的坐标是亲戚.意味着它们来自鼠标事件x和y.因此,我收集了鼠标位置作为点的x和y.我想找到与枢轴点有关的角度.有人有一段代码可以计算该角度吗? 非常感谢,下面的图片是我需要的:
It’s been days that I’m working on a project which I have to use convex hull in it, and specific method of graham scan. The problem has been solved till the place I want to sort the points. So the story is that I have collected bunch of points which they are from the type Point and their coordinates are relatives. Mean they come from the mouse event x and y. So I have collected the mouse positions as x and y of the points. And I want to find the angle related to the pivot point. Does anyone have a piece of code to calculate that angle? Many and many thanks, the image below is what I need:
推荐答案
使用
Math.atan2(dy, dx)
其中dy
和dx
代表该点和枢轴点之间的垂直和水平差.
where dy
and dx
represent the vertical and horizontal difference between the point and pivot point.
一些注意事项:
-
参考(0弧度)按惯例是指向右侧,而不是图像中的左侧.如果您真的想从左侧进行测量,则必须执行
Math.PI - angle
进行转换.
Math
-三角函数以弧度工作.要将结果转换为度,可以使用Math.toDegrees
.
The Math
-trigonometry functions work in radians. To convert the results to degrees, you can use Math.toDegrees
.
在数学世界中,增大的y值指向上方.在您的图像中,它们的指向下方.
In the mathematical world, increasing y-values point upwards. In your image, their pointing downwards.
这篇关于找到与枢轴相关的点的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!