-
Decimals in a matrix
Is it possible to put decimal values in a matrix? I tried creating a double matrix and I'm not getting what I want.
For example
Code:
double A[1][3];
A[0][0] = 2 *(x + x1);
A[0][1] = 2 *(y + y1);
A[0][2] = sqrt(r^2 - (x + x1)^2 - (y + y1)^2);
It's just not working at all and I don't seem to be making any headway. Turning them into ints loses data, and normalizing it (these are vectors) will just give me (0,0,0) everywhere. What am I supposed to do?
-
how does it not work?
btw, perhaps you want to use (r*r) as opposed to (r^2), which is r bitwise-XOR 2.
-
And a bitwise XOR on a double is a nasty beast. In fact I'm surprised the thing compiled.
Yes you can put non-integral data types in arrays. A matrix is one use for arrays, but in all actuality your question boils down to: Can you use floating point values in arrays?
Yes. If you couldn't Direct3D and OpenGL would not be possible. They specifically use floating point matrices as well as floating point colors, vectors, texture coords, and a host of other floating point structures.
Code:
float matrix[3][3];
matrix[0][0]=1.0f;matrix[0][1]=0.0f;matrix[0][2]=0.0f;matrix[0][3]=0.0f;
matrix[1][0]=0.0f;matrix[1][1]=1.0f;matrix[1][2]=0.0f;matrix[1][3]=0.0f;
matrix[2][0]=0.0f;matrix[2][1]=0.0f;matrix[2][2]=1.0f;matrix[2][3]=0.0f;
matrix[3][0]=0.0f;matrix[3][1]=0.0f;matrix[3][2]=0.0f;matrix[3][3]=1.0f;
This should work just fine. Print the array out.