**1**

# Finding vector perpendicular to line in 3D

###
#2
Crossbones+ - Reputation: **1709**

Posted 31 May 2010 - 12:52 PM

Another approach is to find which component in the line direction vector is closest to zero, and create a vector where that component value is 1 and the rest are 0. You can then use something like Gram-Schmidt to find the perpendicular vector.

Unfortunately, the hairy ball theorem tells us that you need conditional logic to make this process work for any given line direction, because there is no continuous function we can use.

###
#4
Members - Reputation: **2076**

Posted 31 May 2010 - 06:13 PM

Quote:I'm not sure if Zipster already mentioned this, but one solution is to find the element of the line direction vector with the smallest magnitude (as Zipster mentioned), and then cross the direction vector with the cardinal basis vector ([1, 0, 0], [0, 1, 0], or [0, 0, 1]) that corresponds to this element. (This is the method I prefer for computing an arbitrary vector perpendicular to another vector, an operation commonly needed for billboarding, decals, and so forth.)

Original post by _swx_

Solving the dotproduct equation was my initial solution to the problem. I was hoping for a prettier solution, but I guess it'll have to do. Thanks for the interesting wikipedia link (Hary ball theorem) :)

###
#6
Members - Reputation: **981**

Posted 01 June 2010 - 02:07 AM

Quote:

Original post by Zipster

Unfortunately, the hairy ball theorem tells us that you need conditional logic to make this process work for any given line direction, because there is no continuous function we can use.

Why? The space here is RP^2, not S^2... granted, that's just S^2 with antipodes identified, but still, it doesn't jump out at me that this should automatically carry over... (But then, lots of things that should jump out at me seem not to...)

Actually, here you go: The hairy ball theorem says you can't have a smooth nonvanishing vector field on S^2. However, just ONE vanishing point is enough. E.g., consider a constant vector field on the plane multiplied by a radial falloff and mapped to the sphere by stereographic projection.

So now, here's a way to get a continuous (albeit nonsmooth) nonvanishing vector field on RP^2: Since each point on RP^2 is identified with two points on the sphere, just take whichever of the two vectors (from the vector field) has larger norm.

Then, there's always an analytic function arbitrarily close to any continuous function (constructively: Run the heat equation for epsilon seconds), so you can now get a smooth vector field from the continuous one constructed above.

(An alternate construction could have used some kind of "soft max" operator.)

Have I missed something?

[Edited by - Emergent on June 1, 2010 4:07:20 PM]

###
#7
Crossbones+ - Reputation: **1709**

Posted 01 June 2010 - 07:10 AM

Quote:

Original post by Emergent

So now, here's a way to get a continuous (albeit nonsmooth) nonvanishing vector field on RP^2: Since each point on RP^2 is identified with two points on the sphere, just take whichever of the two vectors (from the vector field) has larger norm.

Wouldn't this require a conditional to determine the one with the larger norm?

Quote:

Have I missed something?

Probably not :) I've honestly just never seen a solution to this problem that didn't at some point require conditional logic in one way or another, due to the nature of the tangent field. But I'm certainly open to the possibility that one exists.

###
#8
Members - Reputation: **981**

Posted 01 June 2010 - 10:38 AM

From Wikipedia:

Quote:

A consequence of the hairy ball theorem is that any continuous function that maps a sphere into itself has either a fixed point or a point that maps onto its own antipodal point. This can be seen by transforming the function into a tangential vector field as follows.

Hence, any smooth map from RP^2 to RP^2 has a fixed point. At the fixed point,

f(p)=p || p

so there's no way to have f(p) perpendicular to p for all p.

They even give the proof right there...

###
#9
Members - Reputation: **97**

Posted 15 August 2014 - 03:49 PM

If you rotate your direction vector twice (90° arround x-axis and 90° around y-axis) you get an arbitrary vector that is linearly independent of the direction vector. Then you retrieve a perpendicuar vector to those two vectors via cross product.

Or is there an error in reasoning for that method?

Edit: Oh yes there are cases where this fails -.- e.g. (1,0,-1) turned arround x-axis by 90° then turned arround y-axis by 90° results in the same vector. But can it still fail when turned by different angles like 30° and 60° ?

**Edited by hageldave, 15 August 2014 - 04:17 PM.**