Skip to content

add constructor for matrices from diagonal #120

Closed
@jimy-byerley

Description

@jimy-byerley

Hello,
thanks again for maintaining that wonderful module.
I was wondering if it could be possible to implement an additional constructor for matrices.

Right now it's already possible to initialize a diagonal matrix from a user-given value:

>>> mat3(5)
mat3x3(( 5, 0, 0 ), ( 0, 5, 0 ), ( 0, 0, 5 ))

However there is no shorthand to create one with custom elements on the diagonal. I was thinking to something like this:

>>> mat3(1,2,3)    # option 1
mat3x3(( 1, 0, 0 ), ( 0, 2, 0 ), ( 0, 0, 3 ))

>>> mat3(vec3(1,2,3))   # options 2
mat3x3(( 1, 0, 0 ), ( 0, 2, 0 ), ( 0, 0, 3 ))

>>> diag(1,2,3)    # options 3
mat3x3(( 1, 0, 0 ), ( 0, 2, 0 ), ( 0, 0, 3 ))

My current way to do that job is of course:

m = mat3()
m[0,0] = 1
m[1,1] = 2
m[2,2] = 3

What do you think of this ?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions