def get_an_orthogonal_unit_vector(input_vector: QVector3D) -> QVector3D: """ Return a unit vector which is orthogonal to the input vector There are infinite valid solutions, just one is returned """ if np.abs(input_vector.z()) < np.abs(input_vector.x()): vector = QVector3D(input_vector.y(), -input_vector.x(), 0.0) return vector.normalized() return QVector3D(0.0, -input_vector.z(), input_vector.y()).normalized()
def check_coordinate_proc(self, pos: QVector3D): "check coordinate type and value" if not isinstance(pos, QVector3D): raise TypeError( "Given coordinates are not in type QVector3D: " + str(type(pos)) ) pvals = [pos.x(), pos.y(), pos.z()] if not all([isinstance(v, float) for v in pvals]): raise TypeError("Given coordinates do not have proper type float")
def validate_nonzero_qvector(value: QVector3D): if value.x() == 0 and value.y() == 0 and value.z() == 0: raise ValueError("Vector is zero length")
def qvector3d_to_numpy_array(input_vector: QVector3D) -> np.ndarray: return np.array([input_vector.x(), input_vector.y(), input_vector.z()]).astype(float)
def vector(self, new_vector: QVector3D): vector_as_np_array = np.array( [new_vector.x(), new_vector.y(), new_vector.z()]) self.file.set_attribute_value(self.dataset, CommonAttrs.VECTOR, vector_as_np_array)
def validate_nonzero_qvector(value: QVector3D): return value.x() == 0 and value.y() == 0 and value.z() == 0