How To: Transform a Point with a Matrix

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 the topic shows you the technique. You can download a complete code sample for this topic, including full source code and any additional supporting files required by the sample.

Transforming a Point with a Matrix

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

© 2016 Microsoft