• Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Social Media
    •   @Wings3dOfficial
    •   @Wings3dOfficial
    •   Wings3dOfficial
    •   Wings3dOfficial
  • Register
  • Login
  • Website
  • Search
  • Member List
  • Help
  • Old Forum
  • Register
  • Login
Wings 3D Development Forum Wings 3D Programming v
« Previous 1 2 3 4 Next »
Checking for parallel vectors - something is wrong.

 
  • 0 Vote(s) - 0 Average
Checking for parallel vectors - something is wrong.

micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#1
03-25-2016, 01:47 AM
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?
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#2
03-25-2016, 01:43 PM (This post was last modified: 03-25-2016, 01:49 PM by ggaliens.)
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.
micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#3
03-25-2016, 01:58 PM
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.
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#4
03-25-2016, 07:11 PM
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.
micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#5
03-25-2016, 07:25 PM
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.
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#6
03-27-2016, 02:51 AM
""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.
micheus
Offline

Forum's Admin and Support | Bug fixer
Posts: 3,681
Threads: 185
Joined: Jun 2012
#7
03-27-2016, 05:03 AM
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, [Image: eq0033M.gif]
...
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, [Image: eq0029M.gif] and [Image: eq0030M.gif], are parallel then the angle between them is either 0 or 180 degrees. From (1) this implies that, [Image: eq0031M.gif]
ref. link

Sometimes, to learn, we need to know where we are going wrong. Not only that we are wrong. Wink
[Image: tw.png] @MicheusVieira [Image: yt.png] @MicheusVieira [Image: da.png] Micheuss [Image: ig.png] micheus4wings3d
* Wings3D Team stands for: Björn and Dan
ggaliens
Offline

Erlang Hacker
Posts: 954
Threads: 143
Joined: Nov 2012
#8
03-28-2016, 01:48 AM
orthogonal means perpendicular ... but you probably got that down by now.
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode