Ejemplo n.º 1
0
def test_rotate_xy():
    """Test the Plane rotate_xy method."""
    pt = Point3D(2, 2, 2)
    vec = Vector3D(0, 2, 0)
    plane = Plane(vec, pt)
    origin_1 = Point3D(0, 2, 2)

    test_1 = plane.rotate_xy(math.pi, origin_1)
    assert test_1.o.x == pytest.approx(-2, rel=1e-3)
    assert test_1.o.y == pytest.approx(2, rel=1e-3)
    assert test_1.o.z == pytest.approx(2, rel=1e-3)
    assert test_1.n.x == pytest.approx(0, rel=1e-3)
    assert test_1.n.y == pytest.approx(-1, rel=1e-3)
    assert test_1.n.z == pytest.approx(0, rel=1e-3)
    assert test_1.x.x == pytest.approx(-1, rel=1e-3)
    assert test_1.x.y == pytest.approx(0, rel=1e-3)
    assert test_1.x.z == pytest.approx(0, rel=1e-3)
    assert test_1.y.x == pytest.approx(0, rel=1e-3)
    assert test_1.y.y == pytest.approx(0, rel=1e-3)
    assert test_1.y.z == pytest.approx(-1, rel=1e-3)
    assert test_1.k == pytest.approx(-2, rel=1e-3)

    test_2 = plane.rotate_xy(math.pi/2, origin_1)
    assert test_2.o.x == pytest.approx(0, rel=1e-3)
    assert test_2.o.y == pytest.approx(4, rel=1e-3)
    assert test_2.o.z == pytest.approx(2, rel=1e-3)
    assert test_2.n.x == pytest.approx(-1, rel=1e-3)
    assert test_2.n.y == pytest.approx(0, rel=1e-3)
    assert test_2.n.z == pytest.approx(0, rel=1e-3)
    assert test_2.x.x == pytest.approx(0, rel=1e-3)
    assert test_2.x.y == pytest.approx(1, rel=1e-3)
    assert test_2.x.z == pytest.approx(0, rel=1e-3)
    assert test_2.y.x == pytest.approx(0, rel=1e-3)
    assert test_2.y.y == pytest.approx(0, rel=1e-3)
    assert test_2.y.z == pytest.approx(-1, rel=1e-3)
    assert test_2.k == pytest.approx(0, rel=1e-3)
Ejemplo n.º 2
0
    def rotate_xy(self, angle, origin=None):
        """Rotate this view counterclockwise in the world XY plane by a certain angle.

        Args:
            angle: An angle in degrees.
            origin: A ladybug_geometry Point3D for the origin around which the
                object will be rotated. If None, self.position is used. (Default: None).
        """
        view_up_vector = pv.Vector3D(*self.up_vector)
        view_position = pv.Point3D(*self.position)
        view_direction = pv.Vector3D(*self.direction)
        view_plane = Plane(n=view_up_vector, o=view_position, x=view_direction)
        position = origin if origin is not None else view_position

        rotated_plane = view_plane.rotate_xy(math.radians(angle), position)
        self._apply_plane_properties(rotated_plane, view_direction, view_up_vector)