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")
# 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()
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]]
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 artist1 = BoxArtist(box) artist2 = FrameArtist(frame)
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")