
Matrix3d / Subtract method adds
Posted Tuesday, 30 March, 2010 - 14:32 by glebedev| Project: | The Open Toolkit library |
| Version: | 1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | open |
Jump to:
This is not subtraction:
/// Subtract left matrix from this matrix.
/// The matrix to subtract.
public void Subtract(ref Matrix3d matrix)
{
R0C0 = R0C0 + matrix.R0C0;
R0C1 = R0C1 + matrix.R0C1;
R0C2 = R0C2 + matrix.R0C2;
R1C0 = R1C0 + matrix.R1C0;
R1C1 = R1C1 + matrix.R1C1;
R1C2 = R1C2 + matrix.R1C2;
R2C0 = R2C0 + matrix.R2C0;
R2C1 = R2C1 + matrix.R2C1;
R2C2 = R2C2 + matrix.R2C2;
}
/// Subtract left matrix from this matrix.
/// The matrix to subtract.
/// The resulting matrix of the subtraction.
public void Subtract(ref Matrix3d matrix, out Matrix3d result)
{
result.R0C0 = R0C0 + matrix.R0C0;
result.R0C1 = R0C1 + matrix.R0C1;
result.R0C2 = R0C2 + matrix.R0C2;
result.R1C0 = R1C0 + matrix.R1C0;
result.R1C1 = R1C1 + matrix.R1C1;
result.R1C2 = R1C2 + matrix.R1C2;
result.R2C0 = R2C0 + matrix.R2C0;
result.R2C1 = R2C1 + matrix.R2C1;
result.R2C2 = R2C2 + matrix.R2C2;
}
/// Subtract left matrix from left matrix.
/// The matrix on the matrix side of the equation.
/// The matrix on the right side of the equation
/// The resulting matrix of the subtraction.
public static void Subtract(ref Matrix3d left, ref Matrix3d right, out Matrix3d result)
{
result.R0C0 = left.R0C0 + right.R0C0;
result.R0C1 = left.R0C1 + right.R0C1;
result.R0C2 = left.R0C2 + right.R0C2;
result.R1C0 = left.R1C0 + right.R1C0;
result.R1C1 = left.R1C1 + right.R1C1;
result.R1C2 = left.R1C2 + right.R1C2;
result.R2C0 = left.R2C0 + right.R2C0;
result.R2C1 = left.R2C1 + right.R2C1;
result.R2C2 = left.R2C2 + right.R2C2;
}


Comments
#12
I agree that the index operator would be great. And simply using the ListSeparator should be no problem. Will look at this later for my repo. I also considered a little more string formatting when displaying Vectors (which would also apply to matrices as well). Any thoughts on other format strings that would be helpful? Lining up each component? etc?
#13
The ability to specify the number of decimal-places to be output by ToString() is useful, although I'm not sure it necessarily belongs in the core Math classes. I've written extension-methods for my own use which do this.
My gut feeling is that ToString() with no parameters should output the values in as simple a format as possible - the UNIX principle that the output of one command may become the input of another seems a sane model here. Overloads of ToString() which take format-control parameters could be provided, but I'm not convinced: there's obviously no way you could cater to every possible requirement of an application, so it may be better to leave it alone completely :-)
The other method I added was a new constructor which takes a string (in the same format as output by ToString) and constructs a new Vector3d/Matrix4d/whatever from it.
#14
Addressed these issues here: https://github.com/andykorth/opentk
* Issue 1880, Fix non-locale Vector ToString method
* Add create from quaternion method to Matrix4
* Added index getters and setters to all vector and matrix classes
* added Robmaister's Matrix3 implementations