Matrix scale

Tagged: ,

This topic contains 3 replies, has 3 voices, and was last updated by  Ethernaut 2 years, 4 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #5556

    Ethernaut
    Participant

    Maybe this is more of a math question than a M2 question: Is there a way to obtain the current scale factor from an existing AffineMat3?

    I know I can scale it using the Scale method, but I was wondering if that value can be extracted back without storing it in separate variables. It would just be a lot simpler in my case to pass a single matrix as an argument, as opposed to storing the current scale separately, then passing it as arguments to a different method in a different class.

    Thanks!

    #5558

    codifies
    Participant

    TLDR; I keep rotation and position in a couple of vectors – its not a waste to use an extra one for scale….

    its the diagonal values… (NB code isn’t using mx2’s affine matrix but my own version)

    for example if I want to create a scale matrix (to multiply with a matrix I want to scale)

    [/crayon]

    however once you then rotate a matrix etc, these values are going to get lost in the aggregation

    for example once you multiply it with a rotation matrix (which you could make like this)

    [/crayon]

    notice element 5 and 10….

    In general what I have tended to do is use a position vector and quat rotation – stored in a 4 element vector… (if you need scale use another vector to store scale – why not its not a great waste!)

    It used to be fashionable to say you should never store position and rotation ONLY in a matrix, if you only ever needed to add (or subtract!) incremental values from position and rotation, it has worked fine for me in the past – just bare in mind while you can easily extract position from a matrix BUT there are multiple axial rotations (and orders of rotation) that can give the same orientation.

    #5575

    abakobo
    Participant

    Maybe this is more of a math question than a M2 question: Is there a way to obtain the current scale factor from an existing AffineMat3?

    I have the following AffineMat3 Extension for my own use:

    [/crayon]

    It’s Based on this answer: http://stackoverflow.com/questions/4361242/extract-rotation-scale-values-from-2d-transformation-matrix

    But I had to change the rotation sign for Axis convention reasons I suppose.

    If you use only 1:1 scales you will have a consistent GetScale() value whatever transforms order you make. If not then the length of the scale will be consistent but you won’t be able to find your original scale if you made a rotation in the “wrong” order..

    #5579

    Ethernaut
    Participant

    Thanks for the replies, that is very helpful!

    codifies, I definitely keep a vector for each entities’ local scale, but I ran into the need to “extract” the scale when I’m dealing with hierarchies inheriting position, rotation and scale. The way I’m doing it, each entity has a matrix that expresses the transformation for all entities in the hierarchy up to that entity, so extracting the scale from that already existing matrix could be cleaner than searching Up the hierarchy, multiplying each local scale.

    The other case where I wanted it was to obtain the current scale from Mojo’s default window canvas. This is a situation where the scale is not set in my code (depends on window size and virtual resolution, etc.), so I couldn’t store it in a vector without obtaining it first.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.