# About draw a cylindeical ring , use boolean operation

**URL:** https://discourse.vtk.org/t/about-draw-a-cylindeical-ring-use-boolean-operation/14792
**Category:** Support
**Tags:** code
**Created:** [October 31, 2024, 7:29am UTC](https://discourse.vtk.org/t/about-draw-a-cylindeical-ring-use-boolean-operation/14792 "2024-10-31T07:29:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nanoahSR](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/45deac/32.png) [@nanoahSR](https://discourse.vtk.org/u/nanoahSR)
#### Post date: [October 31, 2024, 7:29am UTC](https://discourse.vtk.org/t/about-draw-a-cylindeical-ring-use-boolean-operation/14792/1 "2024-10-31T07:29:48Z")

</div>

I want to use boolean operations to draw a cylinder ring:

1. create two cylinder,
2. use vtkTrianglefilters,
3. and then Boolean operations,

but why is that?

code:

```C++
// Function to create a cylinder
vtkSmartPointer<vtkPolyData> CreateCylinder(double radius, double height)
{
    auto cylinderSource = vtkSmartPointer<vtkCylinderSource>::New();
    cylinderSource->SetCenter(0, 0, 0);
    cylinderSource->SetRadius(radius);
    cylinderSource->SetHeight(height);
    cylinderSource->SetResolution(100); // Controls smoothness of the circle
    cylinderSource->Update();

    auto triangFilter = vtkSmartPointer<vtkTriangleFilter>::New();
    triangFilter->SetInputData(cylinderSource->GetOutput());
    triangFilter->Update();

    return triangFilter->GetOutput();
}

int main(int, char*[])
{
    // Outer cylinder (the larger one)
    auto outerCylinder = CreateCylinder(2, 1);

    // Inner cylinder (the smaller one to subtract)
    auto innerCylinder = CreateCylinder(1, 1);

    // Boolean filter to subtract inner cylinder from the outer one
    auto booleanFilter = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
    booleanFilter->SetOperationToUnion();
    booleanFilter->SetInputData(0, outerCylinder);
    booleanFilter->SetInputData(1, innerCylinder);
    booleanFilter->Update();

    // Mapper and actor for the resulting ring
    auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputData(booleanFilter->GetOutput());
    mapper->ScalarVisibilityOff();

    auto actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->EdgeVisibilityOn();

    ....
}

```

 ![3d1f4da5d92085cae65204b83d2b6b4](https://discourse.vtk.org/uploads/default/original/2X/5/537edd2393826653ad6a68958b37498bd67c4369.png)  
 ![a59dfd26d864d892f9e7315f82ec309](https://discourse.vtk.org/uploads/default/original/2X/6/6f96e97ccb8e147922ebf82d2200e19a520290dd.png)

Refer to： [What’s the problem? Somebody help me - Support - VTK](https://discourse.vtk.org/t/what-s-the-problem-somebody-help-me/1890)

---

<div class="post-metadata">

### Author: ![Jens\_Munk\_Hansen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jens_munk_hansen/32/1215_2.png) [@Jens\_Munk\_Hansen](https://discourse.vtk.org/u/Jens_Munk_Hansen)
#### Post date: [November 2, 2024, 8:52pm UTC](https://discourse.vtk.org/t/about-draw-a-cylindeical-ring-use-boolean-operation/14792/2 "2024-11-02T20:52:41Z")

</div>

Perhaps, you could use implicit functions instead, two vtkCylinder and two vtkPlane. Here I used two vtkCylinder and 4 vtkSphere

 ![Screenshot from 2024-11-02 21-55-14](https://discourse.vtk.org/uploads/default/original/2X/3/3cf98b57490a2a7073910581c7893b53c5eecc0c.png)
