How to calculate the Matrix scale? [SOLVED]



  • On 25/02/2015 at 06:45, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:    
    Platform:      
    Language(s) :     C++  ;   PYTHON  ;

    ---------
    Hi,

    I know the matrix scale is determined by the length of v1, v2 and v3.

    def get_matrix_scale(mat) :
        r""" Returns the scale component from a Matrix. """
      
        return c4d.Vector(
            mat.v1.GetLength(),
            mat.v2.GetLength(),
            mat.v3.GetLength())
    

    But how can I figure if the scale is negative or positive?

    Btw, the information in the Python documentation is not correct. If you use the normalized version
    of v1, v2 and v3, you'll just get a scale of 1, 1, 1.

    Originally posted by xxxxxxxx

    Getting the scale is just a matter of measuring the length of each of the axis vectors:

    m = obj.GetMg()
    scale = c4d.Vector( m.v1.GetNormalized(),
    m.v2.GetNormalized(),
    m.v3.GetNormalized())

    Thanks,
    Niklas



  • On 25/02/2015 at 07:44, xxxxxxxx wrote:

    Howdy,

    You can check the dot product of the axis and the cross product of the other 2 axes. 😉
    Remember:
    X cross Y = Z
    Y cross Z = X
    Z cross X = Y

    Adios,
    Cactus Dan



  • On 02/03/2015 at 09:45, xxxxxxxx wrote:

    Hey Dan, thanks for your reply. I'm trying to make sense of your tip, but it just won't make click. 😪
    Could you enlighten me a bit more?



  • On 02/03/2015 at 10:42, xxxxxxxx wrote:

    The scales on each axial-basis vectors in the matrix are just the lengths of each vector v1,v2,v3 as you noted.

    To determine if there is a reflection ('negative' scaling), you need to get the determinant of the matrix.  A positive value is orientation-preserving while a negative value is orientation-reversing (mirror/flip/reflection).  Just because any of the axial-basis vectors is negative doesn't imply negative scaling.



  • On 02/03/2015 at 10:54, xxxxxxxx wrote:

    Howdy,

    If the dot product is equal to 0, then the vectors are at 90º to each other
    If the dot product is greater than 0, then the vectors are generally pointing in the same direction
    If the dot product is less than 0, then the vectors are generally pointing in opposite directions.

    Let's take the X axis for example:
    Y cross Z will give you a positive X scale vector. If the dot product of the actual X axis and the positive X scale vector is greater than 0 then the scale of the X axis is positive. If the dot product is less than 0, then the scale of the X axis is negative.

    Adios,
    Cactus Dan



  • On 02/03/2015 at 11:06, xxxxxxxx wrote:

    Hi Robert, thanks for chiming in. I know how to compute the determinant of a Matrix, but that only gives
    me one value. I wouldn't be able to deduce which components would be inverted from only one value?



  • On 02/03/2015 at 11:09, xxxxxxxx wrote:

    Originally posted by xxxxxxxx

    Howdy,

    If the dot product is equal to 0, then the vectors are at 90º to each other
    If the dot product is greater than 0, then the vectors are generally pointing in the same direction
    If the dot product is less than 0, then the vectors are generally pointing in opposite directions.

    Let's take the X axis for example:
    Y cross Z will give you a positive X scale vector. If the dot product of the actual X axis and the positive X scale vector is greater than 0 then the scale of the X axis is positive. If the dot product is less than 0, then the scale of the X axis is negative.

    Adios,
    Cactus Dan

    That is starting to make sense to me, I'm going to try something and report back. Thanks :)



  • On 06/03/2015 at 05:11, xxxxxxxx wrote:

    I'm not really getting there.. When either V2 or V3 is inverted, V2.Cross(V3) will yield a vector pointing
    into the opposite direction of V1 assuming V1 is not inverted, and in the same direction assuming V1
    is inverted.

    I appreciate the hints and I usually like finding the solution by myself by applying the tips instead of just
    getting it  in a reply, but I think I can't come with it this time. 😊



  • On 06/03/2015 at 11:24, xxxxxxxx wrote:

    Hi Niklas,

    this is an unsolvable equation, you can detect if there is a negative axis "x cross y = z, compare z with z" , but you won't know which axis is negative "x or y or z!!" , if 2 axes are negative, this even won't appear!! "it can be a rotation"

    here is a simple link:
    http://answers.unity3d.com/questions/689997/need-help-supporting-negative-values-when-extracti.html



  • On 06/03/2015 at 12:20, xxxxxxxx wrote:

    Howdy,

    Mohamed is correct. My post was only to determine whether or not the matrix has a negative scale on one of it's axes.

    You cannot calculate a precise 3 axis positive/negative scale for a matrix without having some sort of starting reference, which is probably why an object stores its scale in a vector to be used for calculating the matrix.

    Adios,
    Cactus Dan



  • On 07/03/2015 at 04:32, xxxxxxxx wrote:

    Oh my. I thought that would be deducable from the Matrix somehow and didn't think it would be
    stored separately within the object. Using BaseObject::GetAbsScale() now.

    Thanks Mohamed and Cactus. :-)



  • On 09/03/2015 at 13:18, xxxxxxxx wrote:

    Hi,

    It looks like you guys solved the issue.  It's fun to see the C4D plugin dev community sharing knowledge, and I often learn a thing or two from these topics!  I'll close it as solved.

    Joey Gaspe
    SDK Support Engineer


Log in to reply