CadQuery / CadQuery/cadquery

Generating a minimum step file with a lot of geometries

Open
#1,410 8 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Python
Stars
5.8k
Forks
541
Avg merge
3d 2h
Merged PRs (30d)
5

Description

I'm doing a processing with a lot of points and I need to create a set of cylinders with them. For now, I'm using a stepfile to create the full geometry but the file created is to slow. Any sugestion to improve the geometry creation? The step file created is huge (50-60mb)

```
# Iterating in a set of points (alot of them)
for idx, fib in enumerate(fibers):
seg = np.array(fib)
y_coords, x_coords = seg[:, 0] * -scale_factor, seg[:, 1] * scale_factor

diameter = 0.47

obj = cq.Workplane("XY")

for idx in range(len(x_coords) - 1):
p1 = cq.Vector(x_coords[idx], y_coords[idx])
p2 = cq.Vector(x_coords[idx + 1], y_coords[idx + 1])

direction = p2 - p1

height = euclidean([p1.x, p1.y], [p2.x, p2.y])
angle = math.degrees(cq.Vector(0, 1).getAngle(direction))

direction_of_rotation = -1 * math.copysign(1, direction.x)
cylinder = (
cq.Workplane("XZ", origin=cq.Vector(p1.x, p1.y, p1.z))
.circle(diameter / 2)
.extrude(-height)
.rotate((p1.x, p1.y, p1.z), (p1.x, p1.y, p1.z + 1), direction_of_rotation * angle)
)

obj.add(cylinder)

output_obj.add(obj)

combined_file = os.path.join('output', "multi_fibers.step")
cq.exporters.export(output_obj, combined_file, exportType="STEP")
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.