1

So if you have 4 vectors, and you know their directions (which all could be different), and you could change all their magnitudes, what would you set the magnitudes equal to if you want all 4 vectors to add up to another vector which you know?

This might seem like a little bit too specific question, but the reason I ask this is for a program I'm making with kRPC for KSP in which 4 tilted engines hover an aircraft, even when the entire aircraft is tilted. I tried searching it, but I didn't know exactly what to search. I don't know a lot about the math of vectors. Thanks!

SwissAndOr
  • 35
  • 1
  • 7
  • 1
    How many dimensions are you working in, 3? And are the vectors linearly independent? – jedwards Apr 02 '15 at 04:57
  • @jedwards Yeah I'm working in 3 dimensions. I don't know if they're linearly independent but they're all facing 45 degrees on the y axis and they're each at "right angles toward each other". – SwissAndOr Apr 02 '15 at 05:23
  • It's not possible to have four vectors in three dimensions that are all at "right angles toward each other" unless you are also considering the zero vector (which won't help your summation) or one of the vector's direction is reverse of another (which would mean you could just multiple one by zero and scale the other). You may want to double check your problem's premise. Also, you want to consult with the [Mathematics](http://math.stackexchange.com/) exchange. – BobChao87 Apr 02 '15 at 06:13

2 Answers2

1

From what I understand, you are trying to sum vectors, and you are looking for a particular solution to get an end vector. In a way you are asking how to solve a problem that looks like this:

a1V1 + a2V2 + a3V3 + a4V4 = aV

where V are vectors, and a are magitudes. I am assuming that V are fixed (the way your plan jets are positioned?). I am also assuming that your vectors are 3 dimensional

So from the math alone, you have 3 dimensions and 4 parameters. Meaning that one of the 'a' can be anything. I don't think I can help any further than that without knowing the exact vectors.

In terms of code, solving for 'a's is trying to solve linear equations, typically done by using scipy's linalg: https://docs.scipy.org/doc/scipy-0.15.1/reference/linalg.html In particular, scipy.linalg.solve().

Again, you have to be very aware of the dimensions of the problem if you use the 4 vectors with the matrix, you will run into a lot of issues. Something must be done to determine one of the 'a' values before trying to solve the equations.

Edit: I thought a bit more about the problem, and I realized that there is a constraint in the system, and that is that the 'a's cannot be negative. So it seems like there are unique solutions to the system.

cyneo
  • 876
  • 7
  • 9
1

It may not always possible, it will depend on the vectors. Technically your target vector must be in the linear span of your four input vectors.

You can write it as the following matrix equation:

Ax = b

With, b the target vector, x the coefficients summing coefficients and A a matrix made by stacking your four vectors column-wise. The x vector exists if and only if the A matrix is invertible.

You can solve this using the numpy.linalg.solve function.

In your case, you may have problem if you have 4 vectors of dimension 3 (or 2): in this case there is not only one solution, and it gets tricky. In practice, you would need to ditch one (or two) of the vectors to keep only 3 (or 2) independent vectors.

You can still use numpy.linalg.lstsq to get an approximative solution though.

Geeklhem
  • 689
  • 7
  • 12
  • I thank you for helping me but I've found out that I was over complicating things too much and I've found a much easier solution to my problem. I haven't even learnt linear algebra yet so I was going too far. Thanks anyways though. – SwissAndOr Apr 02 '15 at 18:48