Exemple #1
0
        /// <summary>
        /// Gets the polyhedron feature that is the most extreme, or furthest along, the specified direction.
        /// </summary>
        /// <remarks>
        /// If two vertices are equally far along the given direction, then an edge feature is returned. If more
        /// than two vertices are equally far, then the extreme feature is a face.
        /// </remarks>
        /// <param name="d">The normalized direction vector along which to search for an extreme feature.</param>
        /// <returns>Returns the extreme feature that is furthest along the specified direction.</returns>
        public PolyhedronFeature ExtremeFeature(ref Vector3 d)
        {
            PolyhedronFeature e = ExtremeVertex(ref d);
            Vector3           v;

            int vIndex = e.Index;

            for (int i = 0; i < _compiled.Neighbors[vIndex].Length; i++)
            {
                float x;
                int   newIndex = _compiled.Neighbors[vIndex][i];
                v = _world[newIndex];
                Vector3.Dot(ref d, ref v, out x);
                if (FloatHelper.Equals(x, e.X))
                {
                    if (e.Type == PolyhedronFeatureType.Vertex)
                    {
                        for (int j = 0; j < _compiled.Edges.Length; j++)
                        {
                            if ((_compiled.Edges[j][0] == vIndex && _compiled.Edges[j][1] == newIndex) ||
                                (_compiled.Edges[j][0] == newIndex && _compiled.Edges[j][1] == vIndex))
                            {
                                e.Type  = PolyhedronFeatureType.Edge;
                                e.Index = j;
                                break;
                            }
                        }
                    }
                    else if (e.Type == PolyhedronFeatureType.Edge)
                    {
                        for (int j = 0; j < _compiled.Faces.Length; j++)
                        {
                            int count = 0;
                            for (int k = 0; k < _compiled.Faces[j].Length; k++)
                            {
                                if (_compiled.Faces[j][k] == _compiled.Edges[e.Index][0] ||
                                    _compiled.Faces[j][k] == _compiled.Edges[e.Index][1] ||
                                    _compiled.Faces[j][k] == newIndex)
                                {
                                    count++;
                                }
                                if (count > 2)
                                {
                                    break;
                                }
                            }
                            if (count > 2)
                            {
                                e.Type  = PolyhedronFeatureType.Face;
                                e.Index = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(e);
        }
Exemple #2
0
        /// <summary>
        /// Gets the polyhedron feature that is the most extreme, or furthest along, the specified direction and for which
        /// all vertices are at least as extreme as the specified depth.
        /// </summary>
        /// <remarks>
        /// If two vertices are more extreme than the specified depth, then an edge is returned. If more than two vertices are
        /// more extreme than the specified depth, then a face is returned. The result will always include the vertex of maximum
        /// extremity.
        /// </remarks>
        /// <param name="d">The normalized direction vector along which to search for an extreme feature.</param>
        /// <param name="depth">All vertices that make up the returned feature must be at least this "deep" along the
        /// given direction.</param>
        /// <returns>Returns the extreme feature.</returns>
        public PolyhedronFeature ExtremeFeature(ref Vector3 d, float depth)
        {
            PolyhedronFeature e = ExtremeVertex(ref d);
            Vector3           v;

            if (depth - e.X >= Constants.Epsilon)
            {
                e.Type = PolyhedronFeatureType.None;
                return(e);
            }

            int vIndex = e.Index;

            for (int i = 0; i < _compiled.Neighbors[vIndex].Length; i++)
            {
                float x;
                int   newIndex = _compiled.Neighbors[vIndex][i];
                World(newIndex, out v);
                Vector3.Dot(ref d, ref v, out x);
                if (x >= depth)
                {
                    if (e.Type == PolyhedronFeatureType.Vertex)
                    {
                        for (int j = 0; j < _compiled.Edges.Length; j++)
                        {
                            if ((_compiled.Edges[j][0] == vIndex && _compiled.Edges[j][1] == newIndex) ||
                                (_compiled.Edges[j][0] == newIndex && _compiled.Edges[j][1] == vIndex))
                            {
                                e.Type  = PolyhedronFeatureType.Edge;
                                e.Index = j;
                                break;
                            }
                        }
                    }
                    else if (e.Type == PolyhedronFeatureType.Edge)
                    {
                        for (int j = 0; j < _compiled.Faces.Length; j++)
                        {
                            int count = 0;
                            for (int k = 0; k < _compiled.Faces[j].Length; k++)
                            {
                                if (_compiled.Faces[j][k] == _compiled.Edges[e.Index][0] ||
                                    _compiled.Faces[j][k] == _compiled.Edges[e.Index][1] ||
                                    _compiled.Faces[j][k] == newIndex)
                                {
                                    count++;
                                }
                                if (count > 2)
                                {
                                    break;
                                }
                            }
                            if (count > 2)
                            {
                                e.Type  = PolyhedronFeatureType.Face;
                                e.Index = j;
                                break;
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            return(e);
        }