如何根据XY坐标计算旋转角度? [英] How to calculate angle of rotation based on XY coordinates?
本文介绍了如何根据XY坐标计算旋转角度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一种用于计算旋转角度的图像处理方法。我为获得每个边框像素的X和Y坐标做了另一个。
我需要一些指示我可以开始。
Exmaple image
我想找出图像的问号角度来计算它,但我还无法找出任何东西。
有些代码会很好。
解决方案
假设你有
--- ----------------------------------
| P2 = {X2,Y2}
| /
| /
| /
| /
| /
| / alpha
| / .............
| P1 = {X1,Y1}
|
然后math.atan2(Y2-Y1,X2-X1)
为您提供alpha
角度。然后简单计算所有其他的。
如果你有每个边框的X和Y,那么你就得到了构成正方形的四条线中每条线的X和Y.
因此计算角度很简单:学校级几何学。
取一个角度 - 在你的例子的右上角。
你知道作为方形一部分的线的坐标:P1和P2,所以你知道X坐标的差异:P2.X - P1.X
这允许你制作一个直角三角形,你知道斜边(从P1和P2的毕达哥拉斯)和相邻的线长度(X合作的差异)。
所以你可以锻炼角度简单:
Theta = Cos -1 (A / H)
当你是什么时,你在数学课上涵盖了所有这些? 12? :笑:
I am making a image processing method for calculating the angle of rotation. I made another for getting the X and Y coordinates of each border pixel.
I need some directions where I can start.
Exmaple image
I want to find out the question mark angles of the image to calculate it but I cant figure out anything yet.
Some code will be nice.
解决方案
Suppose you have
------------------------------------- | P2={X2,Y2} | / | / | / | / | / | / alpha | / ............. | P1={X1,Y1} |
Thenmath.atan2(Y2-Y1,X2-X1)
gives you thealpha
angle. All the other ones are then simply computed.
If you have the X and Y of each border, then you have the X and Y of each of the four lines that makes up the square.
So working out the angle is easy: school level geometry.
Take one of the angles - the top right in your example.
You know the coordinates of the line that is part of the square: P1, and P2, so you know the difference in X coordinates: P2.X - P1.X
That allows you to make a right angle triangle, where you know the Hypotenuse (from Pythagoras on P1 and P2) and Adjacent line lengths ( the difference in X co-ords).
So you can work out the angle simply:
Theta = Cos-1(A/H)
You covered all this in Maths class when you were what? 12? :laugh:
这篇关于如何根据XY坐标计算旋转角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文