# Quaternion from two vectors: the final version

I have published a first article about how to build a quaternion from two arbitrary direction vectors that will transform one of the directions into the other. That article was deliberately omitting the special case when the two vectors were facing away from each other, which required special treatment. So I wrote a second article explaining how to quickly pick an orthogonal vector.

Combining the results from the two articles should be straightforward. Here is the resulting, final function:

/* Build a unit quaternion representing the rotation * from u to v. The input vectors need not be normalised. */ quat quat::fromtwovectors(vec3 u, vec3 v) { float norm_u_norm_v = sqrt(dot(u, u) * dot(v, v)); float real_part = norm_u_norm_v + dot(u, v); vec3 w; if (real_part < 1.e-6f * norm_u_norm_v) { /* If u and v are exactly opposite, rotate 180 degrees * around an arbitrary orthogonal axis. Axis normalisation * can happen later, when we normalise the quaternion. */ real_part = 0.0f; w = abs(u.x) > abs(u.z) ? vec3(-u.y, u.x, 0.f) : vec3(0.f, -u.z, u.y); } else { /* Otherwise, build quaternion the standard way. */ w = cross(u, v); } return normalize(quat(real_part, w.x, w.y, w.z)); }

If you know you are exclusively dealing with unit vectors, you can replace all occurrences of `norm_u_norm_v`

with the value `1.0f`

in order to avoid a useless square root.

## Comments

The complete version from nonunit vectors looks like

quat quat::fromtwovectors(vec3 u, vec3 v) {

}

Derivation of original method can be found http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/minorlogic.htm

For the simple case and normalized vectors, this can be carried out with just a single dot product, a single cross product and a single square root: just taking a half vector, normalizing it, taking a dot product for cosine of the half-angle and taking a cross product to produce the complex part of the quaternion. That seems to be slightly faster than the proposed version.

I have compared to the proposed implementation (which is in fact used in the glm library), glm seems to be less numerically stable for nearly opposite vectors rotate (1, 2, 3) to (-1, -2, -3.01).

Since you blog about these topics, you might be interested to read about Grassman algebra, aka Geometric Algebra.

The math is really nice IMHO, and a lot of 'magic' of complex numbers and quaternions is explained by it.

For example, any rotation in any dimension is actually a double reflection about two vectors where the angle between the vectors is half the rotation angle. The math for a double reflection (hence rotation) in that algebra is N*M*A*M*N, See e.g. http://en.wikipedia.org/wiki/Rotor_(mathematics)

Apparently the guys from the C4 Engine gave a talk about this at GDC! http://gdcvault.com/play/1015322/Fundamentals-of-Grassmann

There are entirely numerous revolutions that will pivot the primary vector to be toward the second vector, yet this strategy finds the turn that is in some sense the most limited, and likely the one which you are considering. To get the more extended pivots you can increase this quaternion by one that uses the first vector as the heading of the hub, Essay Writing Company with a subjective point of turn.

Hello, I am trying to learn what a quaternion is, not just for computer science, I like actually want to know exactly what it is and how to do http://www.click2assignment.co.uk/ calculations with them. I heard they're pretty easy, but I don't understand them. Like adding matrices, adding scalars and vectors and , to get quaternions or however it works.Thanks!!

Hello friends, If you love to play stickman games online then visit our website http://stickmangames.xyz and play stcikman games with it's full resources and no registration or download required.

Actually, you can define division for 4-dim vectors, the so-called "quaternions". Think of a vector in R

^{4 as an element of the form a+bi + cj + dk, where 1,i, j, k are linearly independent. Define i*i = j*j = k*k = -1, i*j = -j*i, and i*j = k. EZ Assignment Service UK tell about These rules allow us to multiply all vectors in R}4, and every non-zero vector has a multiplicative inverse.Hey dear it will be the golden chance for you to get the roblox cheats and you get all the resources of roblox here.

This is stunning, already when there was no permit necessary for the work many individuals were over-burden in the place, it's a decent advance. In the event that anybody needs additional data about this news <a href="https://americasuits.com/bomber-womens-fur-black-leather-hooded-jacket"> Bomber Womens Fur Hooded Black Leather Jacket</a>.

All of the two vectors are necessary whenever students are required dissertation help from most qualified writers. However learning these, people may have good grip on math subject.

as a sum of 4 squares, i.e. in the form c1

^{2 + c2}2 + c3^{2 + c4}2. The only issue with understanding is exactly what the numbers are. Are we talking about quaternion numbers (i.e. sums of squares of quaternions)? Promo Codes pretty sure this is not the case, because a) I don't know if it's true, and b) the method they're pointing to works for real numbers. Are we talking about real numbers? If so, then the answer is pretty easy. The numbers that can be written as the sum of 4 squares are exactly all number greater than or equal to 0, and if you multiply them, you get a number greater than or equal to 0.Such tutorials are very rare to be found. You have work hard in collecting data to write this post which i like it a lot. Keep up your good work.

Such tutorials are very rare to be found. You have work hard in collecting data to write this post which i like it a lot. Keep up your good work. Buy playground tiles from http://playgroundtilesuk.uk/playground-tiles.html

This is really a great stuff for sharing. Thanks for sharing. https://www.finance-assignments.com/

I have read your first article and your second article as well. There are very good informative knowledge shared in this post. Thanks for it. To get london brick Click here http://londonbricksuk.co.uk/

Well thanks for posting such an outstanding idea. I like this blog & I like the topic and thinking of making it right. https://statskey.com/

Deal Hack provides you with the collection of coupons, promo codes, and clearance sales from the Internet arena. You can now save up to 80% on different products and brands, http://dealhack.net is the right choice to make.

Thank you very much for sharing resulting, final function of the very good points. I would like to visit again this post. Carry on sharing it. To get Get information about rubber matting product Click here http://ukrubberflooring.co.uk/

Good information for me that For the simple case and normalized vectors, this can be carried out with just a single dot product, a single cross product and a single square root.Thanks for sharing it. To get strongest motorcycle jeans Click here http://resurgencegear.com/

I bookmark this blog because very impressive points I’ve learned from this blog and the post is written in very a good manner, and very informative and helpful blog I've ever found while searching UK dissertation help on web, and i am very pleased with the overall work, everything is well researched and maintained. I’ve been learned lot more good things from here, will surely recommend this blog to my friends, also thanks for this helpful post!

I Personally Like Your Post; You Have Shared Good Insights And Experiences. Keep It Up. https://www.theappgods.com/

Hi Buddy, Your Blog' S Design Is Simple And Clean And I Like It. Your Blog Posts About Online Writing Help Are Superb. Please Keep Them Coming. Greets! https://www.thecasesolutions.com/

Get the dissertation writing service students look for these days with the prime focus being creating a well researched and lively content on any topic. https://economicskey.com/

Though the only thing which might work for you is a legitimate & active Netflix account login and passwords. Moreover,https://netflixloginhelp.com/netflix-login-sign-in-account-netflix-com-sign-up/ this would even keep you away from harmful and malicious programs which you might encounter on your hunt

Thanks to your explanations, even such a beginner like me figured out this article. Thank you, I really like your blog and the quality of the material that you post 192.168.1.1 http://19216811-admin.com/

I have perused your first article and your second article also. There are great educational learning partook in this post. A debt of gratitude is in order for it. To get london block Click here. Buy Dissertation UK

Nice article to read.. looking for more..

take my online class Online Class Help

Thanks for sharing this blog its very informative and useful for us http://www.google.com

I swear that I did nothing but my blog appears to lose the announcement about newly added blog comment for my entries. I myself can not see my own entries either. It appears "Start a Blog" although if I click in I can see my posted entries. In my Home Page, it only http://promoforsales.com/ has Messages, and Page Views (the Blog Comment and Visitor Views are blown up !!). Moreover, despite my choice of publicizing my entries, but others are impaired to see. WHAT HAS HAPPENED TO MY BLOG? IS THERE ANYONE WHO CAN HELP ME?

i really struggled with this..i was not able to understand how to build a quaternion from two arbitrary direction vectors that will transform one of the directions into the other. this blog really helped me finding the solution..thanks fr sharing this.. https://www.certvalue.com/iso-9001-certification-in-saudi-arabia/ https://www.certvalue.com/iso-22000-certification-dubai/

When you are scratching your head in the middle of the night while hopelessly attempting to write your essays, just remember that help can be obtained by simply calling Best Essays Writing and telling them Top Essay Writing Service. So contact us now and get all of your essays completed by professionals.

All through the auto, arrange exists together with the capacity to help a more conceivable future. For instance, twofold as warmth sinks, keeping down the temperature of the auto's batteries and drivetrain. Black Leather Jacket

Such an instructive common contention for me I have taken an extreme number of central focuses and data in this discourse. Which will genuinely help me in my future. Handyman Dubai

Hello Thanks a lot for sharing such an amazing post. It was helpful and informative. For essay and assignment writing go to <a href="https://www.customessayswriter.co.uk/">Cheap Essay Writing Service UK</a>

As an example, twofold as warmth sinks, preserving down the temperature of the auto's batteries and drivetrain. There are super educational getting to know partook on this put up.Essay A debt of gratitude is in order for it. thank you, I really like your weblog and the satisfactory of the cloth which you post.

It is extremely nice to see the greatest details presented in an easy and understanding manner. Kelp

I see some amazingly important and kept up to length of your strength searching for in your on the site Curry Powder

I have read your article; it is very informative and helpful for me. I admire the valuable information you offer in your articles. Thanks for posting it. Calcium

I must say, I thought this was a pretty interesting read when it comes to this topic. Liked the material. . . . . Jackfruit

I don’t think many of websites provide this type of information. Coconut Oil

Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me. Turnips

The impressive information you can share about Quaternion from two vectors: the final version. Keep it up you are doing a good job https://www.webhostingonedollar.com/

Very friendly you explaining here on how to quickly pick an orthogonal vector which can be easily understand by everyone. Thanks for sharing the complete version from nonunit vectors.

Best Regards, http://www.personalstatementfolks.co.uk/psychology-personal-statement/

That's really important to know how you can watch free football game of Russia football world cup without TV cable. If you are in office or travel you should not miss those game right? So Let's see how you can watch fifa world cup live streaming for free in hd. Click this website https://wc2018live.org/fifa-world-cup-2018-live-stream/

By Visiting This Site I Found Cool Stuff Here Keep It Up. https://accountingassignment.xyz/

https://getapkmarket.co/

Pretty Helpful Material, Much Thanks For This Article. https://www.chelponline.com/c-plus-plus-assignment-help-13067

https://google.com/

https://www.allassignmenthelp.com/java-assignment-help.html

While perusing airfares, look for the one in green. That's the flight Google has identified as the single best deal. It's a small thing, but also a handy time-saver. Note, however, that this flight won't always be contained in the "best flights" box, which represents the best combination of price and flight time. Book google flights on https://www.google-flights.online

Commendable job with the article! It was really informative and enriching. Looking forward to more such posts in the future. Keep us updated with what’s in store! Will surely keep frequenting this website. <a href=https://www.makemyassignments.com/au/marketing-assignment-help-australia/ > marketing assignment help Australia</a>

Wow amazing post, I am interested to write on https://www.abbraci.com/

That's great, This is the really great post, I like it https://www.usajacket.com/blog/

Games are our best https://www.apkcoach.win/ companion for leisure hours ,in fact, some games are so addictive that we find spare hours out of our busy schedule just to play them

KFC is the second-largest restaurant chain all over the world. You can install the KFC App on your phone.

http://lowessurvey.info/kfc-app/

We Also Share Some Information About Our Business Matlab Expert

This Is Really Great Work. Thank You For Sharing Such A Good And Useful Information Here In The Blog For Students. SPSS Assignment Help

Very friendly you explaining here on the way to quickly choose AN orthogonal vector which may be simply perceive by everybody. I see some surprisingly necessary and maintained to length of your strength checking out in your on the location. Bespoke Leather Jacket

Hiring genuinely cheap assignment writing service only makes when the academic specialist also delivers the content as per the client’s expectations. However, easier said than done, but 100% possible when clients decide to hire our writing specialists at PA. We apply a unique strategic approach for each of your project without compromising the quality of the content and your limited budget allowed.

Science Channel’s Are Giving A Complete Knowledge To Its Viewers About Every Thing Students Write Done Dissertation On This Subjects And Show Its Importance. <a href="https://civilengineeringaid.xyz/">Online Civil Engineering Homework Help</a>

Ivey Case Study Analysis <a href="https://casestudyaids.xyz">Ivey Case Study Analysis</a>