PDA

View Full Version : matrices matrices matrices


dunkel3d
06-26-2003, 09:54 PM
3 quick questions?

Is it possible to creatre a matrix and specify its size without assigning the float values?i.e.,

matrix $myMatrix[3][4];

is it possible to specify the size of a matrix with an int $var?

int $myRows = 3;
matrix $myMatrix[$myRows][4];

And does anyone know of an example of assigning float values to a matrix using a loop?

thanks in advance.

S

mark_wilkins
06-29-2003, 08:40 AM
yes, no, and I'm not sure what you're asking other than the really obvious answer.

-- Mark

wrend
06-29-2003, 05:42 PM
you could use a 'hack' to declare a matrix by evaluating a string with your variable concatenated into it, but unfortuneately this will globalise it, not keeping it in local scope ...which i just cant figure out how to do. this has fugged me off before. how to get arround this? arg...

mmm, just thought of way to keep it local, but its a bit annoying.

you have to split your proc into two - the bit that does gear up to where you get your array size, at which point you then evaluate it in a string as mentioned above, but ensure that it is bracketed in to keep it in local scope, and pass that matrix onto a second proc that picks up after that declaratn ...:

{
blah;
blah;
$rows = blah;
$columns = blah;
eval ("{matrix $tmp["+$rows+"]["+$columns+"]; postMatrixDeclareProc $tmp;}");
}

gloabl proc postMatrixDeclareProc (matrix $rightsizedMatrix){
blah;
blah;
}

this has now definately reached hack statis! :wip:

dunkel3d
06-30-2003, 12:43 AM
You call it a hack.

I'm kinda' new to this, but, are hacks fround upon by experienced programmers?

I ask this because it SEEMS like a viable solution.

S

wrend
07-01-2003, 01:39 PM
most of the frown is pointed at implementatn of a programming language that didnt allow for a simple thing to be, simple, i reckon.

its a hack, in the sense of it being something to get around something which is poorly implemented/structured - a resorting to convoluted slight-of-hands to pull off a task. hack must have heaps of different meanings tho. like a 'quick hack', which i would consider as a brute force approach to achieveing something where dynamicity and elegance is not considered.

yeah, it probably is a viable soln to get around the problem, one i will use next time round - but it sux that we should have to do this?

mark_wilkins
07-01-2003, 01:45 PM
Generally, it's easier to use arrays than matrices for storing arbitrary collections of data. Matrices are really designed to be used for one thing: transforming vectors. In that context they are usually 3x3 or 4x4.

-- Mark

dunkel3d
07-01-2003, 11:20 PM
Thanks for the response, all.

:thumbsup:
S

CGTalk Moderation
01-15-2006, 12:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.