simple rotation

Last post 05-09-2008, 1:39 PM by Lord Ikon. 4 replies.
Sort Posts: Previous Next
  •  05-08-2008, 3:55 PM

    simple rotation

    Here is my problem:

    I have two points, like so:

    Vector2 point1;
    Vector2 point2;

    point1.X = 10;
    point1.Y = 10;
    point2.X = 20;
    point2.Y = 20;

    what i need is a function to rotate point1 any given amount of degrees around point2.

    It is really a simple problem, but i am new to this and just dont know how to do it.

  •  05-09-2008, 1:26 AM

    Re: simple rotation

  •  05-09-2008, 2:38 AM

    Re: simple rotation

    /// <summary>
    /// Translates a point around an origin
    /// </summary>
    /// <param name="point">Point that is going to be translated</param>
    /// <param name="originPoint">Origin of rotation</param>
    /// <param name="rotationAxis">Axis to rotate around</param>
    /// <param name="radiansToRotate">Radians to rotate</param>
    /// <returns>Translated point</returns>
    public static Vector3 RotateAroundPoint(Vector3 point, Vector3 originPoint, Vector3 rotationAxis, float radiansToRotate)
    {
    Vector3 rotatedVect = Vector3.Transform(point, Matrix.CreateFromAxisAngle(rotationAxis, radiansToRotate));

    rotatedVect -= originPoint;


    return rotatedVect;
    }

    This should work in 2D by changing the vector3s to vector2s. Although I haven't tried it in 2D yet. Your axis for rotation would likely just be Vector2.UnitY every time. Although, like I said, I've never tried this stuff in 2D.

    EDIT: Oh, and the guy above me is right. The stuff on that page is what is occuring above, only much simpler (to most).


    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
  •  05-09-2008, 8:29 AM

    Re: simple rotation

    ok thanks alot. hopefully this will work   ;-)
  •  05-09-2008, 1:39 PM

    Re: simple rotation

    I believe I might have made an error, this one may work if the other doesn't:

    public Vector3 RotateAroundPoint(Vector3 point, Vector3 originPoint, Vector3 rotationAxis, float radiansToRotate)
    {
    Vector3 diffVect = point - originPoint;

    Vector3 rotatedVect = Vector3.Transform(diffVect, Matrix.CreateFromAxisAngle(rotationAxis, radiansToRotate));

    rotatedVect += originPoint;

    return rotatedVect;
    }

    XNA QuickStart Engine | My site
    "I'll be whatever I want to do!", Philip J. Fry
View as RSS news feed in XML
©2007 Microsoft Corporation. All rights reserved. Privacy Statement Terms of Use Code of Conduct Feedback