mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-15 15:20:37 -08:00
Pillow block example and array points to Part
This commit is contained in:
parent
40b980aa6a
commit
a06f634a7f
2 changed files with 104 additions and 1 deletions
|
|
@ -29,8 +29,9 @@ license:
|
|||
limitations under the License.
|
||||
|
||||
"""
|
||||
from math import radians, tan
|
||||
from math import radians, sin, cos, tan
|
||||
from typing import Union
|
||||
from itertools import product
|
||||
from cadquery import (
|
||||
Edge,
|
||||
Face,
|
||||
|
|
@ -530,6 +531,56 @@ class Loft(Solid):
|
|||
super().__init__(new_solid.wrapped)
|
||||
|
||||
|
||||
class PolarArrayToPart:
|
||||
"""Part Operation: Polar Array
|
||||
|
||||
Push a polar array of locations to BuildPart
|
||||
|
||||
Args:
|
||||
radius (float): array radius
|
||||
start_angle (float): angle to first point from +ve X axis
|
||||
stop_angle (float): angle to last point from +ve X axis
|
||||
count (int): Number of points to push
|
||||
rotate (bool, optional): Align locations with arc tangents. Defaults to True.
|
||||
|
||||
Raises:
|
||||
ValueError: Count must be greater than or equal to 1
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
radius: float,
|
||||
start_angle: float,
|
||||
stop_angle: float,
|
||||
count: int,
|
||||
rotate: bool = True,
|
||||
):
|
||||
if count < 1:
|
||||
raise ValueError(f"At least 1 elements required, requested {count}")
|
||||
|
||||
x = radius * sin(radians(start_angle))
|
||||
y = radius * cos(radians(start_angle))
|
||||
|
||||
if rotate:
|
||||
loc = Location(Vector(x, y), Vector(0, 0, 1), -start_angle)
|
||||
else:
|
||||
loc = Location(Vector(x, y))
|
||||
|
||||
new_locations = [loc]
|
||||
angle = (stop_angle - start_angle) / (count - 1)
|
||||
for i in range(1, count):
|
||||
phi = start_angle + (angle * i)
|
||||
x = radius * sin(radians(phi))
|
||||
y = radius * cos(radians(phi))
|
||||
if rotate:
|
||||
loc = Location(Vector(x, y), Vector(0, 0, 1), -phi)
|
||||
else:
|
||||
loc = Location(Vector(x, y))
|
||||
new_locations.append(loc)
|
||||
|
||||
BuildPart.get_context().locations = new_locations
|
||||
|
||||
|
||||
class PushPointsToPart:
|
||||
"""Part Operation: Push Points
|
||||
|
||||
|
|
@ -547,6 +598,37 @@ class PushPointsToPart:
|
|||
BuildPart.get_context().locations = new_locations
|
||||
|
||||
|
||||
class RectangularArrayToPart:
|
||||
"""Part Operation: Rectangular Array
|
||||
|
||||
Push a rectangular array of locations to BuildPart
|
||||
|
||||
Args:
|
||||
x_spacing (float): horizontal spacing
|
||||
y_spacing (float): vertical spacing
|
||||
x_count (int): number of horizontal points
|
||||
y_count (int): number of vertical points
|
||||
|
||||
Raises:
|
||||
ValueError: Either x or y count must be greater than or equal to one.
|
||||
"""
|
||||
|
||||
def __init__(self, x_spacing: float, y_spacing: float, x_count: int, y_count: int):
|
||||
if x_count < 1 or y_count < 1:
|
||||
raise ValueError(
|
||||
f"At least 1 elements required, requested {x_count}, {y_count}"
|
||||
)
|
||||
|
||||
new_locations = []
|
||||
offset = Vector((x_count - 1) * x_spacing, (y_count - 1) * y_spacing) * 0.5
|
||||
for i, j in product(range(x_count), range(y_count)):
|
||||
new_locations.append(
|
||||
Location(Vector(i * x_spacing, j * y_spacing) - offset)
|
||||
)
|
||||
|
||||
BuildPart.get_context().locations = new_locations
|
||||
|
||||
|
||||
class Revolve(Compound):
|
||||
"""Part Operation: Revolve
|
||||
|
||||
|
|
|
|||
21
pillow_block.py
Normal file
21
pillow_block.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from build_sketch import *
|
||||
from build_part import *
|
||||
|
||||
height, width, thickness, padding = 60, 80, 10, 12
|
||||
screw_shaft_radius, screw_head_radius, screw_head_height = 1.5, 3, 3
|
||||
bearing_axle_radius, bearing_radius, bearing_thickness = 4, 11, 7
|
||||
|
||||
# Build pillow block as an extruded sketch with counter bore holes
|
||||
with BuildPart() as pillow_block:
|
||||
with BuildSketch() as plan:
|
||||
Rectangle(width, height)
|
||||
FilletSketch(*plan.vertices(), radius=5)
|
||||
Extrude(thickness)
|
||||
WorkplanesFromFaces(pillow_block.faces().filter_by_normal(Axis.Z)[-1])
|
||||
CounterBoreHole(bearing_axle_radius, bearing_radius, bearing_thickness)
|
||||
RectangularArrayToPart(width - 2 * padding, height - 2 * padding, 2, 2)
|
||||
CounterBoreHole(screw_shaft_radius, screw_head_radius, screw_head_height)
|
||||
|
||||
# Render the part
|
||||
if "show_object" in locals():
|
||||
show_object(pillow_block.part)
|
||||
Loading…
Add table
Add a link
Reference in a new issue