Vector as linear comb. of vectors from same plane?
#1
Posted 11 January 2010 - 11:56 AM
x = a*x1 + b*x2
y = a*y1 + b*y2
z = a*z1 + b*z2
But what bothers me is this: to find a and b with the above system you need at most 2 of the 3 equations. But which two? Taking an equation out means you're projecting the 3D vectors on a 2D plane, which might give a headache, if after the projection the vectors become colinear, which is very much possible. So before doing the above calculation one has to check on which plane the reference vectors are not colinear and then choose the right 2 equations (cooridnates). There's just gotta be an easier and not that ugly way to do this I think, does anyone have an idea? Thank you!
#2
Posted 11 January 2010 - 01:06 PM
[v1 v2]
should project a vector v into the coordinate system [v1,v2] 'as good as possible' and give you a and b.
For real-valued matrices the Moore-Penrose-Pseudoinverse is (M^T * M)^-1 * M^T. (If the columns of M are linearly independent.)
#3
Posted 11 January 2010 - 01:41 PM
edit: Are all types of pseudo-inverse matrices suitable or just the Moore-Penrose?
#4
Posted 11 January 2010 - 02:16 PM
I don't have an online reference ready, but I think about it that way:
The pseudoinverse is a way to 'solve' the overdetermined least squares problem
min norm(A*x - d)
In your case
x = [a;b]
A = [v1,v2]
d = v
One solution is then
x = pinv(A)*d
But again: Be careful, this is based on the fading memories of a math lecture I had years ago...
[EDIT: of course it is pinv(A)*d, not pinv(A)*b]
#5
Posted 11 January 2010 - 03:07 PM
#6
Posted 12 January 2010 - 01:06 AM
Construct a vector v3, perpendicular to v1 and v2. This can be done using a cross product. Now you know that v has to be a linear combination of v1, v2, and v3, with the coefficient c for v3 in theory being 0:
x = a*x1 + b*x2 + c*x3
y = a*y1 + b*y2 + c*y3
z = a*z1 + b*z2 + c*z3
This is an ordinary system of three linear equations with three variables. Even if c isn't exactly 0 due to numerical imprecision, you know a and b are the coefficients of the projection of v onto the plane.
#7
Posted 12 January 2010 - 10:32 AM
-
Currently working on: the 3D engine for Tomb Raider.
#8
Posted 12 January 2010 - 11:11 AM
.oisyn said:
#9
Posted 12 January 2010 - 11:21 AM
I need to do this very quickly and many many BILLION times per second... The geometrical interpretation does not help in that account, but it was the way I came into these calculations in the first place.
@.nick:
The extended system seems to give a solution in this particular case, yes, but seems a bit computationally intensive, I don't know, I have to benchmark it and I will. Also not sure if it's ill-conditioned and/or stable. The way I was about to do it, before you posted, was by extracting the least squares approximation of the overdetermined system (as macnihist suggested), but not using the pseudoinverse (best solution, but computationally intensive). Instead I'm about to calculate it using QR decomposition. The decomposition itself is performed using Givens rotations (see the great book "Matrix Computations" by Gehe H. Golub et. al.) Let's see if it works.
#10
Posted 12 January 2010 - 01:09 PM
#11
Posted 12 January 2010 - 01:44 PM
Nick said:
Quote
Mihail121 said:
I need to do this very quickly and many many BILLION times per second... The geometrical interpretation does not help in that account, but it was the way I came into these calculations in the first place.
-
Currently working on: the 3D engine for Tomb Raider.
#12
Posted 12 January 2010 - 02:42 PM
coelurus said:
HANS, YOU'RE BACK!!!!!!!!!!!! I'm so glad to know you're alive :) Yes, the reference vectors (base of the plane) are normalized.
.oisyn said:
I don't know yet, but my (crude) guess is they are VERY volatile. We shall see after some experiments.
#13
Posted 12 January 2010 - 03:45 PM
Mihail121 said:
Quote
Quote
#14
Posted 12 January 2010 - 03:58 PM
To project vector A onto vector B, you do "A' = (A.B) / (B.B) * B". If B is normalised, you have just "A' = A.B * B".
#15
Posted 12 January 2010 - 06:44 PM
coelurus said:
#16
Posted 12 January 2010 - 08:11 PM
I have completely forgotten the instability behaviour with least squares fitting, would the normal solution really be a problem in this case?
QR decomposition definitely sounds overkill.
#17
Posted 13 January 2010 - 09:48 AM
Anyway:
Solving Nick's system directly for a,b is probably the fastest (and best) solution, but after massaging the pseudoinverse stuff a bit further I think I have come up with a way that does not employ the 'full construction' of the pinv and offers a nice geometrical interpretation.
Of course this can also be seen as a solution to Nick's linear system, depends on how you approach it.
The rows of the pseudoinverse are two normals onto which you project v:
a = dot(n1,v)
b = dot(n2,v)
you have three constraints on each normal:
dot(n1,v1) = 1
dot(n1,v2) = 0
dot(n1,cross(v1,v2)) = 0 (distances out of the plane should not count)
instead of solving for n1 and n2, in this special case you can construct them directly:
c1 = cross(v1,v2);
n1 = cross(v2,c1);
n1 *= 1/dot(v1,n1);
c2 = cross(v2,v1); // or -c1
n2 = cross(v1,c2);
n2 *= 1/dot(v2,n2);
Then you have, like written above:
a = dot(n1,v)
b = dot(n2,v)
I tried it in MATLAB with 100000 random vectors and it worked. (Let's hope my program isn't flawed...)
#18
Posted 13 January 2010 - 10:25 AM
coelurus said:
I have completely forgotten the instability behaviour with least squares fitting, would the normal solution really be a problem in this case?
QR decomposition definitely sounds overkill.
Yes, you were always silly :> Just don't get too smart around that particle accelerator :D Ok, back to the topic, the normal equation you mean? I never really considered that as an option, not a single man seems to be fond of that, because of extreme instability. QR decomp. is not really an overkill if fast Givens or, hmm, "modified" Givens is used.
Of course I don't have a problem to get the vectors normalized AND orthogonal and just transpose the coef. matrix to get the inverse, which will give me an answer instantly.
I was really hoping this thing has a small solution (1 mul, 2 adds or something), but that's life and it's complex.
@mac
Just tried it also, seems to work fine.
#19
Posted 13 January 2010 - 04:26 PM
macnihilist said:
#20
Posted 14 January 2010 - 07:33 AM
Mihail121 said:
Can you reveal anything more about the actual application you need this for?
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












