as u know dot product and vector norm(euclidean) definitions are as following:

  • $ \vec v . \vec w = \left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta = (v_x \times w_x+v_y \times w_y+v_z \times w_z) $($\theta$ being the angle between two vectors)
  • $ \left\lVert \vec x \right\rVert = \sqrt{(x_x)^2 + (x_y)^2 + (x_z)^2} $(regarding pythagorean theorem).

So we have two 3D vectors(we have their x,y and z components) $ \vec v $ and $ \vec w $ both of which have a length close to zero and since we're dealing with real numbers obviously data is in floatin-point representation and round-off errors during calculation is possible, we want to test whether vectors are perpendicular or parallel(linearly dependent that is pointing in either the same or opposite direction), normally if $ (\vec v . \vec w)^2 $ is close to 0(we say 'close' because of round-off errors) we can conclude vectors are perpendicular and if $ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 $ is close to 0 then we conclude vectors are parallel, but in our case both results of these expressions will be close to zero, now one way to solve the issue is to multiply each vector by a scalar so that its length increases and expressions will not yield near values anymore, but I also came up with an alternate solution as it follows:

$$ R = \frac{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 }{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 } = \frac{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 }{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 \times (\cos\theta) ^2 } $$ if the R is some big value it shows that $ \cos\theta $ has a value close to 1 so we can conclude vectors are parallel and if R is some small value(close to 1) it demonstrates that $ \cos\theta $ is close to 0 so we can conclude vectors are perpendicular, now do you think there is any issue regarding this solution?

  • $\begingroup$ What's wrong with normalising $u$ and $v$ first? $\endgroup$ – lemon Aug 9 '14 at 23:19
  • $\begingroup$ nothing I just want to evaluate the foresaid method $\endgroup$ – Pooria Aug 9 '14 at 23:26
  • $\begingroup$ I am not fond of the use of the $\times$ symbol for scalar multiplication in the context of vector arithmetic. This symbol is frequently used for the cross product, $u \times v = \lVert u \rVert \lVert v \rVert \sin \theta$, and I keep having to remind myself that when you write $\lVert u \rVert \times \lVert v \rVert$ you merely mean $\lVert u \rVert \lVert v \rVert.$ $\endgroup$ – David K Aug 13 '14 at 1:25
  • $\begingroup$ well its between two norms and not two vectors so it can't be mistaken for cross product $\endgroup$ – Pooria Aug 13 '14 at 2:20
  • $\begingroup$ Cross-posted on CS.SE: cs.stackexchange.com/q/29022/755. Please don't cross-post on multiple SE sites, as it violates site rules. $\endgroup$ – D.W. Aug 13 '14 at 17:56

So what we really want to know is the value of $ \cos\theta $ not $ \left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta $ hence I found out that testing closeness of $ \vec v . \vec w $, $ \left\lVert \vec v \right\rVert . \left\lVert \vec w \right\rVert - \vec v . \vec w $, $ (\vec v . \vec w)^2 $ or $ (\left\lVert \vec v \right\rVert . \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 $ to zero is not actually the right solution despite it being written in a math book(a book on the math needed for computer graphics), the correct formula that gives us $ \cos\theta $ very simply is: $$ \frac{\vec v . \vec w}{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert}=\frac{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta}{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert} $$ also normalizing v and w makes it simpler


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.