当前位置: 首页>>代码示例>>C#>>正文


C# Solid.ComputeCentroid方法代码示例

本文整理汇总了C#中Solid.ComputeCentroid方法的典型用法代码示例。如果您正苦于以下问题:C# Solid.ComputeCentroid方法的具体用法?C# Solid.ComputeCentroid怎么用?C# Solid.ComputeCentroid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Solid的用法示例。


在下文中一共展示了Solid.ComputeCentroid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: f

        /*
        void f()
        {
          var cx, cy, cz, volume, v, i, x1, y1, z1, x2, y2, z2, x3, y3, z3;
          volume = 0;
          cx = 0; cy = 0; cz = 0;
          // Assuming vertices are in vertX[i], vertY[i], and vertZ[i]
          // and faces are faces[i, j] where the first index indicates the
          // face and the second index indicates the vertex of that face
          // The value in the faces array is an index into the vertex array
          i = 0;
          repeat (numFaces) {
        x1 = vertX[faces[i, 0]]; y1 = vertY[faces[i, 0]]; z1 = vertZ[faces[i, 0]];
        x2 = vertX[faces[i, 1]]; y2 = vertY[faces[i, 1]]; z2 = vertZ[faces[i, 1]];
        x3 = vertX[faces[i, 2]]; y3 = vertY[faces[i, 2]]; z3 = vertZ[faces[i, 2]];
        v = x1*(y2*z3 - y3*z2) + y1*(z2*x3 - z3*x2) + z1*(x2*y3 - x3*y2);
        volume += v;
        cx += (x1 + x2 + x3)*v;
        cy += (y1 + y2 + y3)*v;
        cz += (z1 + z2 + z3)*v;
        i += 1;
          }
          // Set centroid coordinates to their final value
          cx /= 4 * volume;
          cy /= 4 * volume;
          cz /= 4 * volume;
          // And, just in case you want to know the total volume of the model:
          volume /= 6;
        }
        */
        CentroidVolume GetCentroid( Solid solid )
        {
            CentroidVolume cv = new CentroidVolume();
              double v;
              XYZ v0, v1, v2;

              SolidOrShellTessellationControls controls
            = new SolidOrShellTessellationControls();

              controls.LevelOfDetail = 0;

              TriangulatedSolidOrShell triangulation = null;

              try
              {
            triangulation
              = SolidUtils.TessellateSolidOrShell(
            solid, controls );
              }
              catch( Autodesk.Revit.Exceptions
            .InvalidOperationException )
              {
            return null;
              }

              int n = triangulation.ShellComponentCount;

              for( int i = 0; i < n; ++i )
              {
            TriangulatedShellComponent component
              = triangulation.GetShellComponent( i );

            int m = component.TriangleCount;

            for( int j = 0; j < m; ++j )
            {
              TriangleInShellComponent t
            = component.GetTriangle( j );

              v0 = component.GetVertex( t.VertexIndex0 );
              v1 = component.GetVertex( t.VertexIndex1 );
              v2 = component.GetVertex( t.VertexIndex2 );

              v = v0.X*(v1.Y*v2.Z - v2.Y*v1.Z)
            + v0.Y*(v1.Z*v2.X - v2.Z*v1.X)
            + v0.Z*(v1.X*v2.Y - v2.X*v1.Y);

              cv.Centroid += v * (v0 + v1 + v2);
              cv.Volume += v;
            }
              }

              // Set centroid coordinates to their final value

              cv.Centroid /= 4 * cv.Volume;

              XYZ diffCentroid = cv.Centroid
            - solid.ComputeCentroid();

              Debug.Assert( 0.6 > diffCentroid.GetLength(),
            "expected centroid approximation to be "
            + "similar to solid ComputeCentroid result" );

              // And, just in case you want to know
              // the total volume of the model:

              cv.Volume /= 6;

              double diffVolume = cv.Volume - solid.Volume;

//.........这里部分代码省略.........
开发者ID:nbright,项目名称:GetCentroid,代码行数:101,代码来源:Command.cs


注:本文中的Solid.ComputeCentroid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。