# How should I implement the 3-parameter vector quaternion to represent the rotation?

Since unit quaternion q=q0+qv(norm(q)=1)is convenient to represent rotations, this representation way will have 4 parameters.Could I use the vector part of unit quaternion, which is qv to represent the rotations? which will use 3 parameters to present rotations.

Question1:If yes, are there any restrictions？For example, the first element of the unit quaternion have to be 0?

Right now I have a estimator for my quadcopter dynamics and I use 3-parameters vector quaternion to represent the rotation. For how I implement the quaternion multiplication in Matlab, it shows as follows:

``````function [r] = vec_quat_multiply(p,q)

%vector quaternion multiplycation

p1=p(1);p2=p(2);p3=p(3);

q1=q(1);q2=q(2);q3=q(3);

p0=sqrt(1-(p1^2+p2^2+p3^2)); q0=sqrt(1-(q1^2+q2^2+q3^2));

r=[p0q0-p1q1-p2q2-p3q3; p0q1+q0p1+p2q3-p3q2; p0q2+q0p2+p3q1-p1q3; p0q3+q0p3+p1q2-p2q1;];

r0=r(1)/norm(r); r1=r(2)/norm(r); r2=r(3)/norm(r); r3=r(4)/norm(r);

r=[real(r1);real(r2);real(r3)];

end
``````

Question2: If I use the the function like above,and Over time, due to the problem of calculation accuracy, when I calculate the first element of a unit quaternion(p0=sqrt(1−(p12+p22+p32));q0=sqrt(1−(q12+q22+q32));use these two lines to implement it), sometimes an imaginary number is returned. What should I do?
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://stackoverflow.com/questions/65831061/how-should-i-implement-the-3-parameter-vector-quaternion-to-represent-the-rotati", "fetch_time": 1627585116000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2021-31/segments/1627046153892.74/warc/CC-MAIN-20210729172022-20210729202022-00479.warc.gz", "warc_record_offset": 534710384, "warc_record_length": 36658, "token_count": 456, "char_count": 1378, "score": 3.71875, "int_score": 4, "crawl": "CC-MAIN-2021-31", "snapshot_type": "latest", "language": "en", "language_score": 0.6814412474632263, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00014-of-00064.parquet"}