2
$\begingroup$

Is it possible to get a vector that's perpendicular to given vector using geometry nodes? I know in 3D space there won't be just one such vector but any on of the perpendicular vectors will do in my case.

$\endgroup$
1
  • $\begingroup$ If direction doesn't matter, just use a Vector Math node, and create the cross product with any other vector (anything but $(0,0,0)$). $\endgroup$
    – quellenform
    Commented Oct 31, 2022 at 10:05

1 Answer 1

6
$\begingroup$

⚠ Beware of the traps.

❌ Taking a cross product with any other vector has a chance of taking the cross product with self.

❌ Producing another vector is tricky: rotating a vector by 90° around $x$ and then 90° around $y$ won't necessarily work: you'd think you rotate by one axis, and if it fails (gimbal lock), then you still rotate by another, however if both rotations work, the second can cancel out the first:

>>> v = Vector((1, 1, -1))
>>> v.rotate(Euler((pi/2, pi/2, 0)))
>>> v
Vector((1.0, 0.9999999403953552, -1.0))

The resulting vector above isn't exactly the same, but this is only due to a floating point inaccuracy. Not only in some cases you could end with the exact same vector after rotation (and therefore do a cross product between two exactly same vectors), but also if you can come up with a mathematical way to find another vector, but this another vector can be very similar, you run into a risk that the error will make those vectors the same.

❌ Rotating by less doesn't help at all:

>>> v = Vector((0.706773579120636, 0.706773579120636, -0.030858200043439865))
>>> rot = Euler((radians(5), radians(5), 0))
>>> v.rotate(rot)
>>> v
Vector((0.706773579120636, 0.706773579120636, -0.030858200043439865))

So there are two problems here:

  1. Knowing non-zero vector $\vec{A}$, how to mathematically find a non-parallel non-zero vector $\vec{B}$ so you can apply a cross product $\vec{A}×\vec{B}$ to get a perpendicular vector, or find another way for the perpendicular vector.

How to find perpendicular vector to another vector?

  1. Take floating point inaccuracies into consideration and make sure the $\vec{B}$ vector is significantly different from the original vector $\vec{A}$.

Since this is not a mathematical forum, the solution seems trivial (unless I'm wrong again): Take two axes, and compare which axis is further from $\vec{A}$, then cross product with this axis:

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .