Ejemplo n.º 1
0
    block.attributes['blank'] = blank
    block.attributes['bottom'] = bottom

    blocks.append(block)

# ==============================================================================
# Export
# ==============================================================================

with open(FILE, 'w') as f:
    json.dump(blocks, f, cls=DataEncoder)

# ==============================================================================
# Visualize
# ==============================================================================

compas_rhino.clear_layers(["ITA20::Assignment1"])

for block in blocks:
    artist = MeshArtist(block,
                        layer="ITA20::Assignment1::{}::Block".format(
                            block.name))
    artist.draw_faces(color={block.attributes['bottom']: (255, 0, 0)})

    blank = block.attributes['blank']

    artist = BoxArtist(blank,
                       layer="ITA20::Assignment1::{}::Blank".format(
                           block.name))
    artist.draw(show_edges=True, show_faces=False)
Ejemplo n.º 2
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")
Ejemplo n.º 3
0
        'x': (0, float('inf')),
        'y': (0, float('inf')),
        'z': (0, float('inf'))
    }))
block.vertex_attribute(vertex, 'z', 150)

blank = Box.from_bounding_box(block.bounding_box())
blank.xsize += 20
blank.ysize += 20
blank.zsize += 20

block.attributes['blank'] = blank

# ==============================================================================
# Export
# ==============================================================================

block.to_json(FILE_O)

# ==============================================================================
# Visualize
# ==============================================================================

compas_rhino.clear()

artist = MeshArtist(block, layer="ITA20::HotWire::Block")
artist.draw_faces()

artist = BoxArtist(blank, layer="ITA20::HotWire::Blank")
artist.draw(show_edges=True, show_faces=False)
Ejemplo n.º 4
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()
# 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()
Ejemplo n.º 6
0
    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 i in range(10):
    for block in blocks0:
        T = Translation.from_vector([0, 0, i * 0.2])
        artist = BoxArtist(block.transformed(T), layer="Wall::Blocks")
        artist.draw()
    for block in blocks1:
        T = Translation.from_vector([0, 0, i * 0.2])
        artist = BoxArtist(block.transformed(T), layer="Wall::Blocks")
        artist.draw()
"""
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()
# Create a Projection (can be orthogonal, parallel or perspective)
point = [0, 0, 0]
normal = [0, 0, -1]
plane = Plane(point, normal)
direction = [2, -2, 1]
P = Projection.from_plane_and_direction(plane, direction)

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

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

# clear layer
artist = BoxArtist(box, layer="Default")
artist.clear_layer()

# defining Artists
artist1 = BoxArtist(box)
artist2 = BoxArtist(box_transformed)
artist3 = MeshArtist(mesh_projected)
artist4 = FrameArtist(frame, scale=1.0)
artist5 = FrameArtist(frame1, scale=1.0)

# Draw
artist1.draw()
artist2.draw()
artist3.draw_edges(color="#00ffff")
artist4.draw()
artist5.draw()
Ejemplo n.º 9
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")
Ejemplo n.º 10
0
from compas.geometry import Frame
from compas.geometry import Plane
from compas.geometry import Sphere

# Box
b1 = Box(Frame.worldXY(), 10, 1, 4)  # xsize, ysize, zsize
b2 = Box.from_width_height_depth(10, 4,
                                 1)  # width=xsize, height=zsize, depth=ysize
assert str(b1) == str(b2)
print(b1)

# Sphere
s1 = Sphere([10, 0, 0], 4)
print(s1)

# Cylinder
plane = Plane([20, 0, 0], [0, 0, 1])
circle = Circle(plane, 5)
c1 = Cylinder(circle, height=4)
print(c1)

# Draw!
artist = BoxArtist(b1, layer='shapes')
artist.draw()

artist = SphereArtist(s1, layer='shapes')
artist.draw()

artist = CylinderArtist(c1, layer='shapes')
artist.draw()