## digitalmars.D.learn - Math Libraries (and vectors, matrices, etc)

• Chris Pons (8/8) Mar 13 2012 Does D have a math library that defines, points, vectors and
• H. S. Teoh (14/17) Mar 13 2012 I'd like to know too.
• Dmitry Olshansky (5/18) Mar 13 2012 SciD worths a look, though never used nor had the need to:
• Chris Pons (3/31) Mar 13 2012 Thanks, I'll take a look. I'm new, so I might need some help
• Kiith-Sa (7/7) Mar 13 2012 SciD is a scientific math library providing vectors/matrices of
• Chris Pons (3/10) Mar 13 2012 Oops, I didn't see the replies, after my last message. I'll check
• David (3/9) Mar 14 2012 I think Manu is atm working on std.simd, when he tells me it's useable
• Chris Pons (3/36) Mar 13 2012 SciD looks nice, but it seems to be a bit too complicated for my
• sclytrack (39/61) Mar 13 2012 struct CMatrix(T) //CMatrix
• sclytrack (15/26) Mar 13 2012 For vectors I'd propose
• sclytrack (3/6) Mar 13 2012 Stride!(T) row()
"Chris Pons" <cmpons gmail.com> writes:
```Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot
product, cross product, etc)?

I'm starting my next game and I would like to know what my
options are. I plan on using SDL, I'm not exactly into OpenGL
yet, since I'm new and I only wish to work in 2D.

Nonetheless, I would prefer to get acquainted with using linear
algebra formally in games before I move to 3D.
```
Mar 13 2012
"H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
```On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now I'm stuck at
deciding how best to represent matrices and vectors in a generic way. My
usage will be significantly different from game programming, though,
'cos I'll be dealing with arbitrary-dimensioned vectors and matrices,
not just your typical 2D/3D vector (or 4D homogenous).

But it'd be nice if both can be handled generically without crippling
performance losses in the 2D/3D case for game dev.

T

--
Claiming that your operating system is the best in the world because
more people use it is like saying McDonalds makes the best food in the
world. -- Carl B. Constantine
```
Mar 13 2012
Dmitry Olshansky <dmitry.olsh gmail.com> writes:
```On 14.03.2012 0:03, H. S. Teoh wrote:
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now I'm stuck at
deciding how best to represent matrices and vectors in a generic way. My
usage will be significantly different from game programming, though,
'cos I'll be dealing with arbitrary-dimensioned vectors and matrices,
not just your typical 2D/3D vector (or 4D homogenous).

But it'd be nice if both can be handled generically without crippling
performance losses in the 2D/3D case for game dev.

T

SciD worths a look, though never used nor had the need to:

--
Dmitry Olshansky
```
Mar 13 2012
"Chris Pons" <cmpons gmail.com> writes:
```Thanks, I'll take a look. I'm new, so I might need some help
properly building this. I will post back if I have any problems.

On Tuesday, 13 March 2012 at 20:06:13 UTC, Dmitry Olshansky wrote:
On 14.03.2012 0:03, H. S. Teoh wrote:
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot
product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now
I'm stuck at
deciding how best to represent matrices and vectors in a
generic way. My
usage will be significantly different from game programming,
though,
'cos I'll be dealing with arbitrary-dimensioned vectors and
matrices,
not just your typical 2D/3D vector (or 4D homogenous).

But it'd be nice if both can be handled generically without
crippling
performance losses in the 2D/3D case for game dev.

T

SciD worths a look, though never used nor had the need to:

```
Mar 13 2012
"Kiith-Sa" <42 theanswer.com> writes:
```SciD is a scientific math library providing vectors/matrices of
arbitrary
sizes, but not useful at all for game development.

See gl3n for a game-oriented vector/matrix library:
https://bitbucket.org/dav1d/gl3n

Also, AFAIK, Manu is working on what should end up being
a Phobos module for game-oriented matrices/vectors.
```
Mar 13 2012
"Chris Pons" <cmpons gmail.com> writes:
```Oops, I didn't see the replies, after my last message. I'll check
this out. Thanks!
On Tuesday, 13 March 2012 at 20:34:54 UTC, Kiith-Sa wrote:
SciD is a scientific math library providing vectors/matrices of
arbitrary
sizes, but not useful at all for game development.

See gl3n for a game-oriented vector/matrix library:
https://bitbucket.org/dav1d/gl3n

Also, AFAIK, Manu is working on what should end up being
a Phobos module for game-oriented matrices/vectors.

```
Mar 13 2012
David <d dav1d.de> writes:
```Am 13.03.2012 21:34, schrieb Kiith-Sa:
SciD is a scientific math library providing vectors/matrices of arbitrary
sizes, but not useful at all for game development.

See gl3n for a game-oriented vector/matrix library:
https://bitbucket.org/dav1d/gl3n

Also, AFAIK, Manu is working on what should end up being
a Phobos module for game-oriented matrices/vectors.

I think Manu is atm working on std.simd, when he tells me it's useable
gl3n will get simd support ;)
```
Mar 14 2012
"Chris Pons" <cmpons gmail.com> writes:
```SciD looks nice, but it seems to be a bit too complicated for my
use.  Are there any other alternatives?

On Tuesday, 13 March 2012 at 20:14:14 UTC, Chris Pons wrote:
Thanks, I'll take a look. I'm new, so I might need some help
properly building this. I will post back if I have any problems.

On Tuesday, 13 March 2012 at 20:06:13 UTC, Dmitry Olshansky
wrote:
On 14.03.2012 0:03, H. S. Teoh wrote:
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot
product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now
I'm stuck at
deciding how best to represent matrices and vectors in a
generic way. My
usage will be significantly different from game programming,
though,
'cos I'll be dealing with arbitrary-dimensioned vectors and
matrices,
not just your typical 2D/3D vector (or 4D homogenous).

But it'd be nice if both can be handled generically without
crippling
performance losses in the 2D/3D case for game dev.

T

SciD worths a look, though never used nor had the need to:

```
Mar 13 2012
sclytrack <sclytrack hotmail.com> writes:
```On 03/13/2012 09:06 PM, Dmitry Olshansky wrote:
On 14.03.2012 0:03, H. S. Teoh wrote:
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now I'm stuck at
deciding how best to represent matrices and vectors in a generic way. My

struct CMatrix(T)			//CMatrix
{
T [] data;
size_t rows;
size_t cols;
size_t rowStep;

Stride(T) row()
{
}

T [] rowArray()
{

}

//no colArray

}

struct LMatrix(T)			//Lapack Matrix
{
T [] data;
size_t rows;
size_t cols;
size_t colStep;
}

Above are "storage types" of the matrix. They can be rectangular or
triangular.

I'd move the "matrix shape" to the operation. Because most of the time
you already know the shape.

aadd_upperTriangular_upperTraingular( result, a, b);

So the operation for the upperTriangular "shape" can be applied to the
generic rectangular "storage" type. I know nobody likes the underscore
syntax but I can't come up with anything else.

Also separate the Lapack Matrix from the conventional CMatrix in other
modules.

I'd stick to conventional routines for adding subtracting and not the
build in binary operators like +.

-----

In scid the colStep or leading address of a is an alias. I think this
should not be so.

usage will be significantly different from game programming, though,
'cos I'll be dealing with arbitrary-dimensioned vectors and matrices,
not just your typical 2D/3D vector (or 4D homogenous).

But it'd be nice if both can be handled generically without crippling
performance losses in the 2D/3D case for game dev.

T

SciD worths a look, though never used nor had the need to:

```
Mar 13 2012
sclytrack <sclytrack hotmail.com> writes:
```On 03/13/2012 09:30 PM, sclytrack wrote:
On 03/13/2012 09:06 PM, Dmitry Olshansky wrote:
On 14.03.2012 0:03, H. S. Teoh wrote:
On Tue, Mar 13, 2012 at 08:25:49PM +0100, Chris Pons wrote:
Does D have a math library that defines, points, vectors and
matrices including the appropriate functions(addition, dot product,
cross product, etc)?

I'd like to know too.

I have a medium-sized D project in the works, but right now I'm stuck at
deciding how best to represent matrices and vectors in a generic way. My

For vectors I'd propose

struct Stride(T)
{
T [] data;
size_t step;
}

For fixed size vectors, just use "float [3] v;"

I'd only use below if you can force it into phobos. If not use above.

struct Vec3(T)
{
T x;
T y;
T z;
}
```
Mar 13 2012
sclytrack <sclytrack hotmail.com> writes:
``` Stride(T) row()
{
}

Stride!(T) row()
{
}
```
Mar 13 2012