Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operation along a rounded box #1640

Open
jniclas opened this issue Aug 4, 2024 · 2 comments
Open

Operation along a rounded box #1640

jniclas opened this issue Aug 4, 2024 · 2 comments
Labels
question Further information is requested

Comments

@jniclas
Copy link

jniclas commented Aug 4, 2024

Hey, I have a box which is rounded, now I want to select the upper edge (all around) and want to apply an operation every e.g. 2cm. Like in this picture:
image
How can I perform this operation? I have already:

length = 180
width = 100
height= 80
wall = 0.4*2
topOffset = 5

part = (
    cq.Workplane("XY")
    .rect(width, length)
    .workplane(offset=height)
    .rect(width + topOffset, length + topOffset)
    .loft(ruled=True)
    .edges("not(|X)").edges("not(|Y)")
    .fillet(3)
)

braceWidth = wall
braceDistanceAbsolute = 20

brace = (
    cq.Workplane("XZ")
    .lineTo(0, -height)
    .lineTo(-topOffset, -height)
    .close()
    .extrude(wall)
)

circlePath = part.edges(">Z and >X").val()
print(circlePath.Length())

braceDistance = (braceWidth + braceDistanceAbsolute) / circlePath.Length()
braceCount = floor(circlePath.Length()/(braceDistanceAbsolute+braceDistance))

print(braceDistance)
print(braceCount)

for i in range(braceCount):
    relative_position_on_path = i*braceDistance
    wire_tangent = circlePath.tangentAt(relative_position_on_path)
    wire_angle = degrees(atan2(wire_tangent.y, wire_tangent.x))
    part = part.union(brace.rotate((0,0,0),(0,0,1), wire_angle-90).translate(circlePath.positionAt(relative_position_on_path)))

only issue is, that circlePath is not the full loop, but only one side 🤔

@jniclas jniclas added the question Further information is requested label Aug 4, 2024
@lorenzncode
Copy link
Member

To select the outer wire on the top face try:

circlePath = part.wires(">Z").val()

@adam-urbanczyk
Copy link
Member

adam-urbanczyk commented Aug 4, 2024

You could use apply and cq.Wire.positionAt, e.g.

N = 12

res = (
    cq.Workplane()
    .box(1,1,1)
    .wires('>Z')
    .apply(lambda x: list(x[0].positionAt(p/N) for p in range(N)))
    .sphere(0.1, combine='cut')
)

afbeelding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants