Rounding Issues With A Matrix

Rounding Issues With A Matrix

Joshua.mursic
Advocate Advocate
1,286 Views
6 Replies
Message 1 of 7

Rounding Issues With A Matrix

Joshua.mursic
Advocate
Advocate

I am getting this error when trying to perform a transform on a sketch.

 

 

RuntimeError: 2 : InternalValidationError : xlMat->isValidNonScaledTransformMatrix()

 

 

 

I made this to try and force the matrix to by valid

 

 

def forcePlanar(matrix:adsk.core.Matrix3D):
    o,x,y,z = matrix.getAsCoordinateSystem()

    app.log("Original Matrix")
    app.log(f'asArray: {matrix.asArray()}')
    app.log(f'X length = {x.length}')
    app.log(f'Y length = {y.length}')
    app.log(f'Z length = {z.length}')
    app.log(f'XY Angle = {math.degrees(x.angleTo(y))}')
    app.log(f'XZ Angle = {math.degrees(x.angleTo(z))}')
    app.log(f'YZ Angle = {math.degrees(y.angleTo(z))}')
    app.log(" ")

    x.normalize()
    y.normalize()
    z.normalize()

    xVec = y.crossProduct(z)
    if math.degrees(xVec.angleTo(x)) > 90:
        xVec.scaleBy(-1)
        xVec.normalize()
    
    yVec = xVec.crossProduct(z)
    if math.degrees(yVec.angleTo(y)) > 90:
        yVec.scaleBy(-1)
        yVec.normalize()
    
    zVec = xVec.crossProduct(yVec)
    if math.degrees(zVec.angleTo(z)) > 90:
        zVec.scaleBy(-1)
        zVec.normalize()

    xVec.normalize()
    yVec.normalize()
    zVec.normalize()

    matrix = adsk.core.Matrix3D.create()
    matrix.setWithCoordinateSystem(o,xVec,yVec,zVec)

    app.log("Fixed Matrix")
    app.log(f'asArray: {matrix.asArray()}')
    app.log(f'X length = {xVec.length}')
    app.log(f'Y length = {yVec.length}')
    app.log(f'Z length = {zVec.length}')
    app.log(f'XY Angle = {math.degrees(xVec.angleTo(yVec))}')
    app.log(f'XZ Angle = {math.degrees(xVec.angleTo(zVec))}')
    app.log(f'YZ Angle = {math.degrees(yVec.angleTo(zVec))}')

    return matrix

 

 

 

But I am still getting this error:

 

 

 Original Matrix
 asArray: (-0.9866242022022309, 0.1492357286775443, -0.06558491377514467, 2.5736278824387266, 0.15800404365975573, 0.9744559705989259, -0.15959412129295647, -0.7649845830225152, -0.040092465825598715, 0.16782210417637858, 0.9850016931629284, 1.7089296320501064, 0.0, 0.0, 0.0, 1.0)
 X length = 0.9999999999999997
 Y length = 0.9999999999999998
 Z length = 0.9999999999999999
 XY Angle = 90.0
 XZ Angle = 90.0
 YZ Angle = 90.0
  
 Fixed Matrix
 asArray: (-0.9866242022022313, 0.14923572867754434, -0.06558491377514467, 2.5736278824387266, 0.15800404365975573, 0.9744559705989261, -0.1595941212929565, -0.7649845830225152, -0.04009246582559872, 0.1678221041763786, 0.9850016931629284, 1.7089296320501064, 0.0, 0.0, 0.0, 1.0)
 X length = 1.0
 Y length = 1.0
 Z length = 0.9999999999999999
 XY Angle = 90.0
 XZ Angle = 90.0
 YZ Angle = 90.0

Failed:
Traceback (most recent call last):
line 346, in transformSketch:
sketch.transform = matrix
^^^^^^^^^^^^^^^^

File "C:\......\adsk\fusion.py", line 45318, in _set_transform
return _fusion.Sketch__set_transform(self, value)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: 2 : InternalValidationError : xlMat->isValidNonScaledTransformMatrix()

 

 

 

Am I doing something wrong here? I am not sure how to stop the vectors from being ever so slightly not unit length.

0 Likes
Accepted solutions (1)
1,287 Views
6 Replies
Replies (6)
Message 2 of 7

Joshua.mursic
Advocate
Advocate

I also just got an instance where this was the logged fixed matrix and it still errored? Any help would be greatly appreciated, I have no idea why this would give an error.

 Fixed Matrix
 asArray: (-0.28937833718712835, -0.92790170939954, 0.23507146926036046, -1.8945223767122557, -0.9572147900317696, 0.2804771032288191, -0.07122106646776495, -0.058936886759475254, -0.00015398457080906255, 0.2456237208776513, 0.9693652376844187, 0.890460203796084, 0.0, 0.0, 0.0, 1.0)
 X length = 1.0
 Y length = 1.0
 Z length = 1.0
 XY Angle = 90.0
 XZ Angle = 90.0
 YZ Angle = 90.0

 

Here is how I am transforming the sketches

for sketch in occurrence.component.sketches:
     mat = sketch.transform
     mat.transformBy(transformationMatrix)
     mat = forcePlanar(mat)
     sketch.transform = mat
0 Likes
Message 3 of 7

kandennti
Mentor
Mentor
Message 4 of 7

Joshua.mursic
Advocate
Advocate

it is in direct modelling mode

0 Likes
Message 5 of 7

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

I also get the same error trying to transform a component.

Something is not good in that matrix.

 

How did you get that matrix?

There is a way to rebuild it from scratch (like rotate N° on X axis, then M° o Y, and so on) and not from the values you posted previously?

 

Regards,

Jorge

0 Likes
Message 6 of 7

Joshua.mursic
Advocate
Advocate

I am not very familiar with matrices yet, but I think that the issue might be something like this. Where the angles are all 90 and the vectors are of unit length, but the X vector is pointing in the negative direction. I am not sure if this makes a difference or not. I am going to change the functions that are creating the transformation matrices. Thank you everyone for the help!

 

Joshuamursic_0-1727623902056.png

 

 

0 Likes
Message 7 of 7

kandennti
Mentor
Mentor

@Joshua.mursic -San.

 

I haven't tried it, but I don't think Fusion360 supports left-handed coordinate systems.

0 Likes