Exemple #1
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")
"""
from compas.geometry import Frame
from compas.geometry import Box
from compas_rhino.artists import FrameArtist
from compas_rhino.artists import BoxArtist

# Given: 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)

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

# Task: represent box frame in frame F and construct new box
box_frame_transformed = F.to_world_coordinates(box.frame)
box_transformed = Box(box_frame_transformed, width, length, height)
print("Box frame transformed:", box_transformed.frame)

# create artists
artist1 = FrameArtist(Frame.worldXY())
artist2 = BoxArtist(box)
artist3 = FrameArtist(F)
artist4 = BoxArtist(box_transformed)

# draw
artist1.draw()
artist2.draw()
artist3.draw()
artist4.draw()
Exemple #3
0
    mpoints.append(p)
    mpoints1.append(p1)
    mpoints2.append(p2)

for (a, b), (a1, b1), (a2, b2) in zip(pairwise(mpoints), pairwise(mpoints1),
                                      pairwise(mpoints2)):
    p = (a + b) * 0.5
    t = (b - a).unitized()
    n = Vector(0, 0, 1).cross(t)
    frame = Frame(p, t, n)
    frames.append(frame)
    l1 = (b1 - a1).length
    l2 = (b2 - a2).length
    block = Box(frame, min(l1, l2) - 0.03, 0.3, 0.1)
    block.transform(Translation.from_vector([0, 0, 0.1]))
    blocks1.append(block)

# ==============================================================================
# Visualization
# ==============================================================================

compas_rhino.clear_layers(["Wall::Blocks"])

for block in blocks0:
    artist = BoxArtist(block, layer="Wall::Blocks")
    artist.draw()

for block in blocks1:
    artist = BoxArtist(block, layer="Wall::Blocks")
    artist.draw()
Exemple #4
0
"""
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
"""
artist_01 = BoxArtist(box, layer='box')
artist_02 = MeshArtist(mesh_01, layer='box::projection edges')

artist_01.clear_layer()
artist_02.clear_layer()

artist_01.draw()
artist_02.draw_edges(color="#00ff00")