I'm trying to use some matrix library (for example) to find the roll and then pitch rotations needed for a specific Euler vector.
For example, starting at [0,0,0] (roll, pitch, yaw) then rotating [45,0,0] and then [0,45,0] yields [54.735610,30.000000,35.264390]. With that library it's simply multiplying the two quaternions derived from these two Euler rotations.
When only given [54.735610,30.000000,35.264390] (or corresponding quaternion) - how can I calculate the required roll and pitch rotations? or in other words x and y in [0,x,0] and [y,0,0].
Thanks.
EDIT: I'm sorry if it wasn't clear, but I'm trying to find the roll-only+pitch-only rotations applied on [0,0,0] to result in that or any other specific attitude.
With the Tait-Bryan angles (or any other form of Euler angles) there are problems with multiple conventions over axes and order of rotations, whether the transformation is active (relative to fixed axes) or passive (coordinates relative to rotating coordinate axes), whether the rotation is about extrinsic (fixed) or intrinsic (body-fitted) axes. There are also degenerate/multiple-solution cases arising from geometry on a sphere.
The OP's code samples are based on active rotations about intrinsic axes, but his rotation order is not the more usual one.
Case 1: yaw about z, followed by pitch about y, followed by roll about x.
(This is the more usual case, at least in flight, but it is not what the OP is using.)
Thinking first about the corresponding passive transformations (change of coordinate axes) and then transposing back to get the active transformations, the rotation matrix R is
(XTYTZT)T=Z(z)Y(y)X(x)
which works out as https://i.sstatic.net/jbnSh.png from which you can - in most cases - pick off the original Tait-Bryan angles:
roll(x)=atan2(R32,R33)
pitch(y)=asin(-R31)
yaw(z)=atan2(R21,R11)
(The matrix indices R11, R12 etc. are 1-based here.)
The exception is when cos(y)=0 - gimbal lock - when roll and yaw must be picked off (non-uniquely) from the other terms in the matrix. Of course, at this point the pitch angle will be plus or minus 90 degrees and the passengers in the aircraft will be a little unhappy with the pilot.
Case 2: roll about x, followed by pitch about y, followed by yaw about z.
(This is actually what the OP is using (from his code snippet), but it is not the more common case.)
(ZTYTXT)T=X(x)Y(y)Z(z)
The rotation matrix R is given by https://i.sstatic.net/XLN21.png from which you can - again, in most cases - pick off the Tait-Bryan angles:
roll(x)=atan2(-R23,R33)
pitch(y)=asin(R13)
yaw(z)=atan2(-R12,R11)
If the order of rotations is different then you will have to adapt your matrix and formulae accordingly.
Some useful things about rotation matrices:
Personally, I don't use Euler angles or quaternions much. I would usually deal either with the rotation matrix or the mappings of the unit vectors (which form the columns of the rotation matrix, anyway).