• 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
« Next Oldest | Next Newest »

Users browsing this thread: 2 Guest(s)



Messages In This Thread
Checking for parallel vectors - something is wrong. - by micheus - 03-25-2016, 01:47 AM
RE: Checking for parallel vectors - something is wrong. - by ggaliens - 03-25-2016, 01:43 PM
RE: Checking for parallel vectors - something is wrong. - by micheus - 03-25-2016, 01:58 PM
RE: Checking for parallel vectors - something is wrong. - by ggaliens - 03-25-2016, 07:11 PM
RE: Checking for parallel vectors - something is wrong. - by micheus - 03-25-2016, 07:25 PM
RE: Checking for parallel vectors - something is wrong. - by ggaliens - 03-27-2016, 02:51 AM
RE: Checking for parallel vectors - something is wrong. - by micheus - 03-27-2016, 05:03 AM
RE: Checking for parallel vectors - something is wrong. - by ggaliens - 03-28-2016, 01:48 AM

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

© Designed by D&D - Powered by MyBB

Linear Mode
Threaded Mode