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

Extrude with taper on any Workplane return a wrong extrude length #1383

Closed
trunglebao opened this issue Jul 31, 2023 · 4 comments · Fixed by #1388
Closed

Extrude with taper on any Workplane return a wrong extrude length #1383

trunglebao opened this issue Jul 31, 2023 · 4 comments · Fixed by #1388
Labels
bug Something isn't working

Comments

@trunglebao
Copy link

trunglebao commented Jul 31, 2023

Generic use of the extrude(until = x, taper = y) command will result in extrude length less than x.

a = list(range(0,60))
z = []
for angle in a:
    part = cq.Solid(cq.Workplane('XY').rect(1,1).extrude(1, taper = angle).toOCC())
    bb = part.BoundingBox()
    z.append(bb.zlen)

Running the code above create a bunch of extrude with height 1, with taper ranging from 0 to 60 degree.
Plotting the taper angle (0 to 60 degree) with resulted extrude height (suppose to be 1):
image

Only taper = 0 return the correct height = 1, the rest is all less than 1.
Any thought/alternative solution to get the correct height?
Thanks!

@jmwright
Copy link
Member

jmwright commented Aug 7, 2023

It's because the sides converge to a point before they get to the extruded length. The zlen can be calculated via the cosine of the taper angle as long as there is not a point convergence.

import cadquery as cq
from math import cos, radians

a = list(range(0,30))
for angle in a:
    part = cq.Workplane('XY').rect(100.0,100.0).extrude(100.0, taper = angle)
    bb = part.val().BoundingBox()
    print(str(angle) + " : " + str(bb.zlen) + " : " + str(100.0 * cos(radians(angle))))

Outputs:

0 : 100.00000020000002 : 100.0
1 : 99.98476971563919 : 99.98476951563913
2 : 99.93908290190964 : 99.93908270190957
3 : 99.86295367545753 : 99.86295347545739
4 : 99.75640522598249 : 99.75640502598242
5 : 99.61947000917462 : 99.61946980917456
6 : 99.45218973682736 : 99.45218953682733
7 : 99.25461536413223 : 99.2546151641322
8 : 99.02680707415715 : 99.02680687415703
9 : 98.76883425951381 : 98.76883405951378
10 : 98.48077550122083 : 98.4807753012208
11 : 98.16271854476643 : 98.1627183447664
12 : 97.81476027338061 : 97.81476007338057
13 : 97.43700667852359 : 97.43700647852353
14 : 97.02957282759971 : 97.02957262759965
15 : 96.59258282890686 : 96.59258262890683
16 : 96.12616979383193 : 96.12616959383189
17 : 95.63047579630357 : 95.63047559630354
18 : 95.10565182951544 : 95.10565162951535
19 : 94.55185775993174 : 94.55185755993169
20 : 93.96926227859088 : 93.96926207859084
21 : 93.35804284972023 : 93.35804264972018
22 : 92.71838565667879 : 92.71838545667875
23 : 92.05048554524413 : 92.05048534524404
24 : 91.3545459642601 : 91.35454576426008
25 : 90.63077890366509 : 90.63077870366499
26 : 89.87940482991672 : 89.8794046299167
27 : 89.1006526188368 : 89.10065241883679
28 : 88.29475948589273 : 88.2947592858927
29 : 87.46197091393961 : 87.46197071393958

@trunglebao
Copy link
Author

That explained it. Thank you very much!
Most of the CAD software that i use set the extrude length to be zlen regardless of the taper amount. While cq use the length of the tapered edge.

image

Regardless, very useful library. Hat off to you guys.

@adam-urbanczyk
Copy link
Member

I think we need to fix this. Me expectation was that this param is height, that is confirmed by the docstring:

The distance to extrude, normal to the workplane plane

@adam-urbanczyk adam-urbanczyk added the bug Something isn't working label Aug 8, 2023
jmwright added a commit that referenced this issue Aug 19, 2023
Fix for incorrect tapered extrude height found in #1383
@jmwright
Copy link
Member

@trunglebao This has been fixed in the latest commit, (see linked PR) but the CI system will need a few hours to build and deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants