# Create truncated Cone

**URL:** https://discourse.vtk.org/t/create-truncated-cone/813
**Category:** Support
**Created:** [April 22, 2019, 6:53pm UTC](https://discourse.vtk.org/t/create-truncated-cone/813 "2019-04-22T18:53:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![siaeleni](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/b4bc9f/32.png) [@siaeleni](https://discourse.vtk.org/u/siaeleni)
#### Post date: [April 22, 2019, 6:53pm UTC](https://discourse.vtk.org/t/create-truncated-cone/813/1 "2019-04-22T18:53:30Z")

</div>

Hello,

I want to display a truncated code like the following  
 ![cone](https://discourse.vtk.org/uploads/default/original/1X/462b3e412214479f1f988689c9f8e943bf4573a1.jpeg)

Any hint would be appreciated.  
Thanks

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [April 22, 2019, 6:59pm UTC](https://discourse.vtk.org/t/create-truncated-cone/813/2 "2019-04-22T18:59:14Z")

</div>

You can create any rotationally symmetric shape from a polyline using `vtkRotationalExtrusionFilter`.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [April 22, 2019, 9:23pm UTC](https://discourse.vtk.org/t/create-truncated-cone/813/3 "2019-04-22T21:23:13Z")

</div>

This example shows how to use the `vtkRotationalExtrusionFilter` to extrude a line segment, so is directly applicable for generating this shape:

[https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Modeling/Testing/Cxx/TestRotationalExtrusion.cxx](https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Modeling/Testing/Cxx/TestRotationalExtrusion.cxx)

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [April 23, 2019, 11:54am UTC](https://discourse.vtk.org/t/create-truncated-cone/813/4 "2019-04-23T11:54:41Z")

</div>

Also look at: [CappedSphere](https://lorensen.github.io/VTKExamples/site/Cxx/Modelling/CappedSphere/). You should be able to easily modify the function **GetLine** to do what you want.

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [April 24, 2019, 3:56am UTC](https://discourse.vtk.org/t/create-truncated-cone/813/5 "2019-04-24T03:56:40Z")

</div>

I made a vtkTruncatedConeSource with a simple modification of vtkCylinderSource. Just add some getters and setters for Radius1 and Radius2 instead of Radius. And replace the usage of Radius in the top and bot values in vtkCylinderSource.cxx with Radius1 and Radius2 appropriately. I’d post the whole code but vtkCylinderSource.h/.cxx is a lot.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [April 24, 2019, 6:42am UTC](https://discourse.vtk.org/t/create-truncated-cone/813/6 "2019-04-24T06:42:51Z")

</div>

That should work, although creating a line and rotating it would have been simpler.😃

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [April 24, 2019, 10:26am UTC](https://discourse.vtk.org/t/create-truncated-cone/813/7 "2019-04-24T10:26:24Z")

</div>

Here is a quick example creating a line to rotate to make a truncated cone that you can drop into [CappedSphere](https://lorensen.github.io/VTKExamples/site/Python/Modelling/CappedSphere/) _(the C++ version is easy to create from this, it is left as an exercise for the reader)_.

```auto
def get_line1(height, radius1, radius2, step, uncapped):
    """
    Get the points for a line.

     The parametric equations for the line are:
       x = x1 + (x2 - x1) / t
       z = z1 + (z2 - z1) / t
       0 <= t <= 1

    Conditions:
      height > 0
      radius2 < radius1
      step > 0

    :param height: Height of the cone.
    :param radius1: Radius of the base of the cone.
    :param radius2: Radius of the top of the truncated cone.
    :param step: The number of points in each line.
    :param uncapped: True if uncapped.
    :return: A vector of points.
    """
    pts = list()

    t = 0
    x02 = radius2
    z02 = height / 2
    if not uncapped:
        # Create the cap for radius2
        while t < 1:
            if t != 0:
                x = x02 * t
                z = z02
            else:
                x = 0
                z = z02
            pt = (x, 0, z)
            pts.append(pt)
            t += 1.0 / step
    # The sloped line for the cone
    t = 0
    x21 = radius1 - radius2
    z21 = height / 2
    while t <= 1:
        if t != 0:
            x = radius2 + x21 * t
            z = z21 - height * t
        else:
            x = radius2
            z = z21
        pt = (x, 0, z)
        pts.append(pt)
        t += 1.0 / step
    t = 0
    x10 = radius1
    z10 = -height / 2
    if not uncapped:
        # Create the cap for radius1
        while t < 1:
            if t != 0:
                x = radius1 - x10 * t
                z = z10
            else:
                x = radius1
                z = z10
            pt = (x, 0, z)
            pts.append(pt)
            t += 1.0 / step
    return pts

```
