# Using FMatrix For 3x3?

**URL:** <https://forums.unrealengine.com/t/using-fmatrix-for-3x3/384866>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [February 14, 2017, 4:33am UTC](https://forums.unrealengine.com/t/using-fmatrix-for-3x3/384866 "2017-02-14T04:33:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_920f0672](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_920f0672](https://forums.unrealengine.com/u/anonymous_user_920f0672)\
**Post date:** [February 14, 2017, 4:33am UTC](https://forums.unrealengine.com/t/using-fmatrix-for-3x3/384866/1 "2017-02-14T04:33:01Z")

</div>

Is there a way to use `FMatrix` in a 3x3 manner functionally equivalent to the following c++ code?

```
Matrix3::Matrix3 () {
	for (int i=0; i<3; i++) {
		for (int k=0; k<3; k++) {
			if (i == k)
				m[i][k] = 1;
			else
				m[i][k] = 0;
		}
	}
}

Matrix3::Matrix3 (double a[3][3]) {
	for (int i=0; i<3; i++)
		for (int k=0; k<3; k++)
			m[i][k] = a[i][k];
}

Matrix3& Matrix3::operator = (const Matrix3 &n) {
	for (int i=0; i<3; i++)
		for (int k=0; k<3; k++)
			m[i][k] = n.m[i][k];
	return *this;
}

Vector3 Matrix3::operator * (const Vector3 &v) const {
	return Vector3
		(v.x*m[0][0] + v.y*m[0][1] + v.z*m[0][2],
		 v.x*m[1][0] + v.y*m[1][1] + v.z*m[1][2],
		 v.x*m[2][0] + v.y*m[2][1] + v.z*m[2][2]);
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c3e69a5a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c3e69a5a](https://forums.unrealengine.com/u/anonymous_user_c3e69a5a)\
**Post date:** [February 13, 2019, 9:25am UTC](https://forums.unrealengine.com/t/using-fmatrix-for-3x3/384866/2 "2019-02-13T09:25:23Z")

</div>

Yes, if you use it as homogenous matrix, so it looks like this

```
x1 x2 x3 0
y1 y2 y3 0
z1 z2 z3 0
0 0 0 1

```

So your first constructor is building the identity matrix, which would be

```
FMatrix A = FMatrix::Identity;

```

The second constructor where you copy a 3x3 matrix. In Unreal you cant directly do that, but indirectly using the FPlane constructor

```
FMatrix A( FPlane(a[0][0], a[0][1], a[0][2], 0),
            FPlane(a[1][0], a[1][1], a[1][2], 0),
            FPlane(a[2][0], a[2][1], a[2][2], 0),
            FPlane(0, 0, 0, 1));

```

Or you can set it afterwardst

```
FMatrix A = FMatrix::Identity;
for (int i=0; i<3; i++)
     for (int k=0; k<3; k++)
         A.M[i][k] = a[i][k];

```

The third one is obviously the equal operator

```
FMatrix B = A;

```

The vector multiplication is like seeing the FMatrix as a Transformation applied to a vector. So in unreal it is

```
FVector w = A.TransformVector(v)

```

You can look at the [FMatrix API](https://api.unrealengine.com/INT/API/Runtime/Core/Math/FMatrix/) to get more information 😉

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [February 13, 2019, 9:56am UTC](https://forums.unrealengine.com/t/using-fmatrix-for-3x3/384866/3 "2019-02-13T09:56:26Z")

</div>

there seesms to be implemrntation of this  
[https://api.unrealengine.com/INT/API/Runtime/Apeiron/Apeiron/PMatrix\_float\_3\_3/index.html](https://api.unrealengine.com/INT/API/Runtime/Apeiron/Apeiron/PMatrix_float_3_3/index.html)
