Skip to content

Commit 0708779

Browse files
committed
Added cone 3D primitive to Workplane.
1 parent 0b2a075 commit 0708779

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

cadquery/cq.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,6 +3800,59 @@ 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+
:param height: The height of the cone
3818+
:type height: float > 0
3819+
:param radius: The radius of the cone
3820+
:type radius: float > 0
3821+
:param radius1: The radius of the bottom of the cone
3822+
:type radius1: float > 0
3823+
:param radius2: The radius of the top of the cone
3824+
:type radius2: float > 0
3825+
:param direct: The direction axis for the creation of the cone
3826+
:type direct: A three-tuple
3827+
:param angle: The angle to sweep the cone arc through
3828+
:type angle: float > 0
3829+
:param combine: Whether the results should be combined with other solids on the stack
3830+
(and each other)
3831+
:type combine: true to combine shapes, false otherwise
3832+
:param clean: call :py:meth:`clean` afterwards to have a clean shape
3833+
:return: A cone object for each point on the stack
3834+
One cone is created for each item on the current stack. If no items are on the stack, one
3835+
cone is created using the current workplane center.
3836+
If combine is true, the result will be a single object on the stack. If a solid was found
3837+
in the chain, the result is that solid with all cones produced fused onto it otherwise,
3838+
the result is the combination of all the produced cones.
3839+
If combine is false, the result will be a list of the cones produced.
3840+
"""
3841+
3842+
r1 = radius if radius1 is None or radius1 == 0 else radius1
3843+
r2 = 0 if radius2 is None else radius2
3844+
offset = Vector()
3845+
s = Solid.makeCone(r1, r2, height, offset, direct, angle)
3846+
3847+
# We want a cone for each point on the workplane
3848+
cones = self.eachpoint(lambda loc: s.moved(loc), True)
3849+
3850+
# If we don't need to combine everything, just return the created cones
3851+
if not combine:
3852+
return cones
3853+
else:
3854+
return self.union(cones, clean=clean)
3855+
38033856
def cylinder(
38043857
self: T,
38053858
height: float,

doc/apireference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Some 3D operations also require an active 2D workplane, but some do not.
9191
Workplane.box
9292
Workplane.sphere
9393
Workplane.cylinder
94+
Workplane.cone
9495
Workplane.union
9596
Workplane.combine
9697
Workplane.intersect

doc/roadmap.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ rotation/transform that return a copy
8080

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

tests/test_cadquery.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,19 @@ def testCylinderCentering(self):
24752475
self.assertTupleAlmostEquals(
24762476
s0.val().Center().toTuple(), s1.val().Center().toTuple(), 3
24772477
)
2478+
def testConeDefaults(self):
2479+
s = Workplane("XY").cone(40, 10)
2480+
self.saveModel(s)
2481+
self.assertEqual(1, s.size())
2482+
self.assertEqual(1, s.solids().size())
2483+
self.assertEqual(2, s.faces().size())
2484+
self.assertEqual(2, s.vertices().size())
2485+
s1 = Workplane("XY").cone(40, radius1=10, radius2=5)
2486+
self.saveModel(s)
2487+
self.assertEqual(1, s1.size())
2488+
self.assertEqual(1, s1.solids().size())
2489+
self.assertEqual(3, s1.faces().size())
2490+
self.assertEqual(2, s1.vertices().size())
24782491

24792492
def testWedgeDefaults(self):
24802493
s = Workplane("XY").wedge(10, 10, 10, 5, 5, 5, 5)

0 commit comments

Comments
 (0)