Skip to content

Commit 78ae970

Browse files
committed
Added cone 3D primitive to Workplane.
1 parent 247f0e6 commit 78ae970

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

cadquery/cq.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,6 +3800,63 @@ def sphere(
38003800
else:
38013801
return self.union(spheres, clean=clean)
38023802

3803+
def cone(
3804+
self: T,
3805+
height: float,
3806+
radius: float = 0,
3807+
radius1: float = None,
3808+
radius2: float = None,
3809+
direct: Vector = Vector(0, 0, 1),
3810+
angle: float = 360,
3811+
combine: bool = True,
3812+
clean: bool = True,
3813+
) -> T:
3814+
"""
3815+
Returns a cone with the specified radius and height for each point on the stack
3816+
A truncated cone can be created by specifying parameters radius1 and radius2 instead of radius.
3817+
3818+
:param height: The height of the cone
3819+
:type height: float > 0
3820+
:param radius: The radius of the cone
3821+
:type radius: float > 0
3822+
:param radius1: The radius of the bottom of the cone
3823+
:type radius1: float > 0
3824+
:param radius2: The radius of the top of the cone
3825+
:type radius2: float > 0
3826+
:param direct: The direction axis for the creation of the cone
3827+
:type direct: A three-tuple
3828+
:param angle: The angle to sweep the cone arc through
3829+
:type angle: float > 0
3830+
:param combine: Whether the results should be combined with other solids on the stack
3831+
(and each other)
3832+
:type combine: true to combine shapes, false otherwise
3833+
:param clean: call :py:meth:`clean` afterwards to have a clean shape
3834+
:return: A cone object for each point on the stack
3835+
3836+
One cone is created for each item on the current stack. If no items are on the stack, one
3837+
box using the current workplane center is created.
3838+
3839+
If combine is true, the result will be a single object on the stack. If a solid was found
3840+
in the chain, the result is that solid with all cones produced fused onto it otherwise,
3841+
the result is the combination of all the produced cones.
3842+
3843+
If combine is false, the result will be a list of the cones produced.
3844+
"""
3845+
3846+
r1 = radius if radius1 is None or radius1 == 0 else radius1
3847+
r2 = 0 if radius2 is None else radius2
3848+
offset = Vector()
3849+
s = Solid.makeCone(r1, r2, height, offset, direct, angle)
3850+
3851+
# We want a cone for each point on the workplane
3852+
cones = self.eachpoint(lambda loc: s.moved(loc), True)
3853+
3854+
# If we don't need to combine everything, just return the created cones
3855+
if not combine:
3856+
return cones
3857+
else:
3858+
return self.union(cones, clean=clean)
3859+
38033860
def wedge(
38043861
self: T,
38053862
dx: float,

doc/apireference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ Some 3-d operations also require an active 2-d workplane, but some do not.
9090
Workplane.cutThruAll
9191
Workplane.box
9292
Workplane.sphere
93+
Workplane.cone
9394
Workplane.union
9495
Workplane.combine
9596
Workplane.intersect

doc/roadmap.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ rotation/transform that return a copy
8080

8181
primitive creation
8282
Need primitive creation for:
83-
* cone
8483
* cylinder
8584
* torus
8685
* wedge
8786

8887
extrude/cut up to surface
89-
allow a cut or extrude to terminate at another surface, rather than either through all or a fixed distance
88+
allow a cut or extrude to terminate at another surface, rather than either through all or a fixed distance

tests/test_cadquery.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,20 @@ def testSphereCombine(self):
24432443
self.assertEqual(1, s.solids().size())
24442444
self.assertEqual(4, s.faces().size())
24452445

2446+
def testConeDefaults(self):
2447+
s = Workplane("XY").cone(40, 10)
2448+
self.saveModel(s)
2449+
self.assertEqual(1, s.size())
2450+
self.assertEqual(1, s.solids().size())
2451+
self.assertEqual(2, s.faces().size())
2452+
self.assertEqual(2, s.vertices().size())
2453+
s1 = Workplane("XY").cone(40, radius1=10, radius2=5)
2454+
self.saveModel(s)
2455+
self.assertEqual(1, s1.size())
2456+
self.assertEqual(1, s1.solids().size())
2457+
self.assertEqual(3, s1.faces().size())
2458+
self.assertEqual(2, s1.vertices().size())
2459+
24462460
def testWedgeDefaults(self):
24472461
s = Workplane("XY").wedge(10, 10, 10, 5, 5, 5, 5)
24482462
self.saveModel(s)

0 commit comments

Comments
 (0)