View Issue Details

IDProjectCategoryView StatusLast Update
0000623FreeCADFeaturepublic2012-03-12 09:15
Reportershoogen Assigned Towmayer  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version0.12 
Target VersionFixed in Version0.13 
Summary0000623: Matrix and Vector API extension
Description1. A Matrix should be exposed to python via a subscriptable or offer an interator.
possible Solution: implement
 Py::List MatrixPy::getA(void) const;
 void MatrixPy::setA(Py::List /*arg*/);

2. Expose transpose function(void Matrix4D::transpose (void)) to python.
3. Offer a function for the determinant of the 3x3 submatrix (returns double)
4. Offer a function to check for an ortonormal 3x3 submatrix
   M(3x3)*Transpose(M(3x3)) == UnityMat (returns bool)
5. Overload the python operators (==) and (!=) for Matrix and Vector (compare elementwise)
TagsNo tags attached.
FreeCAD Information

Activities

shoogen

2012-03-06 05:56

developer   ~0001713

Name of function 4 has to be orthogonal.
6. Add a function 'isSpecialOrthogonal' meaning: isOrthogonal && det(M3x3)==1

Jriegel

2012-03-06 06:08

administrator   ~0001714

something for our math wiz..

shoogen

2012-03-07 05:53

developer   ~0001717

I've implemented objectives 3,4 and 6 in python.
http://forum.freecadweb.org/viewtopic.php?f=3&t=2324&p=17201#p17201
To me it would be fine just get (1)Matrix.A and (5)(Matrix == Matrix) fixed and then close the ticket.

galou_breizh

2012-03-07 21:32

reporter   ~0001721

I think there is a small bug, so small that I didn't want to open a mantis for this:

m = FreeCAD.Matrix(); m.rotateZ(1) --> works

m = FreeCAD.Matrix().rotateZ(1) --> doesn't work, (m is None)

------------
Self-compiled FreeCAD 0.13, Libs: 0.13R0697 (Git)

shoogen

2012-03-08 05:36

developer   ~0001723

Last edited: 2012-03-08 09:39

@galou: it isn't a bug in the API. It's a bug in the docs.

rotateZ() works in place and returns None.
So you lose the reference when doing m=m.rotateZ(1)

This way you will it least notice that it works in place.

galou_breizh

2012-03-09 07:50

reporter   ~0001733

@shoogen: you're right, actually, if I hadn't been so lazy, I would have written a feature request, so that Matrix.rotateZ and similar return self.

wmayer

2012-03-11 14:21

administrator   ~0001743

A couple of new methods have been added:
* transpose -- transposes this matrix
* transposed -- transposes a copy of the matrix
* isOrthogonal -- if the matrix is orthogonal it returns the multiple of the identity, otherwise 0
*submatrix -- accepts a dimenstion (int in range[1,4]) and returns the submatrix. This returns again a 4x4 matrix but set the values on the diagonal to 1 and the rest to 0
* operator == and !=
* implement the A attribute access

Example:
To see if a matrix describes a rotation you can test this with:
m = ...
abs(m.submatrix(3).isOrthognal()-1.0) < epsilon

wmayer

2012-03-11 14:23

administrator   ~0001744

Done in git 44147e71ab7076ef9483e5a3ffea402fe903fd68

shoogen

2012-03-11 18:46

developer   ~0001745

Last edited: 2012-03-12 05:00

The example is wrong:
Not taking the determinant into consideration, breaks this check for matrices including mirroring.
>>> m=FreeCAD.Matrix(-1) #Mirror x-axis
>>> abs(m.submatrix(3).isOrthogonal()-1.0) < epsilon
True #wrong
>>> abs(m.submatrix(3).isOrthogonal()-1.0) < epsilon and abs(m.submatrix(3).determinant()-1.0) < epsilon
False

wmayer

2012-03-12 07:10

administrator   ~0001748

OK, you're right!

shoogen

2012-03-12 07:24

developer   ~0001749

Last edited: 2012-03-12 07:51

#m=FreeCAD.Matrix(*[float.fromhex(e) for e in ['1','0','0','0','0', '0x1.6a09edbf8b9bbp-1', '-0x1.6a09edbf8b9bbp-1', '0', '0', '0x1.6a09edbf8b9bbp-1', '0x1.6a09edbf8b9bbp-1']]) #recreate IEEE 754 double
m=FreeCAD.Matrix(*[float(s) for s in ['1','0','0','0','0','0.707107','-0.707107','0','0','0.707107','0.707107','0','0','0','0','1']]) #original parser input
>>> m.multiply(m.transposed()).A
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0000006188980002, 0.0, 0.0, 0.0, 0.0, 1.0000006188980002, 0.0, 0.0, 0.0, 0.0, 1.0]
>>> m.determinant()
1.0000006188980002
>>> m.isOrthogonal() #there has to the a precsion/epsilon argument for the (trp[i][j] != 0.0) and (trp[i][j] != mult) comparrsions!!!!
0.0

wmayer

2012-03-12 09:15

administrator   ~0001750

Fixed in git 8a57a948d36a1f0714d9640c7798688832e625f5.

isOrthogonal() accepts an optional tolerance value. By default this is 1.0e-6

Issue History

Date Modified Username Field Change
2012-03-06 05:44 shoogen New Issue
2012-03-06 05:56 shoogen Note Added: 0001713
2012-03-06 06:08 Jriegel Note Added: 0001714
2012-03-06 06:09 Jriegel Status new => assigned
2012-03-06 06:09 Jriegel Assigned To => wmayer
2012-03-07 05:53 shoogen Note Added: 0001717
2012-03-07 21:32 galou_breizh Note Added: 0001721
2012-03-08 05:36 shoogen Note Added: 0001723
2012-03-08 09:39 shoogen Note Edited: 0001723
2012-03-09 07:50 galou_breizh Note Added: 0001733
2012-03-11 14:21 wmayer Note Added: 0001743
2012-03-11 14:23 wmayer Note Added: 0001744
2012-03-11 14:23 wmayer Status assigned => closed
2012-03-11 14:23 wmayer Resolution open => fixed
2012-03-11 14:23 wmayer Fixed in Version => 0.13
2012-03-11 18:46 shoogen Note Added: 0001745
2012-03-11 18:46 shoogen Status closed => feedback
2012-03-11 18:46 shoogen Resolution fixed => reopened
2012-03-11 18:49 shoogen Note Edited: 0001745
2012-03-12 04:59 shoogen Note Edited: 0001745
2012-03-12 04:59 shoogen Note Edited: 0001745
2012-03-12 05:00 shoogen Note Edited: 0001745
2012-03-12 07:10 wmayer Note Added: 0001748
2012-03-12 07:12 wmayer Status feedback => closed
2012-03-12 07:12 wmayer Resolution reopened => fixed
2012-03-12 07:24 shoogen Note Added: 0001749
2012-03-12 07:24 shoogen Status closed => feedback
2012-03-12 07:24 shoogen Resolution fixed => reopened
2012-03-12 07:27 shoogen Note Edited: 0001749
2012-03-12 07:29 shoogen Note Edited: 0001749
2012-03-12 07:34 shoogen Note Edited: 0001749
2012-03-12 07:51 shoogen Note Edited: 0001749
2012-03-12 09:15 wmayer Note Added: 0001750
2012-03-12 09:15 wmayer Status feedback => closed
2012-03-12 09:15 wmayer Resolution reopened => fixed