find a vector perpendicular to vector

Started by
21 comments, last by Timkin 19 years, 6 months ago
If i have a vector how do i find another vector that is perpendicular to it?
~guyaton
Advertisement
Very simple mathamatics here, all you need to is find the slope of the vector (& the midpoint if you are talking about line segments), then multiply the slope by -1.
2D or 3D?
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
this is only possible in 2 dimensions, in which case its a simple matter of rotating the vector 90 deg, which can be done like this:

output.x = -input.y;
output.y = input.x;
Quote:Original post by Eelco
this is only possible in 2 dimensions

It is certainly possible in 3D, only the solution will be any vector lying in a plane perpendicular to the original vector.
say your vector is v(x, y, z)
easy take and arbitrary vector say r(y, z, x)

the the cross product will generate a vector perpedicular to both

p = cross (v, r)

further more anorther cross product and to get the basis for cordenate system

t = cross (v * p)

know you have not one but two vectors perpendicular to the first,
Given (x,y,z) then (-(y*y+z*z)/x,y,z), (x,-(x*x+z*z)/y,z) and (x,y,-(x*x+y*y)/z) are all orthogonal (perpendicular) to it assuming x, y nor z are zero. If (x,y,z)=(0,0,0) then any vector is orthogonal to it. If (x,y,z)!=(0,0,0) then at least one component is not zero so one of the three vectors will work.
Keys to success: Ability, ambition and opportunity.
Quote:Original post by Anonymous Poster
Quote:Original post by Eelco
this is only possible in 2 dimensions

It is certainly possible in 3D, only the solution will be any vector lying in a plane perpendicular to the original vector.

so the solution to the 3d version of the problem is a plane, not a vector. no unique solution might aswell be no solution at all for all practical intents and purposes.
Quote:Original post by Anonymous Poster
say your vector is v(x, y, z)
easy take and arbitrary vector say r(y, z, x)

the the cross product will generate a vector perpedicular to both
...


So do not choose r == v by accident, since the result will be vector (0/0/0).
Quote:Original post by Eelco
so the solution to the 3d version of the problem is a plane, not a vector. no unique solution might aswell be no solution at all for all practical intents and purposes.

Wrong, since the question was simply to find a vector perpendicular to the first, not to find the ONLY vector perpendicular to the first. There can very well be a practical purpose to finding such a vector. (Btw, the 2D case does not give a unique solution either, even though they all lie along the same line.)

This topic is closed to new replies.

Advertisement