C# Vector maths questions

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-04-22T05:25:06Z Indexed on 2010/04/22 5:33 UTC
Read the original article Hit count: 289

Filed under:
|
|

Im working in a screen coordinate space that is different to that of the classical X/Y coordinate space, where my Y direction goes down in the positive instead of up.

Im also trying to figure out how to make a Circle on my screen always face away from the center point of the screen.

If the center point of my screen is at x(200) y(300) and the point of my circle's center is at x(150) and y(380) then I would like to calculate the angle that the circle should be facing.

At the moment I have this:

        Point centerPoint = new Point(200, 300);
        Point middleBottom = new Point(200, 400);

        Vector middleVector = new Vector(centerPoint.X - middleBottom.X, centerPoint.Y - middleBottom.Y);

        Vector vectorOfCircle = new Vector(centerPoint.X - 150, centerPoint.Y - 400);

        middleVector.Normalize();
        vectorOfCircle.Normalize();

        var angle = Math.Acos(Vector.CrossProduct(vectorOfCircle, middleVector));

        Console.WriteLine("Angle: {0}", angle * (180/Math.PI));

Im not getting what I would expect.

I would say that when I enter in x(150) and y(300) of my circle, I would expect to see the rotation of 90 deg, but Im not getting that... Im getting 180!!

Any help here would be greatly appreciated.

Cheers, Mark

© Stack Overflow or respective owner

Related posts about c#

Related posts about maths