Skip to content

Add row/column algebra methods to Matrix for Vector #459

Open
@Aweptimum

Description

@Aweptimum

This request doesn't really have any justification in the pure linear algebra world, but I have run into a use case where I want to treat 3 columns of a 3x3 matrix as vectors. This 3x3 matrix is constructed from 3 column vectors so that I can easily multiply it by another 3x3 rotation matrix (rotating the 3 vectors in one operation). The issue is that I'd still like to operate on the individual columns of the matrix. It would be convenient if there were methods similar to the columnAdd/rowAdd methods and friends that took a row/column index and a vector as arguments.

$mat = MatrixFactory::createIdentity(3);
$displacement = new Vector([2,0,0]);
$mat  = $mat->columnAdd(0, $displacement);
var_dump($mat->getColumn(0)) // prints [3,0,0]

Currently I'm doing this instead:

$mat = MatrixFactory::createIdentity(3);
$zero = new Vector([0,0,0]);
$displacement = new Vector([2,0,0]);
$displacementMat = MatrixFactory::createFromVectors([
    $displacement, $zero, $zero
]);
$mat = $mat->add($displacementMat);

Which isn't much more trouble to write, it's just less clear what's going on.

Understandable if it's preferred to not add these kinds of methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions