This forum has been archived. All content is frozen. Please use KDE Discuss instead.

make vectors perpendicular

Tags: None
(comma "," separated)
bennih
Registered Member
Posts
21
Karma
0
OS

make vectors perpendicular

Sat Oct 19, 2013 10:13 am
Hello!

Iam searching for a smart way to make 2 vectors, which have the same origin, perpendicular.
One method would be to do the cross product twice, but i hope there is a better way.

greetings from germany!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: make vectors perpendicular

Sun Oct 20, 2013 7:44 am
Are your vectors unit vectors? Do you want to preserve their length? Do you want to keep the first one fixed?

Anyway, an alternative to two cross product is to project the second one on the plane orthogonal to the first one, e.g.,

Code: Select all
v2 = (v2-v2.dot(v1)/v1.squaredNorm()*v1).normalized();


This returns a unit vector, and if v1 is unit, then you can avoid the normalization by /v1.squaredNorm().
bennih
Registered Member
Posts
21
Karma
0
OS

Re: make vectors perpendicular

Sun Oct 20, 2013 3:25 pm
Hi,

maybe some more informations from my side would be appropriate. sorry for that.
Yes you guessed it right. The two vectors are unit vectors and one should be fixed.

Ive done it before with a twice cross product, but if one vector was on an axis it doesnt worked, because the cross product didnt get along with the zeros.

Your solution seems fine!

Thank you again Sir!

greetings Benni


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]