Low dimensional matrices, vectors, quaternions and a cubic equation solver

Gareth Charnock gareth.tpc at gmail.com
Fri Apr 16 14:25:15 PDT 2010


Okay, here goes. I've collected together the basic functionality that 
would probably make a good starting point. As I've mentioned my code is 
very messy and has bits missing (e.g. I never had a use for the cross 
product but it's pretty important in general). I guess a good way to 
begin would be to write the pubic interfaces then start on the 
implementation.

Cubic Solvers:
General complex cubic solver with two algorithms (one requiring a 
complex cosine and and arcosine one using only +-*/ and roots). A 
special case cubic solver for the reduced cubic x^^3 + px - q = 0.

Quaternions:
opAdd, opSub, opMult(quaternion), opMult(vector), opDiv, Normalise, 
Normalized, conjugate, conjugated, toEulerAngles*, fromEulerAngles, 
this(real,i,j,k), this(angle,axis), getAngle(), getAxis()

*Currently I've only got a quaternion->euler angles routine that works 
in the ZYZ convention but I have read a paper that generalises my method 
to all valid axis conventions. Will probably impliment as something like:
toEulerAngles(string convention="XYZ")()

Vectors:
opAdd, opSub, opMult(scalar), opMult(vector)*, cross**, Normalise, 
Normalized, Length

* dot product. Would this be better named as dot()?
** 3D vectors only. Perhaps defining a cross product on the

Matrices:
opAdd, opSub, opMult(scalar), opMult(vector), opMult(matrix)**, Invert, 
Inverted, Orthogonalize, Orthogonalized, Reorthogonalize***, 
Reorthogonalized***, Det, Transpose, Transposed, Dagger*, Daggered*, 
Eigenvalues****, Eigenvectors****

*The hermitian conjugate/conjugate transpose. Reduces to the transpose 
for a real matrix
** Matrix-matrix multiplication doesn't commute. Could this be a problem 
when using operator notation?
*** Othogonalize assuming the matrix is nearly orthogonal already 
(possibly using some quick, approximate method such as a Taylor series)
**** I have a eigenvalue/vector solver for 3x3 matrices which seems 
reasonably stable but needs more testing.

Free functions:
MatrixToQuaternion
QuaternionToMatrix
+ code to allow easy printing to stdout/streams and such.

Andrei Alexandrescu wrote:
> On 04/15/2010 01:49 PM, Gareth Charnock wrote:
>> As a side effect of my PhD project I've got a collection of mathematical
>> classes. I'd be happy to collect them together, tidy them up and donate
>> them to phobos the authors are interested in including them. Matrices
>> and vectors in particular get reinvented all the time so I'm sure users
>> of D will appreciate them being there. Quaternions are probably somewhat
>> more specialised; they are most often used for representing rotations
>> (they have different advantages and disadvantages to rotation matrices).
>> I've also written a solver for cubic equations.
>>
>> The matrix and vector classes are of the sort where the dimension is
>> known at compile time and will probably be most useful for modelling
>> geometry. High dimensional matrices and vectors are probably better left
>> to a scientific library (I remember there was talk that one might be
>> being proposed).
>>
>> Would this sort of functionality be useful for phobos? At the moment, I
>> can't promise anything, I'm just trying to judge the interest should I
>> find time to look into it.
>>
>> Gareth Charnock
> 
> I think it would. Could you please post a brief list of features so 
> people can take a look?
> 
> Andrei



More information about the Digitalmars-d mailing list