Rotation matrices for yaw, pitch roll system 
(see Goldstein, 2nd Ed.,  p. 609)

RotationMatrixXYZBS[yaw, pitch, roll] gives a rotation matrix which transforms body to space coordinates when used to left multiply a vector. RotateX[roll], RotateY[pitch] and RotateZ[yaw] give the individual components. These are defined righthandedly about the +X, +Y and +Z axes and are applied in roll-pitch-yaw order so the total matrix is equivalent to rotateZ[yaw].rotateY[pitch].rotateX[roll].

BeginPackage["RotationsXYZ`"]

EulerB::usage = "EulerB[yaw_, pitch_, roll_]";
EulerC::usage = "EulerC[yaw_, pitch_, roll_]";
EulerD::usage = "EulerD[yaw_, pitch_, roll_]";

RotationMatrixXYZSB::usage = "RotationMatrixXYZSB[yaw, pitch, roll]";

RotationMatrixXYZBS::usage = "RotationMatrixXYZBS[yaw, pitch, roll]";

RotateX::usage "RotateX[roll]";
RotateY::usage "RotateY[pitch]";
RotateZ::usage "RotateX[yaw]";

Begin["`Private`"]

Partial transformation matrices - set 1: active body to space matrices for rotating vectors.

rotateX[theta_] := {
	{
		1,
		0,
		0
	},
	{
		0,
		Cos[theta],
		-Sin[theta]
	},
	{
		0,
		Sin[theta],
		Cos[theta]
	}
};

rotateY[theta_] := {
	{
		Cos[theta],
		0,
		Sin[theta]
	},
	{
		0,
		1,
		0
	},
	{
		-Sin[theta],
		0,
		Cos[theta]
	}
};

rotateZ[theta_] := {
	{
		Cos[theta],
		-Sin[theta],
		0
	},
	{
		Sin[theta],
		Cos[theta],
		0
	},
	{
		0,
		0,
		1
	}
};

Partial transformation matrices - set 2: passive (space to body) matrices.

EulerB[yaw_, pitch_, roll_] := {
	{
	1,
	0,
	0
	},
	{
	0,
	Cos[roll],
	Sin[roll]
	},
	{
	0,
	-Sin[roll],
	Cos[roll]
	}
}

EulerC[yaw_, pitch_, roll_] := {
	{
	Cos[pitch],
	0,
	-Sin[pitch]
	},
	{
	0,
	1,
	0
	},
	{
	Sin[pitch],
	0,
	Cos[pitch]
	}
}

EulerD[yaw_, pitch_, roll_] := {
	{
	Cos[yaw],
	Sin[yaw],
	0
	},
	{
	-Sin[yaw],
	Cos[yaw],
	0
	},
	{
	0,
	0,
	1
	}
}

General transformation from space coordinates to body coordinates

RotationMatrixXYZSB[yaw_, pitch_, roll_] = EulerB[yaw, pitch, roll].EulerC[yaw, pitch, roll].EulerD[yaw, pitch, roll]

General transformation from body coordinates to space coordinates

RotationMatrixXYZBS[yaw_, pitch_, roll_] = Transpose[RotationMatrixXYZSB[yaw, pitch, roll]]

End[]   (* Graphics`Shapes`Private` *)

EndPackage[]   (* Graphics`Shapes` *)