Пример #1
0
        public static (float[], int[]) GetBisectedThetaValues(IPoly polygon, int index)
        {
            Vector3 center = polygon.GetPoint(index);
            Vector3 left   = polygon.GetPointWrapped(index - 1);
            Vector3 right  = polygon.GetPointWrapped(index + 1);
            Vector3 biSect = Vector3.Lerp((left - center).normalized, (right - center).normalized, 0.5f).normalized;

            int[]   indicies = new int[polygon.Resolution - 1];
            float[] tValues  = new float[polygon.Resolution - 1];
            for (int i = 0; i < polygon.Resolution; i++)
            {
                if (i < index)
                {
                    indicies[i] = i;
                    tValues[i]  = Vector3.Dot(biSect, (polygon.GetPoint(i) - center).normalized);
                }
                else if (i == index)
                {
                    continue;
                }
                else
                {
                    indicies[i - 1] = i;
                    tValues[i - 1]  = Vector3.Dot(biSect, (polygon.GetPoint(i) - center).normalized);
                }
            }
            Array.Sort(tValues, indicies);
            return(tValues, indicies);
        }
Пример #2
0
        public static bool IsEdgeIntersectingPolygon(IPoly polygon, Vector3 point1, Vector3 point2)
        {
            for (int i = 0; i < polygon.Resolution; i++)
            {
                Vector3 a = polygon.GetPoint(i);
                Vector3 b = polygon.GetPointWrapped(i + 1);
                if ((point1 - a).sqrMagnitude < 0.0001f)
                {
                    continue;
                }
                if ((point1 - b).sqrMagnitude < 0.0001f)
                {
                    continue;
                }
                if ((point2 - a).sqrMagnitude < 0.0001f)
                {
                    continue;
                }
                if ((point2 - b).sqrMagnitude < 0.0001f)
                {
                    continue;
                }

                if (Math3d.AreLineSegmentsCrossing(a, b, point1, point2))
                {
                    return(true);
                }
            }
            return(false);
        }