Description
Allows the user to select a rectangle in Rhino and creates a polyline that follows a zigzag pattern. The zigzag pattern is inscribed in the rectangle and its wave size is equal to the zigzag’s pattern side size:
- Inscribes a zigzag pattern in a rectangle
- Wave size of the zigzag pattern is equal to the zigzag’s pattern side size
- The script works with both horizontal and vertical rectangles
Warning
The script won’t work on rotated rectangles that are not strictly horizontal or vertical
Author and license
Script by MLAV.LAND, licensed under the GNU GPL 3 License.
Code
import rhinoscriptsyntax as rs
# Create an empty list to store the points
points = []
# Ask the user to select a rectangle
rectangle = rs.GetObject("Select a rectangle")
if rectangle is None: exit()
# Get the bounding box of the rectangle
bbox = rs.BoundingBox(rectangle)
# Get the width and height of the bounding box
width = rs.Distance(bbox[0], bbox[1])
height = rs.Distance(bbox[0], bbox[3])
# Get the smaller side of the rectangle
zigzag_side = (min(width, height) / 0.866025403) / 2
# Check if the rectangle is horizontal or vertical
if width > height:
# Rectangle is horizontal
for i in range(int((width+zigzag_side)/zigzag_side + 1)):
x = bbox[0][0] + i * zigzag_side
y = bbox[0][1] + (i % 2) * height
points.append((x, y, 0))
else:
# Rectangle is vertical
for i in range(int((height+zigzag_side)/zigzag_side + 1)):
x = bbox[0][0] + (i % 2) * width
y = bbox[0][1] + i * zigzag_side
points.append((x, y, 0))
# Draw a line that passes through all the points
rs.AddPolyline(points)