C++ Question matrix operation needed for control mixing.

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,868
Reaction score
4
Points
0
Location
San Diego
I have a set of simple 3x3 matrices that represent "mixing commands".

Code:
// Mixer for Quadrant 1
//		 X   Y   Z
//pitch		 0,  1,  0 
//yaw		-1,  0,  0
//roll		 0,  1,  0

In this example I want a positive pitch input to translate into 0 thrust along the quad's x and z axes and positive thrust along the y axis.

Sadly, I'm burnt out from work + finals and drawing a blank, on how to actually do it.
 
That looks pretty much correct by the idea. You convert the input commands into a new coordinate system. Thus every column in the matrix should be the base vectors for the coordinate system: if you only want pitch, the first column should be the result of the operation.

You can also turn the input vector into the thruster level vector by a single matrix. You just need a matrix that has three columns and one row for every thruster you want to handle, so that the product "M * v" has one vector with one element for every thruster.
 
So I went to bed and now, drinking my morning coffee, I know the operation that I need to perform.

:coffee:

Code:
// Where "VECTOR3 input" is the desired rotation around each axis and "MATRIX3 mQuad1" is the 3x3 matrix from before.

VECTOR3 v1 = _V(mQuad1.m11, mQuad1.m12, mQuad1.m13) * input.x;	// multiply pitch input by first row
VECTOR3 v2 = _V(mQuad1.m21, mQuad1.m22, mQuad1.m23) * input.y;	// multiply yaw by second
VECTOR3 v3 = _V(mQuad1.m31, mQuad1.m32, mQuad1.m33) * input.z;	// and Roll by third
VECTOR3 output = v1 + v2 + v3;					// combine result.

I recognize this as being a standard operation but I'm drawing a blank on it's name.
 
Last edited:
I recognize this as being a standard operation but I'm drawing a blank on it's name.
Matrix multiplication?

You're just multiplying a vector3 (a 1x3 matrix) by a 3x3 matrix, which returns a 1x3 matrix, e.g. another vector3.
 
Matrix multiplication?

You're just multiplying a vector3 (a 1x3 matrix) by a 3x3 matrix, which returns a 1x3 matrix, e.g. another vector3.

It's not straight matrix multiplication.

For standard multiplication, "mQuad1 * vector", an input of ( 1, -1, 0) would return (-1, -1, -1) where as my operation returns ( 1, 1, 0).

I know there's a name for this but my brain's coming up blank.

---------- Post added at 11:39 ---------- Previous post was at 10:00 ----------


Knowing how I would solve the problem on paper, if not in code, I reversed the standard order of operations for columns and rows.

In other words I reinvented transpose-multiplication, AKA the "tmul ()" operator. :facepalm:

---------- Post added at 11:43 ---------- Previous post was at 11:39 ----------

Again I blame exhaustion and lack of coffee for not realizing this earlier.
 
Last edited:
Back
Top