Export (0) Print
Expand All

How To: Transform a Point with a Matrix

This example demonstrates how to use the Vector3 and Matrix classes to transform a point.

The Complete Sample

The code in this tutorial illustrates the technique described in the text. A complete code sample for this tutorial is available for you to download, including full source code and any additional supporting files required by the sample.

To transform a point

  1. Create a Matrix by using CreateRotationY or one of the other Create methods.
  2. Pass the point and the Matrix to the Vector3.Transform method.
static Vector3 RotatePointOnYAxis(Vector3 point, float angle)
{
    // Create a rotation matrix that represents a rotation of angle radians.
    Matrix rotationMatrix = Matrix.CreateRotationY(angle);

    // Apply the rotation matrix to the point.
    Vector3 rotatedPoint = Vector3.Transform(point, rotationMatrix);

    return rotatedPoint;
}

Community Additions

ADD
Show:
© 2014 Microsoft