From 5340592791276710425
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,94e9c2bbb0060b48
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-08-14 14:29:04 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: ros0230@iperbole.bologna.it (Natale Fietta)
Newsgroups: comp.std.c++
Subject: Re: Proposals for small vectors?
Date: Wed, 14 Aug 2002 21:28:36 GMT
Organization: NETTuno
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <3d5a1dd2.2181932@news.iperbole.bologna.it>
References: <87wurryywb.fsf@grue.ucsd.edu> <87hei3zkxb.fsf@grue.ucsd.edu>
Reply-To: ros0230@iperbole.bologna.it
X-Trace: mail2news.demon.co.uk 1029360522 mail2news:14215 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ncar.ucar.edu
NNTP-Posting-Date: 14 Aug 2002 09:22:37 GMT
X-Newsreader: Forte Free Agent 1.21/32.243
Lines: 187
Xref: archiver1.google.com comp.std.c++:13254

On Sat, 10 Aug 2002 11:46:39 GMT, Walter Landry <wlandry@ucsd.edu>
wrote:

>Natale Fietta wrote:
>> Please, define "simple equation".
>
>What I meant is do your equations tend to look like
>
>  A=B*C;
>  D=A+E*F;
>
>or is it more like
>
>  A=(B*C + D*F)/(B*E - D*B) + B*B - F*C;

With matrixes i usually write long expression breaked in little token
to get rid of unnecessary temporaries, so i can be happy if the
library can automagically eliminate temporary for me :-)

My expressions often are not a simple sequence of arithmetic
operators, but are intermixed with various function calls, this way:

A=Normalize( CrossProduct((A - B), (C - B)) );
a=DotProduct( Vector(A.z, A.y, -A.x), Normalize(B - A) );

It is very infrequent for me to mix matrixes and vectors in the same
expression, i usually have strong separation betwen them, instead i do
often mix float in the same expression, this way:

//in this example lower-case are floats, upper-case are vectors or
matrixes
A=(u*B + v*C) / t;

The only very frequent case i mix vector and matrixes is vector*matrix
multiplications, usually they are in the simplest form: U=V*M; or also
V*=M;
Note: for some API matrixes are transposed, so i must use M*V instead
of V*M. because using the wrong multiplication order can be a
difficult bug to find (and also a pain to write if the same program
must be compiled for both conventions) i usually define both V*M and
M*V to be equivalent to the only geometrically correct multiplication
for the currently selected API.
(i can hear mathematicians cry out with horror ;-)
This is very different form what a general purpose library can
reasonably do...

>Let me get this straight.  You have matrices of the form
>
>    A00 A01 A02 A03
>A=  A10 A11 A12 A13
>    A20 A21 A22 A23
>      0   0   0   1
>
>and you want to be able to multiply it by a vector
>
>  B=(B0 B1 B2 B3)
>to get C=A*B without actually doing any multiplies for the last
>element of C.

Not only, i also want to multiply two matrixes of this form using the
minimal needed number of operations, like as
C00 = A00*B00 + A01*B10 + A02*B20  instead of 
C00 = A00*B00 + A01*B10 + A02*B20 + A03*B30

>  B=(B0 B1 B2 B3)

It is worth noting that i prefer traditional names (with a geometrical
meaning) for vectors components, i do not access them using B[0] B[1]
B[2] but instead i use B.x, B.y B.z; this is far more readable for me
because i do think in terms of xyz, i am not interested in a vector
class without the ability to access components with a .x or .x() or
GetX() syntax or similar (the .x is my favourite).

> What I could do is something
>like
>
>  Index<'i',3> i;
>  Index<'j',4> j;
>
>  C(i)=A(i,j)*B(j);
>  C(3)=B(3);
>
>Where the template parameter '3' for Index 'i' is so that only the
>first three elements of C are computed.

I've had a quick look at FTensor library, tensor concept is very
interesting (it is new to me) but for my work it is an unneeded
complexity; i am very happy with unrelated vector and matrix classes,
i do use them in very different modes and do not have any need to
generalize them in a tensorial way...

Also note that often videogames console do not have very standard
conforming C++ compilers, so a library that do not work even on
MSVC++6 in out of my range of usefulness.
i strongly hope in a near future all C++ compilers can be standard
conforming, but i must work with current compilers :-(

>For matrix*matrix operations, if you're using 3x4 matrices, you could
>do something like

The strange thing is that being 3x4 (widely used in past, but less
often now) a space optimized form of 4x4, i do want to be able to
multiply them, i mean multiply a 3x4 matrix for a 3x4 matrix obtaining
as result another 3x4 matrix (another cry from mathematicians ;-)

>  Index<'i',3> i;
>  Index<'j',4> j;
>  Index<'k',3> k;
>
>  D(i,j)=A(i,k)*B(k,j);
>
>and it would do the minimum number of multiplies.  In addition, this
>D(i,j) would still work with the vector*matrix example above.

Sorry, this tensorial formalism only confuse me... :-(

>> Also we often use 3-vector to represent normalized 4-vector in
>> homogeneous coordinates, so we can multiply a 3-vector by a 4x4
>> matrix and obtain another 3-vector as result. (i suppose this sound
>> very odd to mathematicians).
>
>I think you want to be able to multiply
>
>  A00 A01 A02 A03   B0
>  A10 A11 A12 A13 * B1
>  A20 A21 A22 A23   B2
>    0   0   0   1    1
>
>without storing that last B3=1.  Instead of simply
>  C=A*B

Yes, but i do also use (less often) this:

 A00 A01 A02 A03   B0
 A10 A11 A12 A13 * B1
 A20 A21 A22 A23   B2
 A30 A31 A32 A33    1

performing the full multiplication and returning as result:
Vector(C.x/C.w, C.y/C.w, C.z/C.w) //C.w is C3

>Well, it seems like you can do most of what you need with a general
>tool.  I will admit that it is not quite as simple as a specialized
>library.  In cases where this matters, though, it shouldn't be
>difficult to define your own inline functions.  It will at least free
>you from having to construct the basic operations.

For me it is *far* more easy to construct all the basic operations
than to understand and use a tensor library...

>If, as John Nagle says, the algebra3 library is considered useful,
>then a more powerful and flexible interface with equivalent
>optimizations should work fine for most people.

As i said in my first post in this thread, i am talking only about my
personal experience and needs; i am not surprised John Neagle has
slightly (or also not so slightly) different needs than me; we do work
in differents niche of the geometric community.

I dislike some of algebra3 design, in particular the missing x y z
names for vector components, and various missing optimizations.

>I've also rooted around the Quake II source code a little, and it
>seems like that code in particular could benefit greatly from a
>standard vector and matrix toolkit.

Well, first of all this particular code is not a good example of C++
programming, because it is written in C...

In any case i must make my position more clear: i think a good quality
standard vector/matrix library can be a great benefit for the graphic
community, but i do think the needs are too peculiar and specific to
include a similar library in the C++ standard or boost libraries.

The library i do dream of has some peculiarity (for example the
mentioned V*M==M*V) that can be only cause of unexpected bugs for more
general purpose applications...

Regards,
Natale Fietta

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



