Click here to Skip to main content
15,947,476 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.How do I find angle between two pixcels...
austinbox 29-Jan-14 11:29am    
Well if you want the angle between the two pixels you can use Math.atan2.
For example:

double angleInDegrees = Math.Atan2(pix2.y - pix1.y, pix2.x - pix1.x) * (180 / Math.PI);
Adam Zgagacz 29-Jan-14 11:31am    
Can you be more specific? Pixel as most people understand it is a dot/point. I dont see what could be an angle in this case. How do you define an angel beteen two pixels?

Point p1 = new Point(100, 100);
Point p2 = new Point(150, 50);
double radians = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X);
Share this answer
Rahul VB 29-Jan-14 12:27pm    
that great OG, how have you been?
OriginalGriff 29-Jan-14 13:55pm    
Not too bad - a little disappointed with tonights food, was a new recipe, and I won't do it again! I did wonder just how risotto was going to work in the Sous Vide and now I know. Not so much "risotto" as "chicken, mushroom and rice soup". :sigh:
Rahul VB 29-Jan-14 21:17pm    
great i just had some chapattis with Egg curry. Its cold here, dint feel like going out. Other wise i thought of getting some wine too. But never the less, we always have week ends to full fill our dreams. :) hahah
Google is your friend ;)
There is a lot of resources about that online.
For example :[^]
Share this answer
That makes no sense : there is no angle between two pixels.
You need at least 3 pixels, which could define two segments; you can then measure an angle between these segments.

Please clarify your question.
Share this answer
OriginalGriff 29-Jan-14 11:35am    
Think in terms of two pixels on a bitmap: they both have an X and Y coordinate, so they have a relative angle within the framework:
If one is (0,0) and the other is (100,100) then the angle is at 45 degrees to the baseline X and Y axes.
phil.o 29-Jan-14 11:45am    
Maybe I remind too much about my mathematics courses :)
Or maybe I just do not like making assumptions about OP's needs. Here the 45° example is working; but what about (0,0) and (87,134)? Does he want the angle with X or Y axis? As they clearly cannot equal each other.

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