# Math 3D: how rotate the 3D vectors?

```Private Function ConvertDegreesToRadians(Rotation As Angle3D) As Angle3D    Dim deg2Rad As Double     deg2Rad = Pi / 180         ConvertDegreesToRadians.X = Rotation.X * deg2Rad     ConvertDegreesToRadians.Y = Rotation.Y * deg2Rad     ConvertDegreesToRadians.Z = Rotation.Z * deg2Rad End Function Private Function Rotate(Position As Position3D, Rotation As Angle3D, PositionRotated As Position3D) As Position3D     Dim ConvertedPosition As Position3D     Dim RotationInRads As Angle3D         'Convert degrees to Radians     'Rotation works on Radians     RotationInRads = ConvertDegreesToRadians(Rotation)         'Convert the actual position to zero or player position, using the rotation position:     ConvertedPosition = Position     ConvertedPosition.X = Position.X - PositionRotated.X     ConvertedPosition.Y = -(PositionRotated.Y - Position.Y)  'reversed because Y increments down     ConvertedPosition.Z = Position.Z - PositionRotated.Z             'Rotate the position, but the Z axis must be the 1st:     Dim T As Position3D         'Z axis  (Roll)     T = ConvertedPosition         ConvertedPosition.X = T.X * Cos(RotationInRads.Z) - T.Y * Sin(RotationInRads.Z)         ConvertedPosition.Y = T.X * Sin(RotationInRads.Z) + T.Y * Cos(RotationInRads.Z)         'X axis  (Pitch)     T = ConvertedPosition         ConvertedPosition.Y = T.Y * Cos(RotationInRads.X) - T.Z * Sin(RotationInRads.X)         ConvertedPosition.Z = T.Y * Sin(RotationInRads.X) + T.Z * Cos(RotationInRads.X)       'Y axis  (Yaw)     T = ConvertedPosition         ConvertedPosition.X = T.Z * Sin(RotationInRads.Y) + T.X * Cos(RotationInRads.Y)         ConvertedPosition.Z = T.Z * Cos(RotationInRads.Y) - T.X * Sin(RotationInRads.Y)                 'Convert to the rotated original position:         ConvertedPosition.X = ConvertedPosition.X + PositionRotated.X         ConvertedPosition.Y = ConvertedPosition.Y + PositionRotated.Y         ConvertedPosition.Z = ConvertedPosition.Z + PositionRotated.Z                 'Convert to Camera Coordinates\Position:         'ConvertedPosition.X = ConvertedPosition.X + camera1.Position.X         'ConvertedPosition.Y = ConvertedPosition.Y + camera1.Position.Y         'ConvertedPosition.Z = ConvertedPosition.Z + camera1.Position.Z             Rotate = ConvertedPosition End Function```