Exemplo n.º 1
0
        /// <summary>
        /// return points array along circle from start point
        /// </summary>
        /// <param name="startPoint"></param>
        /// <param name="center">rotate center</param>
        /// <param name="angle">degree</param>
        /// <param name="step"></param>
        /// <param name="pointsCount"></param>
        /// <returns></returns>
        public static Vector3[] CirclePointsAroundZ(Vector3 startPoint, Vector3 center, float degAngle, int pointsCount)
        {
            Vector3[] cList = new Vector3[pointsCount];
            cList[0] = startPoint;
            float radAngle = degAngle * Mathf.Deg2Rad;
            // float startAngle = Mathf.Deg2Rad * Vector2.Angle((startPoint - center), Vector2.right);
            float startAngle = Mathf.Deg2Rad * MathMk.GetFullAngleOX((startPoint - center));
            float cRadius    = Vector3.Distance(startPoint, center);
            float dAngle     = radAngle / (pointsCount);

            for (int i = 1; i < pointsCount; i++)
            {
                float   newAngle = startAngle + i * dAngle;
                Vector3 pos      = center + cRadius * new Vector3(Mathf.Cos(newAngle), Mathf.Sin(newAngle), 0);
                cList[i] = pos;
            }
            return(cList);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Return array of points on arc inbetween two degree angles
        /// </summary>
        /// <param name="center"></param>
        /// <param name="circleRadius"></param>
        /// <param name="startAngle"></param>
        /// <param name="endAngle"></param>
        /// <param name="pointsCount"></param>
        /// <returns></returns>
        public static Vector3[] ArcPoints(Vector3 center, float circleRadius, Vector2 startDirection, Vector2 endDirection, int pointsCount)
        {
            float radStart = Mathf.Deg2Rad * MathMk.GetFullAngleOX(startDirection);

            Debug.Log("startAngle" + MathMk.GetFullAngleOX(startDirection));
            if (pointsCount == 0 || pointsCount == 1 || startDirection == endDirection)
            {
                return(new Vector3[] { new Vector3(Mathf.Cos(radStart), Mathf.Sin(radStart), 0) * circleRadius });
            }
            Vector3[] result = new Vector3[pointsCount];
            float     radEnd = Mathf.Deg2Rad * MathMk.GetFullAngleOX(endDirection);

            Debug.Log("endAngle" + MathMk.GetFullAngleOX(endDirection));
            float dAngle = (radEnd - radStart) / (pointsCount - 1);

            for (int i = 0; i < pointsCount; i++)
            {
                float currAngle = radStart + i * dAngle;
                result[i] = center + new Vector3(Mathf.Cos(currAngle), Mathf.Sin(currAngle), 0) * circleRadius;
            }
            return(result);
        }