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

Sweep Path Orientation Issue with Parametric Wave Path #1723

Open
HamzaHassan9320 opened this issue Dec 4, 2024 · 3 comments
Open

Sweep Path Orientation Issue with Parametric Wave Path #1723

HamzaHassan9320 opened this issue Dec 4, 2024 · 3 comments
Labels
question Further information is requested

Comments

@HamzaHassan9320
Copy link

HamzaHassan9320 commented Dec 4, 2024

When sweeping a rectangular profile along a parametric wave path, the profile's orientation changes incorrectly as the sweep progresses. This happens regardless of whether isFrenet is set to True or False. The sweep initially aligns with the path correctly but distorts as it continues, making the result inconsistent.

Code Example
Below is a minimal, complete example to reproduce the issue. This can be copied and run directly in CQ-Editor:

`import cadquery as cq
import math

Parameters for the wave spring

t1 = 0 # Start parameter
t2 = 50 # End parameter
num_points = 500 # Number of points for smoothness
radius = 50
(width, thickness) = (4, 2)

Generate the wave spring path

points = []
delta_t = (t2 - t1) / num_points
for i in range(num_points + 1):
t = t1 + i * delta_t
# Parametric equations for the wave spring
x = radius * math.sin(t)
y = radius * math.cos(t)
z = 7 * math.sin(3.5 * t) + 3 * t
points.append((x, y, z))

Create the wave path as a spline

wave_path = cq.Workplane("XY").spline(points)

Define a rectangular profile and sweep along the path

result = (
cq.Workplane("YZ") # Profile aligned to XZ plane
.center(radius, 0) # Offset to the radius of the wave spring
.rect(width, thickness) # Create a rectangle profile
.sweep(wave_path, isFrenet=False) # Sweep along the wave path
)`

Observed Behavior
The sweep starts with the profile aligned correctly to the path.
As the path progresses, the profile's orientation distorts and deviates from the intended alignment.

Expected Behavior
The rectangular profile should maintain consistent orientation along the entire wave path, ensuring a uniform sweep.

Screenshots
Sweep with normal=(0,0,1):
with normal assigned

Sweep with no normal:
with no normal

Sweep with a circular profile (for comparison)(best to understand how it changes with the path as the path(black line) goes from outward to inward)
circular sweep

@HamzaHassan9320 HamzaHassan9320 added the question Further information is requested label Dec 4, 2024
@HTeyssedre
Copy link

HTeyssedre commented Dec 10, 2024

Same situation I think, sweeping a wire profile along a spline wave does not work properly (or as expected).
Minimal example:

import cadquery as cq
import numpy as np

support = cq.Workplane("XY").rect(50, 100).offset2D(5)
nodes = [support.consolidateWires().val().positionAt(t) + cq.Vector(0, 0, 2+2np.sin(20np.pi*t)) for t in np.linspace(0,1,100)]
sweepingPath = cq.Workplane("XY").polyline(nodes).close() # or .spline

ref0 = cq.Vector(nodes[0].y , nodes[0].z)
points = [ ref0 + cq.Vector(5, 0),
ref0 + cq.Vector(-5, 0),
ref0 + cq.Vector(-5, -4)
]

profile = cq.Workplane("YZ", origin=(nodes[0].x,0,0)).polyline(points).consolidateWires()
sweptPlane = profile.sweep(sweepingPath, isFrenet=False)

show_object(sweptPlane)

Screenshot 2024-12-10 070358
Screenshot 2024-12-10 070439
Screenshot 2024-12-10 070703
(nodes).close()

@HamzaHassan9320
Copy link
Author

@adam-urbanczyk could this be a potential limitation of the library, at its current stage?

@adam-urbanczyk
Copy link
Member

If you don't like the generated orientation you can always use an aux spine to define one explicitly.

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