# How to get the section area?

**URL:** <https://discourse.vtk.org/t/how-to-get-the-section-area/9078>\
**Category:** Development\
**Tags:** python\
**Created:** [August 4, 2022, 1:11am UTC](https://discourse.vtk.org/t/how-to-get-the-section-area/9078 "2022-08-04T01:11:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [August 4, 2022, 1:11am UTC](https://discourse.vtk.org/t/how-to-get-the-section-area/9078/1 "2022-08-04T01:11:10Z")

</div>

I want to get the section area of the Lumbar pedicle. I had got a the point cloud the section from numpy arrays, and then use 👇 code:

```python
def areaSect(points):
        ""
        verts = vtk.vtkPoints()
        polygon = vtk.vtkPolygon()

        polygon_pid = polygon.GetPointIds()
        for i, p in enumerate(points):
            verts.InsertNextPoint(*tuple(p))
            polygon_pid.InsertNextId(i)

        polygon_cell = vtk.vtkCellArray()
        polygon_cell.InsertNextCell(polygon)

        pd = vtk.vtkPolyData()
        pd.SetPoints(verts)
        pd.SetPolys(polygon_cell)

        model = slicer.mrmlScene.AddNewNodeByClass(
            'vtkMRMLModelNode', 'planeMod')
        model.CreateDefaultDisplayNodes()
        model.SetAndObservePolyData(pd)
        tri_converter = vtk.vtkTriangleFilter()
        tri_converter.SetInputDataObject(model.GetMesh())
        tri_converter.Update()
        Mass = vtk.vtkMassProperties() 
        Mass.SetInputData(tri_converter.GetOutput()) 
        Mass.Update() 
        return Mass.GetSurfaceArea()
[in]: areaSect(cP[1])
[out]: 49.16256299367866

```

However, 👆🏻this result(49.16256299367866) is too small for the 19\*10 section below 👇🏻

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/c0ff58672fbd79be6bc1813d8aa8bcdb321c669f.png)  
[psarr.csv](https://discourse.vtk.org/uploads/short-url/mQEsyoMOmvpRAjtfiIZf2gGLSzT.csv) (7.0 KB)

What’s wrong?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [August 4, 2022, 10:46am UTC](https://discourse.vtk.org/t/how-to-get-the-section-area/9078/2 "2022-08-04T10:46:29Z")

</div>

I think the order of points(np.array) seems an import reason, so reorder the np.array… I got a more smooth polygon and more area…but 😑 😑👇🏻

 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/2827056163a9128c513f2a92eaeff3fb05eae1bd.png)

How to patch this last seams👆🏻?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jumbojing/32/5578_2.png) [@jumbojing](https://discourse.vtk.org/u/jumbojing)\
**Post date:** [August 8, 2022, 12:16pm UTC](https://discourse.vtk.org/t/how-to-get-the-section-area/9078/3 "2022-08-08T12:16:30Z")

</div>

我想…其实这似乎就是根据距离最近对点进行排序的问题,对于这样的在同一平面的环形点云, 如何按照最近距离依次排序呢? 比如:以points[0]为起点按照一定方向找到一个最近点(设为points[1]), 然后再以points[1]为起点按照同一方向查找下一个最近点…依次类推…完成排序

> I think… Actually, this seems to be a problem of sorting points by the closest distance. For such a circular point cloud on a plane, how to sort by the closest distance? For example: set points[0] as the starting point to find a closest point in a certain direction (set as points[1]), and then set points[1] as the starting point to find the next closest point in the same direction… and so on… complete sorting.

@lassoan@Juicy@jamesobutler @jcfr @pieper@ jmhuie @manjula @szhang
