开发者

Calculating angle (in degrees) from pixel values

For instance I click and drag a line directly to the left, that would be about 270 degrees, directly bottom would be 180 degrees dragging to the north east would be 45 and 开发者_开发技巧so forth. I want to display the exact value in degrees.

I am using 2D graphics in WPF (very new to this). I can see that it's pixels start at the top left corner of the screen (0,0) and increase x towards the right and y towards the bottom.

I have the code to calculate angles for two points in the x,y coordinate system, but I'm not sure how to achieve this in WPF.

If you guys can give me some ideas it would be very helpful.


    Point start;
    Point endPoint;
    Canvas canvas;  //or whatever control the user is clicking
    private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //The start of the user dragging
        start = e.GetPosition(canvas)
    }
    private void canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        //The user is done dragging, calculate angle
        endPoint = e.GetPosition(canvas)
        //Do whatever you want with start and end
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜