Example #1
0
def _normalise(input_vector: QVector3D) -> Tuple[QVector3D, float]:
    """
    Normalise to unit vector

    :param input_vector: Input vector
    :return: Unit vector, magnitude
    """
    magnitude = input_vector.length()
    if magnitude == 0:
        return QVector3D(0.0, 0.0, 0.0), 0.0

    return input_vector.normalized(), magnitude
Example #2
0
 def calculate_vertices(axis_direction: QVector3D, height: float,
                        radius: float) -> np.ndarray:
     """
     Given cylinder axis, height and radius, calculate the base centre, base edge and top centre vertices
     :param axis_direction: axis of the cylinder (not required to be unit vector)
     :param height: height of the cylinder
     :param radius: radius of the cylinder
     :return: base centre, base edge and top centre vertices as a numpy array
     """
     axis_direction = axis_direction.normalized()
     top_centre = axis_direction * height / 2.0
     base_centre = axis_direction * height / -2.0
     radial_direction = get_an_orthogonal_unit_vector(
         axis_direction).normalized()
     base_edge = base_centre + (radius * radial_direction)
     vertices = np.vstack((
         qvector3d_to_numpy_array(base_centre),
         qvector3d_to_numpy_array(base_edge),
         qvector3d_to_numpy_array(top_centre),
     ))
     return vertices