Cancel
Showing results for 
Search instead for 
Did you mean: 

Volume calculation of 3D Geometry

Valued Contributor
Valued Contributor

Hello,

 

is there any way to calculate the volume of the 3D geometry with API?

 

Thank you in advance,

Witalij.

4 REPLIES

Re: Volume calculation of 3D Geometry

Siemens Legend Siemens Legend
Siemens Legend

You can access the TxOject geometry using ITxGeometry.Approximation

(provided the object has Geometry, some objects don't have...).

This returns a class called TxApproximationData which contains the vertices (Points), Normals and faces (Primitives).

 

From the mesh geometry you can calculate the volume yourself. Not all meshes have trivial volume or a volume at all.

See this for example:

how-to-calculate-the-volume-of-a-3d-mesh-object

 

Re: Volume calculation of 3D Geometry

Phenom
Phenom

@Zachi_Mann

 

How would you approximate a volume when you only have points data (like in collision contour data)? I've seen convex hull solution, but have not tried to implement yet.

 

Regards

Re: Volume calculation of 3D Geometry

Valued Contributor
Valued Contributor

Thank you!

 

I put here my function to calculate the volume of the 3D body based on the approximation (may be somebody else will required it also):

#Region "GetVolume"
    ''' <summary>
    ''' Calculate the volume of the <see cref="ITx2Or3DimensionalGeometry"/> based on the aprroximation data.
    ''' </summary>
    ''' <param name="geometry">The <see cref="ITx2Or3DimensionalGeometry"/>.</param>
    ''' <returns>The calculated volume value.</returns>
    <Extension>
    Public Function GetVolume(geometry As ITx2Or3DimensionalGeometry) As Double
        Dim primitives() As TxPrimitiveData = geometry.Approximation.Primitives.ToArray()
        Return (From p As TxPrimitiveData In primitives Select GetSignedVolume(p)).Sum()
    End Function

    ''' <summary>
    ''' Calculates the signed volume value for a <see cref="TxPrimitiveData"/>.
    ''' </summary>
    ''' <param name="primitive">The <see cref="TxPrimitiveData"/>.</param>
    ''' <returns>The signed volume value.</returns>
    Private Function GetSignedVolume(primitive As TxPrimitiveData) As Double
        Dim sideA As TxVector = primitive.Approximation.Points(primitive.Indices(1)) - primitive.Approximation.Points(primitive.Indices(0))
        Dim sideB As TxVector = primitive.Approximation.Points(primitive.Indices(2)) - primitive.Approximation.Points(primitive.Indices(0))
        Dim normal As TxVector = TxVector.CrossProduct(sideA, sideB)
        Dim sign As Double = 1
        If normal.GetAngle(primitive.Approximation.Normals(primitive.Indices(0))) > Math.PI / 2.0R Then sign = -1
        Return sign * TxVector.DotProduct(primitive.Approximation.Points(primitive.Indices(0)),
                                          TxVector.CrossProduct(primitive.Approximation.Points(primitive.Indices(1)),
                                                                primitive.Approximation.Points(primitive.Indices(2)))) / 6.0R
    End Function
#End Region

 

The usage is straight forward:

 

Dim geometrie As ITx2Or3DimensionalGeometry = TxApplication.ActiveSelection.GetItems()(0)
        MsgBox(geometrie.GetVolume())

Re: Volume calculation of 3D Geometry

Siemens Legend Siemens Legend
Siemens Legend

Convex hull is easy to calculate and yields an upper bound on the volume, yet it does not consider e.g., cavities.

There are many spatial algorithms which attempt to create an estimate, but since point cloud is partial information, there can always be some case of error.

You can check this goolge search.