def test_plane_from_points_order(self): points = np.array([ [1, 0, 0], [0, math.sqrt(1.25), 0], [-1, 0, 0], ]) plane = Plane.from_points(*points) expected_v = np.array([0, 0, 1]) np.testing.assert_array_equal(plane.normal, expected_v)
def test_plane_from_points(self): points = np.array([ [1, 1, 1], [-1, 1, 0], [2, 0, 3], ]) plane = Plane.from_points(*points) a, b, c, d = plane.equation plane_equation_test = [a * x + b * y + c * z + d for x, y, z in points] np.testing.assert_array_equal(plane_equation_test, [0, 0, 0]) projected_points = [plane.project_point(p) for p in points] np.testing.assert_array_almost_equal(projected_points, points)
def create_triangular_prism(p1, p2, p3, height): ''' Return a Mesh which is a triangular prism whose base is the triangle p1, p2, p3. If the vertices are oriented in a counterclockwise direction, the prism extends from behind them. ''' from blmath.geometry import Plane base_plane = Plane.from_points(p1, p2, p3) lower_base_to_upper_base = height * -base_plane.normal # pylint: disable=invalid-unary-operand-type vertices = np.vstack(([p1, p2, p3], [p1, p2, p3] + lower_base_to_upper_base)) faces = np.array([ [0, 1, 2], # base [0, 3, 4], [0, 4, 1], # side 0, 3, 4, 1 [1, 4, 5], [1, 5, 2], # side 1, 4, 5, 2 [2, 5, 3], [2, 3, 0], # side 2, 5, 3, 0 [5, 4, 3], # base ]) return Mesh(v=vertices, f=faces)