Esempio n. 1
0
        /// <summary>
        /// from a given point in space, order the face, from the closest to the farrest from the point
        ///
        ///         cube
        ///      6 ------------ 7
        ///    / |    3       / |
        ///  5 ------------ 8   |
        ///  |   |          |   |
        ///  | 5 |     6    | 2-|------------  face
        ///  |   |   1      |   |
        ///  |  2 ----------|-- 3
        ///  |/       4     | /
        ///  1 ------------ 4
        /// </summary>
        /// <returns></returns>
        public static FloatRange[] GetOrdersOfFaceFromPoint(ExtCube cube, Vector3 point)
        {
            FloatRange[] faceDistance = new FloatRange[6];

            faceDistance[0] = new FloatRange(1, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P1, cube.P5, cube.P8, cube.P4), point));
            faceDistance[1] = new FloatRange(2, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P4, cube.P8, cube.P7, cube.P3), point));
            faceDistance[2] = new FloatRange(3, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P5, cube.P6, cube.P7, cube.P8), point));
            faceDistance[3] = new FloatRange(4, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P1, cube.P2, cube.P3, cube.P4), point));
            faceDistance[4] = new FloatRange(5, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P2, cube.P6, cube.P5, cube.P1), point));
            faceDistance[5] = new FloatRange(6, ExtVector3.DistanceSquared(ExtVector3.GetMeanOfXPoints(cube.P3, cube.P7, cube.P6, cube.P2), point));

            faceDistance = FloatRange.Sort(faceDistance);
            return(faceDistance);
        }