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

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

Open
vmaurin-pf opened this issue Feb 6, 2024 · 2 comments

Comments

@vmaurin-pf
Copy link

vmaurin-pf commented Feb 6, 2024

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
FreeCAD_circular_solid

Code:

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"))
@adam-urbanczyk
Copy link
Member

adam-urbanczyk commented Feb 6, 2024

That seems to be a tessellation/rendering issue. AFAICT the model is valid. In general it is probably not a good idea to interpolate 1000 points and if circle is what you need, use circle - the whole point of NURBS is that you can represent circles.

@vmaurin-pf
Copy link
Author

Ok that makes sense. Thanks a lot for your answer!

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

No branches or pull requests

2 participants