Beispiel #1
0
        public static List <Vector2> Generate2DArcBorderPoints(Vector2 arcOrigin, Vector2 arcStartPoint, float degreesFromStart, bool forceShortestArc, int numPoints)
        {
            if (numPoints < 2)
            {
                return(new List <Vector2>());
            }

            var arcPoints = new List <Vector2>(numPoints);

            degreesFromStart %= 360.0f;

            Vector2    toStartPt = (arcStartPoint - arcOrigin);
            Quaternion rotation  = Quaternion.AngleAxis(degreesFromStart, Vector3.forward);
            float      arcRadius = toStartPt.magnitude;

            toStartPt.Normalize();

            if (forceShortestArc)
            {
                degreesFromStart = ArcMath.ConvertToSh2DArcAngle(arcOrigin, arcStartPoint, degreesFromStart);
            }

            float angleStep = degreesFromStart / (numPoints - 1);

            for (int ptIndex = 0; ptIndex < numPoints; ++ptIndex)
            {
                float angle = ptIndex * angleStep;
                rotation = Quaternion.AngleAxis(angle, Vector3.forward);
                Vector2 rotatedAxis = (rotation * toStartPt).normalized;
                arcPoints.Add(arcOrigin + rotatedAxis * arcRadius);
            }

            return(arcPoints);
        }
        public static bool ShArcContains2DPoint(Vector2 point, Vector2 arcOrigin, Vector2 arcStartPoint, float degreesFromStart, ArcEpsilon epsilon = new ArcEpsilon())
        {
            degreesFromStart   = ArcMath.ConvertToSh2DArcAngle(arcOrigin, arcStartPoint, degreesFromStart);
            epsilon.ExtrudeEps = 0.0f;

            return(ShArcContains3DPoint(point.ToVector3(), false, arcOrigin.ToVector3(), arcStartPoint.ToVector3(), Vector3.forward, degreesFromStart, epsilon));
        }