What is the formula for obtaining a vector perpendicular to another vector?

What is the formula for obtaining a three-dimensional vector B lying on a plane perpendicular to vector A?

That is, given the vector A, that is, the formula f (angle, module), which gives a vector perpendicular to A with the specified module and rotated through an angle φ

+5
source share
6 answers

If two vectors are perpendicular, then their point product is zero.

So: v1(x1, y1, z1), v2(x2, y2, z2).

=> x1 * x2 + y1 * y2 + z1 * z2 = 0

You know (x1, y1, z1). Put arbitrary x2and y2, and you will get the corresponding z2:

z1 * z2 = -x1 * x2 - y1 * y2
=> z2 = (-x1 * x2 - y1 * y2) / z1

Remember that z1- 0. Then you are on the plane.

+8
source

cross product AxC C, A.

, A, . , , C, A:

if (A2 != 0 || A3 != 0)
    C = (1, 0, 0);
else
    C = (0, 1, 0);
B = A x C; 
+6
function (a,b,c)
{
    return (-b,a,0)
}

, a, b 0.

, :

function (a,b,c) 
{
    return  c<a  ? (b,-a,0) : (0,-c,b) 
}

, c < a then max(a,b) = max(a,b,c), vector(b,-a,0).length() > max(a,b) = max(a,b,c), max(a,b,c) , . c > a .

+4

z ( ) . <modulus * cos(angle), modulus * sin(angle), 0> .

def getPerpendicular(v1,modulus,angle):
    v2 = vector(0,0,1)
    v1_len = v2.length()

    axis = v1.cross_product(v2)
    sinAngle = axis.length() / v1_len       # |u x v| = |u| * |v| * sin(angle)
    cosAngle = v1.dot_product(v2) / v1_len  # u . v = |u| * |v| * cos(angle)
    axis = axis.normalize()
    # atan2(sin(a), cos(a)) = a, -pi < a < pi
    angle = math.atan2(sinAngle, cosAngle)

    rotationMatrix = fromAxisAngle(axis, angle)

    # perpendicular to v2
    v3 = vector(modulus*cos(angle),modulus*sin(angle),0)

    return rotationMatrix.multiply(v3);

, . : WP:

. , , , .

+1

, , vec, vec ( , vec ). , Vec3D - .

Vec3D arbitrary_orthogonal(Vec3D vec)
{
  bool b0 = (vec[0] <  vec[1]) && (vec[0] <  vec[2]);
  bool b1 = (vec[1] <= vec[0]) && (vec[1] <  vec[2]);
  bool b2 = (vec[2] <= vec[0]) && (vec[2] <= vec[1]);

  return cross(vec, Vec3D(int(b0), int(b1), int(b2)));
}
+1
source

q4w56 almost exists for a reliable solution. Problems: 1) Does not take into account scaling. 2) Does not compare the value between two variables, if necessary.

scale = |x| + |y| + |z|

if scale == 0:
  return (0,0,0)

x = x/scale
y = y/scale
z = z/scale

if |x| > |y|:
  return (z, 0,-x)
else:
  return (0, z,-y)

Scaling is important when working with very large or very small numbers. In addition, in general, you are better off doing floating point operations with values ​​from 0 to 1.

0
source

All Articles