Example #1
0
def test_projection_perspective():
    point = [0, 0, 0]
    normal = [0, 0, 1]
    perspective = [1, 1, 0]
    P = Projection.perspective(point, normal, perspective)
    assert P.matrix == [[0.0, 0.0, -1.0, 0.0], [0.0, 0.0, -1.0, 0.0],
                        [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, -1.0, 0.0]]
Example #2
0
def test_projection_parallel():
    point = [0, 0, 0]
    normal = [0, 0, 1]
    direction = [1, 1, 1]
    P = Projection.parallel(point, normal, direction)
    assert P.matrix == [[1.0, 0.0, -1.0, 0.0], [0.0, 1.0, -1.0, 0.0],
                        [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
Example #3
0
    def decomposed(self):
        """Decompose the `Transformation` into its components.

        Returns
        -------
        :class:`compas.geometry.Scale`
            The scale component of the current transformation.
        :class:`compas.geometry.Shear`
            The shear component of the current transformation.
        :class:`compas.geometry.Rotation`
            The rotation component of the current transformation.
        :class:`compas.geometry.Translation`
            The translation component of the current transformation.
        :class:`compas.geometry.Projection`
            The projection component of the current transformation.

        Examples
        --------
        >>> from compas.geometry import Scale, Translation, Rotation
        >>> trans1 = [1, 2, 3]
        >>> angle1 = [-2.142, 1.141, -0.142]
        >>> scale1 = [0.123, 2, 0.5]
        >>> T1 = Translation.from_vector(trans1)
        >>> R1 = Rotation.from_euler_angles(angle1)
        >>> S1 = Scale.from_factors(scale1)
        >>> M = T1 * R1 * S1
        >>> S, H, R, T, P = M.decomposed()
        >>> S1 == S
        True
        >>> R1 == R
        True
        >>> T1 == T
        True

        """
        from compas.geometry import Scale  # noqa: F811
        from compas.geometry import Shear
        from compas.geometry import Rotation  # noqa: F811
        from compas.geometry import Translation  # noqa: F811
        from compas.geometry import Projection
        s, h, a, t, p = decompose_matrix(self.matrix)
        S = Scale.from_factors(s)
        H = Shear.from_entries(h)
        R = Rotation.from_euler_angles(a, static=True, axes='xyz')
        T = Translation.from_vector(t)
        P = Projection.from_entries(p)
        return S, H, R, T, P
Example #4
0
    def decomposed(self):
        """Decompose the ``Transformation`` into its ``Scale``, ``Shear``,
        ``Rotation``, ``Translation`` and ``Perspective`` components.

        Returns
        -------
        5-tuple of Transformation
            The scale, shear, rotation, tranlation, and projection components
            of the current transformation.

        Examples
        --------
        >>> trans1 = [1, 2, 3]
        >>> angle1 = [-2.142, 1.141, -0.142]
        >>> scale1 = [0.123, 2, 0.5]
        >>> T1 = Translation(trans1)
        >>> R1 = Rotation.from_euler_angles(angle1)
        >>> S1 = Scale(scale1)
        >>> M = (T1 * R1) * S1
        >>> Sc, Sh, R, T, P = M.decomposed()
        >>> S1 == Sc
        True
        >>> R1 == R
        True
        >>> T1 == T
        True

        """
        from compas.geometry import Scale  # noqa: F811
        from compas.geometry import Shear
        from compas.geometry import Rotation  # noqa: F811
        from compas.geometry import Translation  # noqa: F811
        from compas.geometry import Projection

        sc, sh, a, t, p = decompose_matrix(self.matrix)
        Sc = Scale(sc)
        Sh = Shear.from_entries(sh)
        R = Rotation.from_euler_angles(a, static=True, axes='xyz')
        T = Translation(t)
        P = Projection.from_entries(p)
        return Sc, Sh, R, T, P
Example #5
0
from compas_rhino.artists import MeshArtist
from compas_rhino.artists import PlaneArtist  # not implemented

from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame(Point(1, 1, 3), Vector(1, 0, 1), Vector(0, 1, 1))

# Create a Box with that frame
box = Box(frame, 2, 3, 6)

# create a plane for the projection
planexy = Plane.worldXY()

# Create a Projection (can be orthogonal, parallel or perspective)
P3 = Projection.from_plane(
    planexy)  # orthogonal Projection to project onto a plane
P4 = Projection.from_plane_and_direction(planexy, direction=Vector(
    -2, 2, 1))  # parallel projection
P5 = Projection.from_plane_and_point(planexy,
                                     Point(3, -3,
                                           -1))  # perspective Projection

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected3 = mesh.transformed(P3)
mesh_projected4 = mesh.transformed(P4)
mesh_projected5 = mesh.transformed(P5)

# Create artists
Example #6
0
def test_projection_orthogonal():
    point = [0, 0, 0]
    normal = [0, 0, 1]
    P = Projection.from_plane((point, normal))
    assert P.matrix == [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
Example #7
0
def test_projection_entries():
    persp1 = [0.3, 0.1, 0.1, 1]
    P1 = Projection.from_entries(persp1)
    assert P1.matrix == [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.3, 0.1, 0.1, 1.0]]
Example #8
0
def test_projection_perspective():
    point = [0, 0, 0]
    normal = [0, 0, 1]
    perspective = [1, 1, 0]
    P = Projection.from_plane_and_point((point, normal), perspective)
    assert P.matrix == [[0.0, 0.0, -1.0, 0.0], [0.0, 0.0, -1.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, -1.0, 0.0]]
Example #9
0
def test_projection_parallel():
    point = [0, 0, 0]
    normal = [0, 0, 1]
    direction = [1, 1, 1]
    P = Projection.from_plane_and_direction((point, normal), direction)
    assert P.matrix == [[1.0, 0.0, -1.0, 0.0], [0.0, 1.0, -1.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.0]]
Example #10
0
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame([4, 4, 4], [.5, 1, 2], [0, 1, 2])

# Create a Box with that frame
width, length, height = 1, 1, 1
box = Box(frame, width, length, height)

# Create a Projection (can be orthogonal, parallel or perspective)
point = [0, 0, 0]
normal = [0, 0, 1]
plane = Plane(point, normal)
direction = [1, 1, 1]
P = Projection.from_plane_and_direction(plane, direction)

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
Example #11
0
print("Translation:\n", T)

#create concantinated transformation of Frame
X1 = R * T
F.transform(X1)
print(F)
"""
CREATE BOX AND PROJECTION
"""
width, length, height = 1, 1, 8
box = Box(F, width, length, height)

#create projection
projection_plane = Plane([0, 0, 0], [0, 0, 1])  #world XY plane
P = Projection.from_plane(projection_plane)  #orthogonal projection

print("Projection:\n", P)
"""
CREATE PROJECTED MESH
"""
mesh_01 = Mesh.from_shape(box)
projected_mesh = mesh_01

try:
    projected_mesh.transform(P)
except:
    print("Something went wrong with the projection")
"""
ARTISTS
"""
Example #12
0
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Projection, Plane, Vector
from compas_rhino.artists import BoxArtist
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame_1 = Frame([7, 7, 7], [0.5, 1, 0], [1, 0, 0.5])

# Create a Box with that frame
box_1 = Box(frame_1, 1, 2, 3)

# Create a Projection transformation (can be orthogonal, parallel or perspective)
plane_1 = Plane([0, 0, 0], [0, 0, 1])
P = Projection.from_plane_and_point(plane_1, (10, 10, 10))

# Create a Mesh from the Box
mesh = Mesh.from_shape(box_1)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box_1)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
Example #13
0
frame = Frame.from_euler_angles([0.5, 1., 0.2])
translation_vector = [5, 3, 1]
T = Translation.from_vector(translation_vector)
# move frame from origin
frame.transform(T)

# Create a Box with that frame
width, length, height = 1, 1, 1
box = Box(frame, width, length, height)

# Create a Projection (can be orthogonal, parallel or perspective)
point = [0, 0, 0]
normal = [0, 0, 1]
plane = Plane(point, normal)
# An orthogonal projection transformation
P = Projection.from_plane(plane)

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = Mesh.transformed(mesh, P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
from compas.geometry import Scale
from compas.geometry import Reflection
from compas.geometry import Projection
from compas.geometry import Shear

axis, angle = [0.2, 0.4, 0.1], 0.3
R = Rotation.from_axis_and_angle(axis, angle)
print("Rotation:\n", R)

translation_vector = [5, 3, 1]
T = Translation.from_vector(translation_vector)
print("Translation:\n", T)

scale_factors = [0.1, 0.3, 0.4]
S = Scale.from_factors(scale_factors)
print("Scale:\n", S)

point, normal = [0.3, 0.2, 1], [0.3, 0.1, 1]
R = Reflection.from_plane((point, normal))
print("Reflection:\n", R)

point, normal = [0, 0, 0], [0, 0, 1]
perspective = [1, 1, 0]
P = Projection.from_plane_and_point((point, normal), perspective)
print("Perspective projection:\n", R)

angle, direction = 0.1, [0.1, 0.2, 0.3]
point, normal = [4, 3, 1], [-0.11, 0.31, -0.17]
S = Shear.from_angle_direction_plane(angle, direction, (point, normal))
print("Shear:\n", S)
Example #15
0
"""
from compas.geometry import Box
from compas.geometry import Frame
from compas.geometry import Projection
from compas_rhino.artists import BoxArtist
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame([1, 2, 3], [-4, 5, 6], [7, 8, 9])

# Create a Box with that frame
box = Box(frame, 3, 4, 5)

# Create a Projection (can be orthogonal, parallel or perspective)
point, normal = [0, 0, 0], [0, 0, 1]
P = Projection.from_plane((point, normal))

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#ff0000")
# Box in the world coordinate system
frame = Frame([1, 0, 0], [-0.45, 0.1, 0.3], [1, 0, 0])
width, length, height = 1, 1, 1
box = Box(frame, width, length, height)

# Frame F representing a coordinate system
F = Frame([2, 2, 2], [0.978, 0.010, -0.210], [0.090, 0.882, 0.463])

# Get transformation between frames and apply transformation on box.
T = Transformation.from_frame_to_frame(Frame.worldXY(), F)
box_transformed = box.transformed(T)

# make Mesh from box
mesh_transformed = Mesh.from_shape(box_transformed)

# create Projection
P = Projection.from_plane_and_direction(Plane((0, 0, 0), (0, 0, 1)), (3, 5, 5))
P = Projection.from_plane(Plane((0, 0, 0), (0, 0, 1)))
P = Projection.from_plane_and_point(Plane((0, 0, 0), (0, 0, 1)), (3, 5, 5))

# apply transformation on mesh
mesh_projected = mesh_transformed.transformed(P)

# create artists
artist1 = BoxArtist(box_transformed)
artist2 = MeshArtist(mesh_projected)

# draw
artist1.draw()
artist2.draw()
Example #17
0
frame = Frame((
    1,
    0,
    0,
), (1, 0, 0), (0, 1, 0))

# Create a Box with that frame
box = Box(frame, 0.3, 0.3, 0.3)

# Create a Projection (can be orthogonal, parallel or perspective)
point = [0, 0, 0]
normal = [0, 0, 1]
XYplane = Plane(point, normal)
direction = [1, 1, 1]

P = Projection.from_plane_and_direction(XYplane, normal)

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.projected(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
from compas.geometry import Scale
from compas.geometry import Reflection
from compas.geometry import Projection
from compas.geometry import Shear

axis, angle = [0.2, 0.4, 0.1], 0.3
R = Rotation.from_axis_and_angle(axis, angle)
print("Rotation:\n", R)

translation_vector = [5, 3, 1]
T = Translation(translation_vector)
print("Translation:\n", T)

scale_factors = [0.1, 0.3, 0.4]
S = Scale(scale_factors)
print("Scale:\n", S)

point, normal = [0.3, 0.2, 1], [0.3, 0.1, 1]
R = Reflection(point, normal)
print("Reflection:\n", R)

point, normal = [0, 0, 0], [0, 0, 1]
perspective = [1, 1, 0]
P = Projection.perspective(point, normal, perspective)
print("Perspective projection:\n", R)

angle, direction = 0.1, [0.1, 0.2, 0.3]
point, normal = [4, 3, 1], [-0.11, 0.31, -0.17]
S = Shear(angle, direction, point, normal)
print("Shear:\n", S)
Example #19
0
"""Assignment 01: Project box to xy-plane
"""
from compas.geometry import Box
from compas.geometry import Frame, Plane
from compas.geometry import Projection
from compas_rhino.artists import BoxArtist
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame([1, 2, 3], [-0.45, 0.1, 0.3], [1, 2, 1])

# Create a Box with that frame
box = Box(frame, 2, 3, 5)

# Create a Projection (can be orthogonal, parallel or perspective)
P = Projection.from_plane(Plane([0, 0, 0], [0, 0, 1]))

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")