def _rotation_matrix(self) -> QMatrix4x4: """ :return: A QMatrix4x4 describing the rotation from the Z axis to the cylinder's axis """ default_axis = QVector3D(0, 0, 1) desired_axis = self.axis_direction.normalized() rotate_axis = QVector3D.crossProduct(desired_axis, default_axis) rotate_radians = acos(QVector3D.dotProduct(desired_axis, default_axis)) rotate_matrix = QMatrix4x4() rotate_matrix.rotate(degrees(rotate_radians), rotate_axis) return rotate_matrix
def createRotation(self, firstPoint, nextPoint): lastPos3D = self.projectToTrackball(firstPoint).normalized() currentPos3D = self.projectToTrackball(nextPoint).normalized() angle = acos(self.clamp(QVector3D.dotProduct(currentPos3D, lastPos3D))) direction = QVector3D.crossProduct(currentPos3D, lastPos3D) return angle, direction
def test_get_an_orthogonal_unit_vector_gives_an_orthogonal_vector(test_vector): result_vector = get_an_orthogonal_unit_vector(test_vector[0]) # Test orthogonal (dot product is zero) assert QVector3D.dotProduct(test_vector[0], result_vector) == approx(0)