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

seems parametricCuve()bug #1586

Open
Lofuys opened this issue May 12, 2024 · 10 comments
Open

seems parametricCuve()bug #1586

Lofuys opened this issue May 12, 2024 · 10 comments

Comments

@Lofuys
Copy link

Lofuys commented May 12, 2024

Hi,
i think i met with bug .I want to sweep along 3D path defined by parametricCurve(), It's Basically double helix—— wire make helix revolve a normal helix.
However,when I increase t, the curve goes wrong, and I also try to increase N, It,s dosen' work too.
And I am new to cq and code thing, I need to find way to solve this prblem.

q = -1
p = -1
origine_angle = 0
def double_helix(r, R, B, n, t):
x = r * (cos(origine_angle + p * q * t * n) * cos(t) - q * sin(origine_angle + p * q * t * n) * cos(B) * sin(t)) + R * cos(t)
y = q * r * (cos(origine_angle + p * q * t * n) * sin(t) + q * sin(origine_angle + p * q * t * n) * cos(B) * cos(t)) + R * sin(t)
z = -1qrsin(origine_angle+pqtn)sin(B)+tR/tan(B)
return x, y, z

x, y, z = double_helix(R_22, R_21, a_21, n_22, 0)
path = (
cq.Workplane("XY")
.parametricCurve(lambda t: double_helix(R_22, R_21, a_21, n_22,t2pi),start= 0,stop= 3/4
)
)

show_object(path)

when t=3/4, the curve is good, but t=1, the curve isn't the correct result.
屏幕截图 2024-05-12 213335
屏幕截图 2024-05-12 213206
屏幕截图 2024-05-12 213242

I think that might be bug, and how to solve this.
And forgive my English,if i have ever make uncomefortabl words.

Regrads

@Lofuys
Copy link
Author

Lofuys commented May 12, 2024

sorry, I mean t is stop

@Lofuys
Copy link
Author

Lofuys commented May 12, 2024

屏幕截图 2024-05-12 224017
and along the correct curve the result also strange

@lorenzncode
Copy link
Member

The code example is corrupted as shown in the comment.

For example -1qrsin? here:

z = -1qrsin(origine_angle+pqtn)sin(B)+tR/tan(B)

Could you repost with code formatting? See the github docs here:
https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code

Please also include a minimal reproducible example that defines all variables used in the code. Missing variables include R_22, R_21, a_21, n_22.

@Lofuys
Copy link
Author

Lofuys commented May 13, 2024

sorry, I am alos new to github.Its kind of tricky for me at least now.
anyway,the code is below:

import cadquery as cq
from math import sin, cos, pi, tan

def parameter_n(r_1,r_2,a,B):
    return(
        r_1 *  tan(a) / (r_2 * sin(B) )
        )

#diamater of wires , helix radius and lay angle.

r_B = 0.135

R_21 = 1.100
a_21 = 0.16309787547

R_22 = 0.27
a_22 = 0.23454060987
n_22 = parameter_n(R_21,R_22,a_22,a_21)

oreigine_angle = 0 
q=1
def single_helix(r,t,a):
    return(
        r * cos(q * t + oreigine_angle),
        r * sin(q * t + oreigine_angle),
        r * t/tan(a),
         )
x,y,z= single_helix(R_21,0,a_21)
    
path= (
        cq.Workplane("XY")
        .parametricCurve(lambda t: single_helix(R_21,t*2*pi,a_21)
                         )
        )
ISCW = (
    cq.Workplane("XY")
    .center(x,y)
    .circle(r_B)
    .sweep(path,isFrenet=True)
    )
show_object(ISCW)
        
q = -1
p = -1
origine_angle = 0
def double_helix(r, R, B, n, t):
    x = r * (cos(origine_angle + p * q * t * n) * cos(t) - q * sin(origine_angle + p * q * t * n) * cos(B) * sin(t)) + R * cos(t)
    y = q * r * (cos(origine_angle + p * q * t * n) * sin(t) + q * sin(origine_angle + p * q * t * n) * cos(B) * cos(t)) + R * sin(t)
    z = -1 * q * r * sin(origine_angle  + p * q * t * n) * sin(B) + t * R / tan(B)
    return x, y, z

x, y, z = double_helix(R_22, R_21, a_21, n_22, 0)

path = (
        cq.Workplane("XY")
        .parametricCurve(lambda t: double_helix(R_22, R_21, a_21, n_22,t*2*pi),start= 0,stop= 3/4
                         )
        )
show_object(path)

@adam-urbanczyk
Copy link
Member

I get r_A is not defined.

@Lofuys
Copy link
Author

Lofuys commented May 14, 2024

Sorry for my mistake, it's actually r_B. I hvae already fixed it, seeing the code above.

@adam-urbanczyk
Copy link
Member

Another error:
NameError: name 'i' is not defined

@Lofuys
Copy link
Author

Lofuys commented May 15, 2024

I have fixed and test the code again, it should work now.
Apology for the errors and thaks for your patience!

@adam-urbanczyk
Copy link
Member

It seems that you need to turn off smoothing:

path1 = (
    cq.Workplane("XY")
    .parametricCurve(
        lambda t: double_helix(R_22, R_21, a_21, n_22,t*2*pi),start= 0,stop= 1, smoothing=None
    )
)

The other thing is related to rendering tolerance (Edit>Preferences>3D Viewer>Deviation in CQ-editor). If I set tighter tol, I see no artifacts (though it takes longer to display the object).

@Lofuys
Copy link
Author

Lofuys commented May 27, 2024

Thank you very much! Your advice really helps me a lot. At firs I though it is some bugs.

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

3 participants