Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in mult_matrix_4 #13

Open
telamonian opened this issue Jun 10, 2013 · 1 comment · May be fixed by #14
Open

Bug in mult_matrix_4 #13

telamonian opened this issue Jun 10, 2013 · 1 comment · May be fixed by #14

Comments

@telamonian
Copy link

It seems that the mult_matrix_4 function is showing some odd behavior. I defined a 4x4 transformation matrix that should move a shape up by 3 units and then rotate that shape by pi/7 radians about the point (0, 3.5, 0) and about the axis (0,0,1):

tmat = [[ 0.90096887 -0.43388374  0.          0.21694187]
        [ 0.43388374  0.90096887  0.          3.04951557]
        [ 0.          0.          1.          0.        ]
        [ 0.          0.          0.          1.        ]]

I then flattened the matrix in row-major format, as mult_matrix_4 seems to require:

formatted_tmat = [0.9009688679024191, -0.4338837391175581, 0.0, 0.21694186955877903, 0.4338837391175581, 0.9009688679024191, 0.0, 3.0495155660487905, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]

I then made a box in pyPolyCSG and applied the transformation:

a = csg.box(3.0,1.0,1.0)
b = a.mult_matrix_4(formatted_tmat)

In terms of the first 4 vertices (as returned by b.get_vertices()), I get what seems to be a translation + dilation of my shape:

[0.21694187, 3.04951557, 0]
[1.61819726, 3.04951557, 0]
[1.61819726, 4.38436817, 0]
[0.21694187, 4.38436817, 0] 

image

I was expecting to get a translation + rotation of the box, as I do when I multiply the vertex coordinates by the transformation matrix by hand:

[0.216942, 3.04952, 0.]
[2.91985, 4.35117, 0.]
[2.48596, 5.25214, 0]
[-0.216942, 3.95048, 0]

image

Do you know what's causing the discrepancy, and do you know how I can fix it?

@telamonian
Copy link
Author

There seems to have been an error in polyhedron polyhedron_multmatrix4::operator()( const polyhedron &in ), the function that handled the matrix multiplication for mult_matrix_4. One of the indices in the matrix multiplication routine itself was wrong. I fixed it, and also simplified the function somewhat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant