Checking for parallel vectors - something is wrong. - Printable Version +- Wings 3D Development Forum (https://www.wings3d.com/forum) +-- Forum: Wings 3D (https://www.wings3d.com/forum/forumdisplay.php?fid=1) +--- Forum: Programming (https://www.wings3d.com/forum/forumdisplay.php?fid=7) +--- Thread: Checking for parallel vectors - something is wrong. (/showthread.php?tid=1645) |
Checking for parallel vectors - something is wrong. - micheus - 03-25-2016 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) -> Any idea about what is wrong? RE: Checking for parallel vectors - something is wrong. - ggaliens - 03-25-2016 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. RE: Checking for parallel vectors - something is wrong. - micheus - 03-25-2016 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. RE: Checking for parallel vectors - something is wrong. - ggaliens - 03-25-2016 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. RE: Checking for parallel vectors - something is wrong. - micheus - 03-25-2016 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. RE: Checking for parallel vectors - something is wrong. - ggaliens - 03-27-2016 ""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. RE: Checking for parallel vectors - something is wrong. - micheus - 03-27-2016 Yeah. I know now. For some reason I read and understood this text in the wrong way : 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.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. RE: Checking for parallel vectors - something is wrong. - ggaliens - 03-28-2016 orthogonal means perpendicular ... but you probably got that down by now. |