Matrices in Objective-C

Is there any class for supporting Matrix in Objective-C? By matrix, I mean 2D arrays.

Now I use 2 NSArrays, one in the other. This works fine, but my code looks like a big mess.

I also tried using C-style arrays inside each other ( matrix[][]), but this approach is not suitable for my application, since I cannot automatically @synthesizeor specify @propertiesfor them.

I could, of course, create my own class for this, but I wonder if Objective-C can do something for this kind of situation. I did some research on Google but found nothing.

+5
source share
4 answers

No, Foundation does not have a 2D class. As for mathematical calculations, matrices are usually implemented in C or C ++ for reasons of mobility and performance. You will need to write your own class if you really want to.

+4
source

Obj-c doesn't seem to have its own structure for the matrix. I referenced the CATransform3D iOS SDK, found that it uses:

struct CATransform3D
{
    CGFloat m11, m12, m13, m14;
    CGFloat m21, m22, m23, m24;
    CGFloat m31, m32, m33, m34;
    CGFloat m41, m42, m43, m44;
};

typedef struct CATransform3D CATransform3D;

as a matrix of three-dimensional transformation.

+1
source

, , Matrix C, BLAS LAPACK. : .

:

YCMatrix *I = [YCMatrix identityOfRows:3 Columns:3];
double v = [I getValueAtRow:1 Column:1];
[I setValue:0 Row:0 Column:0];
+1

I think you need to subclass NSArray or use some non-sweet syntax: [ MyArray objectAtIndex:i*d+j]. The latter case is really cumbersome, since you will get only one awkward type of enumerator.

-2
source

All Articles