Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking for parallel vectors - something is wrong.
03-25-2016, 11:47 AM
Post: #1
Checking for parallel vectors - something is wrong.
Hi there

In a code I'm working, at some point I have two vectors with these values:
Vec: {0.0,1.0,0.0}
VecRef: {1.0,0.0,0.0}


and by computing the dot product e3d_vec:dot(Vec, VecRef) it's returning 0.0 (zero).

By the Dot Product definition, I was expecting to get a value other than zero. It should happens only if both vectors were parallel to each other. (Am I wrong?)

The two vectors cannot be parallel, so I test this value to try fix that - I need them to be perpendicular each other, being the Vec1 the reference one.

Just in case needed, here is the code where I use it:
Code:
force_perpendicular(Vec, VecRef) ->
    DotProd = e3d_vec:dot(Vec, VecRef),
    if abs(DotProd) =< 0.001 -> % vectors are almost parallel
            Nor0 = e3d_vec:cross(VecRef, rot_axis_vec(main_axis(Vec))),
            Rot0 = e3d_mat:rotate(+90.0, Nor0),
            Nor = e3d_mat:mul_vector(Rot0, VecRef);
       true ->
            Nor = e3d_vec:cross(VecRef, Vec)
    end,
    Rot = e3d_mat:rotate(90.0, Nor),
    e3d_vec:norm(e3d_mat:mul_vector(Rot,VecRef)).

main_axis({X,Y,Z}) ->
    if (abs(X) > abs(Y)) ->
            if (abs(Z) > abs(X)) -> z;
               true -> x
            end;
       true ->
            if (abs(Z) > abs(Y)) -> z;
               true -> y
            end
    end.

rot_axis_vec(x) -> {0.0,0.0,1.0}; % rotate vector in x around of z axis
rot_axis_vec(y) -> {0.0,0.0,1.0}; % rotate vector in y around of x axis
rot_axis_vec(z) -> {1.0,0.0,0.0}. % rotate vector in z around of x axis

Any idea about what is wrong?

My Wings3D Collection at G+
Reply
03-25-2016, 11:43 PM (This post was last modified: 03-25-2016 11:49 PM by ggaliens.)
Post: #2
RE: Checking for parallel vectors - something is wrong.
More often than not ... if I need two vectors to be perpendicular ... I used the e3d_vec:cross( ) in order to ensure that.

For example ... I have a single vector ... and I need any of its perpendiclar vectors (family of vectors) ... I can take


Vector A

compute any old random vector which is not equal to A .... call it B.

C = Then e3d_vec:cross(A,B)

C will be perfectly perpendicular to A by definaition. And then you could of course compute the third mutually perp B prime B2 using {A,C}



Not sure if this helps at all.

If you believe MathcWorld ... then the ZERO VALUE for perpendiculars is correct.

So e3d_vec seems correct.
Reply
03-25-2016, 11:58 PM
Post: #3
RE: Checking for parallel vectors - something is wrong.
The random vector doesn't interest me.

As I said, I have two vector - set by the user, where one is the reference and then I want to ensure the second one must be rotated from it by 90°. For that I'm using the cross operation - of course.

I think I'm going to computer the degree between them. It will be a little more expensive computationally, but I will be sue about what I'm evaluating.

Thanks.

My Wings3D Collection at G+
Reply
03-26-2016, 05:11 AM
Post: #4
RE: Checking for parallel vectors - something is wrong.
How could e3d_vec:degrees used one time
on user inputs be "expensive" ?

I don't get it. Used in a big loop. Yes. Used 1000 times. Almost instant.
Reply
03-26-2016, 05:25 AM
Post: #5
RE: Checking for parallel vectors - something is wrong.
Not much I know. That is why I used "little".

As I'm going to use that during preview mode, I tend to use the "shortest path" I can take.

Anyway, I need to go ahead and I will not spend time here.

Thanks again.

My Wings3D Collection at G+
Reply
03-27-2016, 12:51 PM
Post: #6
RE: Checking for parallel vectors - something is wrong.
""By the Dot Product definition, I was expecting to get a value other than zero. It should happens only if both vectors were parallel to each other. (Am I wrong?)"


Yes ... you were wrong.
Reply
03-27-2016, 03:03 PM
Post: #7
RE: Checking for parallel vectors - something is wrong.
Yeah. I know now.

For some reason I read and understood this text in the wrong way Blush:
Quote:The dot product gives us a very nice method for determining if two vectors are perpendicular and it will give another method for determining when two vectors are parallel. Note as well that often we will use the term orthogonal in place of perpendicular.

Now, if two vectors are orthogonal then we know that the angle between them is 90 degrees. From (2) this tells us that if two vectors are orthogonal then,
...
ref. link

The Cross product have the behaviour I wanted:
Quote:Now, let’s address the one time where the cross product will not be orthogonal to the original vectors. If the two vectors, and , are parallel then the angle between them is either 0 or 180 degrees. From (1) this implies that,
ref. link

Sometimes, to learn, we need to know where we are going wrong. Not only that we are wrong. Wink

My Wings3D Collection at G+
Reply
03-28-2016, 11:48 AM
Post: #8
RE: Checking for parallel vectors - something is wrong.
orthogonal means perpendicular ... but you probably got that down by now.
Reply


Forum Jump:


User(s) browsing this thread: 1 Guest(s)