CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
3.27k stars 295 forks source link

Matrix Class rotateX, rotateY and rotateZ methods assume the provide angle is in radians #787

Open gumyr opened 3 years ago

gumyr commented 3 years ago

The rotateX, rotateY and rotateZ methods of the Matrix class assume the angle of rotation is in radians not degrees like all of the other cadquery methods.

import cadquery as cq
import math

print("Unit X Vector rotated about the Z axis by 30 degrees:(",math.cos(math.radians(30)),",",math.sin(math.radians(30)),",0)")
unitXVector = cq.Vector(1,0,0)
m0 = cq.Matrix()
m0.rotateZ(30)
rotatedUnitXVector = m0.multiply(unitXVector)
print("Unit X Vector rotated by rotateZ(30):",rotatedUnitXVector)

m1 = cq.Matrix()
m1.rotateZ(math.radians(30))
rotatedUnitXVector = m1.multiply(unitXVector)
print("Unit X Vector rotated by rotateZ(math.radians(30)):",rotatedUnitXVector)

There is one line fix:

    def _rotate(self, direction: gp_Ax1, angle: float):

        new = gp_Trsf()
        # new.SetRotation(direction, angle)
        new.SetRotation(direction, math.radians(angle))

        self.wrapped = self.wrapped * gp_GTrsf(new)

However, this will break backwards compatibility.

adam-urbanczyk commented 3 years ago

Why do you actually want to use the Matrix class? Unless you want to do some low level things (extend CQ) I'd advise against it.

gumyr commented 3 years ago

My immediate need was the creation of rotation functions for the cq.Vector class. However, the affine transformation matrix is an incredibly powerful component of linear algebra allowing for combinations of rotation, translations, skew, etc. Who knows what clever things users might do with it in the future?

adam-urbanczyk commented 3 years ago

Especially with things like skew your quickly run into kernel issues.