Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic functions for change of basis in 3D #939

Merged
merged 16 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addons/vectors/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
class CfgFunctions {
class CBA {
class Vectors {
PATHTO_FNC(matrixProduct3D);
PATHTO_FNC(matrixTranspose);
PATHTO_FNC(polar2vect);
PATHTO_FNC(scaleVect);
PATHTO_FNC(scaleVectTo);
Expand All @@ -16,6 +18,7 @@ class CfgFunctions {
PATHTO_FNC(vectElev);
PATHTO_FNC(vectMagn);
PATHTO_FNC(vectMagn2D);
PATHTO_FNC(vectMap3D);
PATHTO_FNC(vectRotate2D);
PATHTO_FNC(vectRotate3D);
PATHTO_FNC(vectSubtract);
Expand Down
43 changes: 43 additions & 0 deletions addons/vectors/fnc_matrixProduct3D.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_matrixProduct3D

Description:
Returns the resulting matrix from the matrix-matrix product.

Only accepts a 3x3 matrices.

Parameters:
_matrixA - first 3x3 matrix. <ARRAY>
_matrixB - second 3x3 matrix. <ARRAY>

Returns:
_returnMatrix - 3x3 matrix returned after matrix multiplication <ARRAY>

Examples:
(begin example)
// point reflection at origin [0,0,0] for every vector in matrix B
[[[-1,0,0],[0,-1,0],[0,0,-1]], [[1,2,3], [3,1,2], [2,3,1]]] call CBA_fnc_matrixProduct3D;
(end)

Author:
Kex
---------------------------------------------------------------------------- */

#include "script_component.hpp"

params [["_matrixA", [], [[]], 3], ["_matrixB", [], [[]], 3]];

_matrixB = [_matrixB] call CBA_fnc_matrixTranspose;

private _returnMatrix = [];
for "_i" from 0 to (count _matrixA -1) do
{
private _returnRow = [];
private _rowA = _matrixA select _i;
for "_j" from 0 to (count _matrixB -1) do
{
_returnRow pushBack (_rowA vectorDotProduct ( _matrixB select _j));
};
_returnMatrix pushBack _returnRow;
};
_returnMatrix;
44 changes: 44 additions & 0 deletions addons/vectors/fnc_matrixTranspose.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_matrixTranspose

Description:
Returns the transposed matrix.

Accepts any mxn matrix.

Parameters:
_matrix - mxn matrix to transpose. <ARRAY>

Returns:
_returnMatrix - nxm matrix <ARRAY>

Examples:
(begin example)
// returns the transposed matrix [[1,3,2], [2,1,3], [3,2,1]]
[[[1,2,3], [3,1,2], [2,3,1]]] call CBA_fnc_matrixTranspose;
(end)

Author:
Kyle Kotowick, Kex
---------------------------------------------------------------------------- */

#include "script_component.hpp"

params [["_matrix", [], [[]]]];

private _m = count _matrix;
private _n = count (_matrix select 0);

private _returnMatrix = [];

for "_j" from 0 to (_n - 1) do
{
private _returnRow = [];
for "_i" from 0 to (_m - 1) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use apply here?

Copy link
Contributor Author

@Kexanone Kexanone Jun 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the same goes for CBA_fnc_matrixProduct3D.

{
_returnRow pushBack ((_matrix select _i) select _j);
};
_returnMatrix pushBack _returnRow;
};

_returnMatrix;
29 changes: 29 additions & 0 deletions addons/vectors/fnc_vectMap3D.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_vectMap3D

Description:
Returns the resulting vector of the product matrix-vector product.

Only accepts a 3x3 matrices and 3D vector.

Parameters:
_matrix - 3x3 matrix, which serves as a map. <ARRAY>
_vector - 3D vector that is mapped. <ARRAY>

Returns:
_returnVector - 3D vector returned after matrix multiplication <ARRAY>

Examples:
(begin example)
// point reflection at origin [0,0,0]
[[[-1,0,0],[0,-1,0],[0,0,-1]], [1,2,3]] call CBA_fnc_vectMap3D;
(end)

Author:
Kex
---------------------------------------------------------------------------- */

#include "script_component.hpp"

params[["_matrix", [], [[]], 3], ["_vector", [], [[]], 3]];
_matrix apply {_x vectorDotProduct _vector};