public override Vector2 GetLeftOrRightMostPointFromOrigin(Vector2 origin, bool orientation)
        {
            if (convexHull == null || convexHull.hull.Count == 0)
            {
                return(Vector2.zero);
            }

            Vector2 axis = -origin.normalized;

            int   result   = 0;
            float bestProj = float.MaxValue;

            // Maximize angle with axis (minimize dot product)
            for (int i = 0; i < convexHull.hull.Count; ++i)
            {
                int side = ConvexHull2D.Orientation(origin, origin + axis, convexHull.hull[i]);

                if ((orientation && side >= 0) || (!orientation && side < 0))
                {
                    float proj = Vector2.Dot((convexHull.hull[i] - origin).normalized, axis);
                    if (proj < bestProj)
                    {
                        bestProj = proj;
                        result   = i;
                    }
                }
            }

            return(convexHull.hull[result]);
        }
Beispiel #2
0
 public void OnEnable()
 {
     convexHull = (ConvexHull2D)target;
 }