Exercise Three – Solids and Surfaces

This is Exercise Three: Solids and Surfaces. For this exercise, we were asked to create one or more Python functions that manage one or more three‐dimensional elements that must be created from geometric operations with invocation of commands to create solids or surfaces.

Here is the Python Code:

 


import rhinoscriptsyntax as rs
import random as r

lotSizeX = 60
lotSizeY = 100

roomSizeX = 6
roomSizeY = 10
roomSizeH = 3.5

offsetDist = 0.25

Crv = []

def makeBlock (room, blockHeight):
    #create a list to save the surfaces.
    blocksrf = []
    #create blocks and explode them into six surfaces.
    origin = rs.CurveStartPoint (room)
    midPoint = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, 0]
    plan = rs.OffsetCurve (room, midPoint, offsetDist)
    roof = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, blockHeight]
    Crv.append (plan)
    facade = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    rs.CapPlanarHoles (facade)
    facade2 = rs.ExplodePolysurfaces (facade, True)
    blocksrf = facade2
    #select and save one surface into a list.
    wall = facade2[3]
    #find the center point of the surface, and create a sphere on it.
    point = rs.SurfaceAreaCentroid (wall)[0]
    rs.AddPoint (point)
    sphere = rs.AddSphere (point, 0.5)
    #extrude the surface so that to make booleandifference between it and the sphere.
    thickness = 0.1
    extrusionCurve = rs.AddLine ([0,0,0],[0,thickness,0])
    wall = rs.ExtrudeSurface (wall, extrusionCurve)
    rs.BooleanDifference (wall, sphere)
    #join the six surfaces back to a block and give it an ID, and return it.
    joinedblock = rs.JoinSurfaces (blocksrf)
    return joinedblock

rs.DeleteObjects (rs.AllObjects ())

#we need to define the workplane before create a rectangle.
plane = rs.WorldXYPlane ()
C = rs.AddRectangle (plane, lotSizeX, lotSizeY)

nrRoomsX = lotSizeX // roomSizeX
nrRoomsY = lotSizeY // roomSizeY

#use three for loop to create blocks in three directions.
for j in range (0, nrRoomsY):

    for i in range (0, nrRoomsX):
        
        for h in range (0, nrRoomsX):
            print (str(i) + "," + str(j) + "," + str(h))
            #we also need to move the workplane so that to crate a new rectangle at the new place.
            newPlane = rs.MovePlane (plane, [i*roomSizeX,j*roomSizeY,h*roomSizeH])
            newRoom = rs.AddRectangle (newPlane, roomSizeX, roomSizeY)
            Crv.append (newRoom)
            #make the block with the defined makeBlock function.
            block = makeBlock (newRoom, 3)
            #use random to randomly delete 25% of the blocks.
            if r.random () < .25:
                rs.DeleteObject (block)
#delete the previouslly created rectangles.
rs.DeleteObjects (Crv)
rs.DeleteObjects (C)

Leave a Reply

Your email address will not be published. Required fields are marked *