CadQuery / CadQuery/cadquery

CAD generation issues when sweeping a circular cross-section along a spline

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

Description

Hi there,

Basically, I am generating a solid by sweeping a small circular cross section (5 mm) around a circle generated by a spline with 1000 points (1 m radius). The code generating this solid is attached below.
Interestingly enough, when I import the generated step file in solidworks, the solid is loading fine. However, when loading this solid in the Cadquery GUI or in FreeCAD, only the right part of the solid seems to be generated (see picture 1 and 2).

I have narrowed down this error to the use of the spline. When generating the circle with a polyline, the step object seems to be loaded correctly in Solidworks, FreeCAD and in the Cadquery GUI. Do you have any idea of what is going on with the spline object? Am I using too many points? Or is there a tangency argument that I need to specify in the spline object as well?

Thanks for your help!

![Solidworks_circular_solid](https://github.com/CadQuery/cadquery/assets/153509067/63786f38-34a0-4d4a-83fb-d21c6f028a65)
![FreeCAD_circular_solid](https://github.com/CadQuery/cadquery/assets/153509067/13e7ca9a-cabd-4b76-a667-6f8a7d3a5e81)

# Code:
```python
import numpy as np
import cadquery as cq
import os

your_path = "write your file path"

# parameters
radius = 1
number_of_points_spline = 1000
diameter = 5e-3

# generating a spline
thetas = np.linspace(0, 2*np.pi, number_of_points_spline)
x_coord = np.cos(thetas)*radius
y_coord = np.sin(thetas)*radius

list_xy_coord = []

for coord_number in range(len(x_coord)):
list_xy_coord.append((x_coord[coord_number], y_coord[coord_number]))

spline = cq.Workplane("XZ").spline(list_xy_coord).close()
#spline = cq.Workplane("XZ").polyline(list_xy_coord).close()

# generating a circular cross section
circular_cross_section = cq.Workplane("XY").center(radius, radius).circle(diameter)

# sweeping the cross section along the spline
circular_solid = circular_cross_section.sweep(spline)

# saving as a step file
cq.exporters.export(circular_solid, os.path.join(your_path, "circular_solid.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.