I have been trying to create the model of a drone for fun and when calculating the linear dynamics I need to find out the Z component of the thrust vector.
Basically, in 3D space the thrust vector is always perpendicular to my drone, hence its angle and therefore z component changes with the pitch and the roll of the drone. Pitch is the angle about the x axis and roll is the angle about the y axis with $ 0$ degrees being the vector pointing straight up.
I also know the total magnitude of the thrust vector, basically the total thrust generated by my drone. From there I can easily get the thrust vectors' components in the x and y directions by multiplying the vector's magnitude to, respectively, sin(roll) and sin(pitch).
What I have been doing until now is then using the magnitude to write that: $$M^2=X^2+Y^2+Z^2$$ with M being the magnitude and X, Y Z the components of the thrust vector. From this I rewrote,
$$Z=\sqrt{M^2-X^2-Y^2}$$
Again here: $$X=sin(roll)*M$$ and $$Y=sin(pitch)*M$$ with roll the angle about the y axis and pitch the angle about the X axis.
The problem is that this fails in a lot of cases as $M^2-X^2-Y^2$ becomes negative. I am sure I did something basic pretty wrong here but I cannot get my head around it, I would greatly appreciate your help if anyone knows what I am doing wrong.
Thank you!