Exemple #1
0
    def tilted(self, new_point, coplanar_point):
        """
        Create a new plane, tilted so it passes through `new_point`. Also
        specify a `coplanar_point` which the old and new planes should have
        in common.

        Args:
            new_point (np.arraylike): A point on the desired plane, with shape
                `(3,)`.
            coplanar_point (np.arraylike): The `(3,)` point which the old and
                new planes have in common.

        Returns:
            Plane: The adjusted plane.
        """
        vg.shape.check(locals(), "new_point", (3, ))
        vg.shape.check(locals(), "coplanar_point", (3, ))

        vector_along_old_plane = self.project_point(new_point) - coplanar_point
        vector_along_new_plane = new_point - coplanar_point
        axis_of_rotation = vg.perpendicular(vector_along_old_plane,
                                            self.normal)
        angle_between_vectors = vg.signed_angle(
            vector_along_old_plane,
            vector_along_new_plane,
            look=axis_of_rotation,
            units="rad",
        )
        new_normal = vg.rotate(
            self.normal,
            around_axis=axis_of_rotation,
            angle=angle_between_vectors,
            units="rad",
        )
        return Plane(point_on_plane=coplanar_point, unit_normal=new_normal)
Exemple #2
0
def test_project_point_to_line_stacked_both():
    p1 = np.array([5.0, 5.0, 4.0])
    p2 = np.array([10.0, 10.0, 6.0])
    along_line = p2 - p1

    common_kwargs = dict(
        reference_points_of_lines=np.array([p1, p1, p1]),
        vectors_along_lines=np.array([along_line, along_line, along_line]),
    )

    other_point_on_line = np.array([0.0, 0.0, 2.0])

    example_perpendicular_displacement = [
        k * vg.perpendicular(vg.normalize(along_line), vg.basis.x)
        for k in [0.1, 0.5, -2.0]
    ]

    example_points = np.vstack([p1, p2, other_point_on_line])
    expected_projected_points = np.vstack([p1, p2, other_point_on_line])

    np.testing.assert_array_almost_equal(
        project_point_to_line(points=example_points, **common_kwargs),
        expected_projected_points,
    )
    np.testing.assert_array_almost_equal(
        project_point_to_line(points=example_points +
                              example_perpendicular_displacement,
                              **common_kwargs),
        expected_projected_points,
    )
Exemple #3
0
def test_project_point_to_line():
    p1 = np.array([5.0, 5.0, 4.0])
    p2 = np.array([10.0, 10.0, 6.0])
    along_line = p2 - p1

    common_kwargs = dict(reference_points_of_lines=p1,
                         vectors_along_lines=along_line)

    np.testing.assert_array_almost_equal(
        project_point_to_line(points=p1, **common_kwargs), p1)
    np.testing.assert_array_almost_equal(
        project_point_to_line(points=p2, **common_kwargs), p2)

    other_point_on_line = np.array([0.0, 0.0, 2.0])
    np.testing.assert_array_almost_equal(
        project_point_to_line(points=other_point_on_line, **common_kwargs),
        other_point_on_line,
    )

    example_perpendicular_displacement = [
        k * vg.perpendicular(vg.normalize(along_line), vg.basis.x)
        for k in [0.1, 0.5, -2.0]
    ]
    for point_on_line in [p1, p2, other_point_on_line]:
        for displacement in example_perpendicular_displacement:
            np.testing.assert_array_almost_equal(
                project_point_to_line(points=point_on_line + displacement,
                                      **common_kwargs),
                point_on_line,
            )
Exemple #4
0
def test_project():
    p1 = np.array([5.0, 5.0, 4.0])
    p2 = np.array([10.0, 10.0, 6.0])
    line = Line.from_points(p1, p2)

    np.testing.assert_array_almost_equal(line.project(p1), p1)
    np.testing.assert_array_almost_equal(line.project(p2), p2)

    other_point_on_line = np.array([0.0, 0.0, 2.0])
    np.testing.assert_array_almost_equal(line.project(other_point_on_line),
                                         other_point_on_line)

    example_perpendicular_displacement = [
        k * vg.perpendicular(line.along, vg.basis.x) for k in [0.1, 0.5, -2.0]
    ]
    for p in [p1, p2, other_point_on_line]:
        for displacement in example_perpendicular_displacement:
            np.testing.assert_array_almost_equal(
                line.project(p + displacement), p)
Exemple #5
0
def test_project_stacked():
    p1 = np.array([5.0, 5.0, 4.0])
    p2 = np.array([10.0, 10.0, 6.0])
    line = Line.from_points(p1, p2)

    other_point_on_line = np.array([0.0, 0.0, 2.0])

    example_perpendicular_displacement = [
        k * vg.perpendicular(line.along, vg.basis.x) for k in [0.1, 0.5, -2.0]
    ]

    example_points = np.vstack([p1, p2, other_point_on_line])
    expected_projected_points = np.vstack([p1, p2, other_point_on_line])

    np.testing.assert_array_almost_equal(line.project(example_points),
                                         expected_projected_points)
    np.testing.assert_array_almost_equal(
        line.project(example_points + example_perpendicular_displacement),
        expected_projected_points,
    )