Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 7-Jun-19 3:51am

Suppose you have
     -------------------------------------

|                     P2={X2,Y2}
|                   /
|                  /
|                 /
|                /
|               /
|              /  alpha
|             / .............
|              P1={X1,Y1}
|


Then math.atan2(Y2-Y1,X2-X1) gives you the alpha angle. All the other ones are then simply computed.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Apr-14 2:05am    
5ed. :-)
—SA
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:
 
Share this answer
 
Comments
Zhivko Kabaivanov 13-Mar-14 7:46am    
No I am 24.
OriginalGriff 13-Mar-14 8:06am    
I didn;'t say you weren't: I said they taught you this stuff 12 years ago, when you were 12! :laugh:
Zhivko Kabaivanov 13-Mar-14 8:29am    
Arc cos in 5th grade, are you serious ?!
OriginalGriff 13-Mar-14 8:38am    
You mean you didn't get that?
What do they teach you then, these days? :laugh:
Zhivko Kabaivanov 13-Mar-14 9:25am    
http://translate.google.com/translate?hl=en&sl=auto&tl=en&u=http%3A%2F%2Fwww.bgtest.eu%2F%3Ff%3Dtest%26test_id%3D46

This is a test for 5th grade students.
This works perfectly for me

const double Rad2Deg = 180.0 / Math.PI;
const double Deg2Rad = Math.PI / 180.0;

/// <summary>
/// Calculates angle in radians between two points and x-axis.
/// </summary>
private double Angle(Point start, Point end)
{
    return Math.Atan2(start.Y - end.Y, end.X - start.X) * Rad2Deg;
}
 
Share this answer
 
Comments
Richard Deeming 7-Jun-19 14:14pm    
Using Atan2 was already explained in solution 1, back in 2014.

And your method doesn't match its own comments. The comments claim the return value is in radians, but the return value is in degrees.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900