예제 #1
0
        /// <summary>
        /// Return an arbitrary point on a planar face,
        /// namely the midpoint of the first mesh triangle.
        /// </summary>
        XYZ PointOnFace(PlanarFace face)
        {
            Mesh mesh = face.Triangulate();

            return(0 < mesh.NumTriangles
        ? MedianPoint(mesh.get_Triangle(0))
        : XYZ.Zero);
        }
예제 #2
0
        public static XYZ Meshvector(this PlanarFace planarFace)
        {
            Mesh mesh   = planarFace.Triangulate();
            var  fg     = mesh.Vertices;
            var  p1     = fg[0];
            var  p2     = fg[1];
            var  vector = p1 - p2;

            return(vector);
        }
예제 #3
0
        public static XYZ CenterPoint(PlanarFace face)
        {
            XYZ         xyz  = new XYZ();
            Mesh        mesh = face.Triangulate();
            IList <XYZ> list = new List <XYZ>();

            foreach (XYZ xyz2 in mesh.Vertices)
            {
                xyz += xyz2;
                list.Add(xyz2);
            }
            xyz /= (double)list.Count;
            return(xyz);
        }
예제 #4
0
        /// <summary>
        /// Return an arbitrary point on a planar face,
        /// namely the midpoint of the first mesh triangle.
        /// </summary>
        XYZ PointOnFace(PlanarFace face)
        {
            XYZ  p    = new XYZ(0, 0, 0);
            Mesh mesh = face.Triangulate();

            for (int i = 0; i < mesh.NumTriangles;)
            {
                MeshTriangle triangle = mesh.get_Triangle(i);
                p += triangle.get_Vertex(0);
                p += triangle.get_Vertex(1);
                p += triangle.get_Vertex(2);
                p *= 0.3333333333333333;
                break;
            }
            return(p);
        }
예제 #5
0
        /// <summary>
        /// Return a 'good' point on a planar face, namely
        /// the median point of its largest mesh triangle.
        /// </summary>
        XYZ PointOnFace2(PlanarFace face)
        {
            Mesh   mesh     = face.Triangulate();
            double max_area = 0;
            int    selected = 0;

            for (int i = 0; i < mesh.NumTriangles; i++)
            {
                double area = TriangleArea(
                    mesh.get_Triangle(i));

                if (max_area < area)
                {
                    max_area = area;
                    selected = i;
                }
            }
            return(MedianPoint(mesh.get_Triangle(selected)));
        }
        /// <summary>
        /// returns the average height of a face by averaging it's points' v values (for ruled faces - origin is returned fro planar faces.
        /// </summary>
        /// <param name="f">the face</param>
        /// <returns>average height of the face, or it's origin height</returns>
        private static double GetAverageFaceHeight(Autodesk.Revit.DB.Face f)
        {
            double d = 0.0;

            //if face is a ruled face, average the z value of it's mesh vertices
            RuledFace rf = f as RuledFace;

            if (rf != null)
            {
                double total = 0.0;
                int    i     = 1;
                foreach (XYZ v in rf.Triangulate().Vertices)
                {
                    total = total + v.Z;
                    i++;
                }

                //return the average
                d = total / (double)i;
            }
            else // if it isn't a ruled face, treat it as planar and return the origin
            {
                PlanarFace pf = f as PlanarFace;
                if (pf != null)
                {
                    double total = 0.0;
                    int    i     = 1;
                    foreach (XYZ v in pf.Triangulate().Vertices)
                    {
                        total = total + v.Z;
                        i++;
                    }

                    //return the average
                    d = total / (double)i;
                }
            }

            return(d);
        }
        /// <summary>
        /// Return an arbitrary point on a planar face,
        /// namely the midpoint of the first mesh triangle.
        /// </summary>
        XYZ PointOnFace( PlanarFace face )
        {
            XYZ p = new XYZ( 0, 0, 0 );
              Mesh mesh = face.Triangulate();

              for( int i = 0; i < mesh.NumTriangles; )
              {
            MeshTriangle triangle = mesh.get_Triangle( i );
            p += triangle.get_Vertex( 0 );
            p += triangle.get_Vertex( 1 );
            p += triangle.get_Vertex( 2 );
            p *= 0.3333333333333333;
            break;
              }
              return p;
        }
        private static Autodesk.DesignScript.Geometry.Point getAveragePointFromFace(Autodesk.Revit.DB.Face f)
        {
            //the point to return
            Autodesk.DesignScript.Geometry.Point p = null;

            //if face is a ruled face
            RuledFace rf = f as RuledFace;

            if (rf != null)
            {
                //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(rf.Triangulate());
                var points = m.VertexPositions;


                int    numVertices = points.Count();
                double x = 0, y = 0, z = 0;
                foreach (var v in points)
                {
                    x = x + v.X;
                    y = y + v.Y;
                    z = z + v.Z;
                }
                x = x / numVertices;
                y = y / numVertices;
                z = z / numVertices;
                p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
            }
            else // if it isn't a ruled face, treat it as planar
            {
                PlanarFace pf = f as PlanarFace;
                if (pf != null)
                {
                    //units seem to be messed up...  convert to a designscript mesh first, then pull from that
                    Autodesk.DesignScript.Geometry.Mesh m = Revit.GeometryConversion.RevitToProtoMesh.ToProtoType(pf.Triangulate());
                    var points = m.VertexPositions;


                    int    numVertices = points.Count();
                    double x = 0, y = 0, z = 0;
                    foreach (var v in points)
                    {
                        x = x + v.X;
                        y = y + v.Y;
                        z = z + v.Z;
                    }
                    x = x / numVertices;
                    y = y / numVertices;
                    z = z / numVertices;
                    p = Autodesk.DesignScript.Geometry.Point.ByCoordinates(x, y, z);
                }
            }
            return(p);
        }