1

What mathematical formula can I use to rotate a series of 3d Vectors about a given 3d Vector?

I am attempting to use the 3rd party library: Math.NET Iridium to calculate my rotations but I dont know what formulas or mathematical concepts I should use. As you can see Maths is not my strong point thus the need for the library.

PS: I've attempted to use the standard System.Windows.Shapes.Polyline and System.Windows.Media.RotateTransform but it looks like the rotation is only applied at rendering time (correct me if I am wrong). I need to know the location of the rotated point right after I apply the RotateTransform.

public static XYZ rotateXYZ(XYZ pnt)
{
    Polyline polyline = new Polyline();
    polyline.Points.Add(new Point(pnt.X, pnt.Y)); //, pnt.Z));
    System.Windows.Media.RotateTransform rotateTransform = new System.Windows.Media.RotateTransform(projectRotation, pnt.X, pnt.Y);
    polyline.RenderTransform = rotateTransform;
    return new XYZ(polyline.Points[0].X, polyline.Points[0].Y, pnt.Z); // the points coordinates are the same - not rotated
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
sazr
  • 24,984
  • 66
  • 194
  • 362

1 Answers1

2

See Rotation Matrix for the mathematical background/formula, section "Rotation matrix from axis and angle".

If you'd like to use a library: Math.NET Iridium (and its successor Math.NET Numerics) are numerical methods libraries, but you could use Math.NET Spatial instead.

var point = new Point3D(1,1,1);
var vector = new Vector3D(0,0,1);

// will have coordinates (-1,-1,1)
var rotated = point.Rotate(vector, Angle.FromDegrees(180));

Note that Math.NET Spatial is in a very early phase, so there is no release or NuGet package yet. But you can compile it yourself, or simply have a look at the code to see how it was implemented.

Christoph Rüegg
  • 4,626
  • 1
  • 20
  • 34