Computing two vectors that are perpendicular to third vector in 3D

后端 未结 5 2034
無奈伤痛
無奈伤痛 2021-01-18 03:06

What is the best (fastest) way to compute two vectors that are perpendicular to the third vector(X) and also perpendicular to each other?

This is ho

5条回答
  •  余生分开走
    2021-01-18 03:30

    I think the minimum maximum magnatude out of all element in a unit vector is always greater than 0.577, so you may be able to get away with this:

    -> Reduce the problem of finding a perpendicular vector to a 3D vector to a 2D vector by finding any element whose magnatude is greater than say 0.5, then ignore a different element (use 0 in its place) and apply the perpendicular to a 2D vector formula in the remaining elements (for 2D x-axis=(ax,ay) -> y-axis=(-ay,ax))

    let x-axis be represented by (ax,ay,az)
    
    if (abs(ay) > 0.5) {
      y-axis = normalize((-ay,ax,0))
    } else if (abs(az) > 0.5) {
      y-axis = normalize((0,-az,ay))
    } else if (abs(ax) > 0.5) {
      y-axis = normalize((az,0,-ax))
    } else {
      error("Impossible unit vector")
    }
    

提交回复
热议问题