示例#1
0
        /// <summary>
        /// Returns points in a defined spiral.
        /// </summary>
        /// <param name="origin">Center position of the spiral.</param>
        /// <param name="direction">Direction in which the spiral spans.</param>
        /// <param name="extent">Length of the spiral along the direction.</param>
        /// <param name="innerRadius">Inner radius of the spiral; the distance between the center and the first point of the spiral.</param>
        /// <param name="outerRadius">Outer radius of the spiral; the distance from the center to the last point of the spiral.</param>
        /// <param name="turns">Number of times the spiral turns in itself.</param>
        /// <param name="points">Number of points in the spiral.</param>
        /// <param name="rotation">Rotation of the spiral along the direction.</param>
        /// <returns></returns>
        public static List <Vector3> Spiral(Vector3 origin, Vector3 direction, float extent, float innerRadius, float outerRadius, int turns, int points, float rotation)
        {
            if (points <= 1 || innerRadius < 0)
            {
                return(null);
            }

            Vector3 circleNormal = direction - origin;

            Components.Plane plane = new Components.Plane(direction);

            float width              = (outerRadius - innerRadius) / (points - 1);
            float height             = extent / (points - 1);
            float angleBetweenPoints = turns * 360 / (points - 1);

            List <Vector3> spiral = new List <Vector3>();

            for (int i = 0; i < points; i++)
            {
                float separationAngle = rotation + i * angleBetweenPoints;

                Vector3 originDeviation = GetPoint(origin, origin + direction, height * i);

                Vector3 point = plane.GetPoint(originDeviation, innerRadius + width * i, separationAngle);
                spiral.Add(point);
            }

            return(spiral);
        }
示例#2
0
        /// <summary>
        /// Returns points in a defined arc.
        /// </summary>
        /// <param name="origin">Center from which the arc is drawn.</param>
        /// <param name="normal">Normal vector of the arc; the direction in which it is pointing.</param>
        /// <param name="amplitude">Angle, in degrees, covered by the arc. 360 is a full circle.</param>
        /// <param name="horizontalRadius">Horizontal radius of an elliptic arc.</param>
        /// <param name="verticalRadius">Vertical radius of an elliptic arc.</param>
        /// <param name="radius">Radius of the arc; the distance between its center and a point.</param>
        /// <param name="points">Number of points in the arc.</param>
        /// <param name="rotation">Rotation of the circle; change the position of the first point.</param>
        /// <returns></returns>
        public static List <Vector3> Arc(Vector3 origin, Vector3 normal, float amplitude, float horizontalRadius, float verticalRadius, int points, float rotation)
        {
            if (horizontalRadius <= 0f || verticalRadius <= 0f)
            {
                return(null);
            }

            Vector3 arcNormal = normal - origin;

            Components.Plane plane = new Components.Plane(arcNormal);

            float amplitudeAngle = ClampAngle(amplitude);

            float angleBetweenPoints = 0f;

            if (amplitude < 360)
            {
                angleBetweenPoints = amplitude / (points - 1);
            }
            else
            {
                angleBetweenPoints = amplitude / points;
            }

            List <Vector3> circle = new List <Vector3>();

            for (int i = 0; i < points; i++)
            {
                float   separationAngle = rotation + i * angleBetweenPoints;
                Vector3 point           = plane.GetPoint(origin, horizontalRadius, verticalRadius, separationAngle);
                circle.Add(point);
            }

            return(circle);
        }
示例#3
0
        /// <summary>
        /// Returns a path of zigzaguing points.
        /// </summary>
        /// <param name="origin">Origin of the path.</param>
        /// <param name="direction">Direction in which the path extents.</param>
        /// <param name="deviation">Deviation of the path center from the origin. Values on range [-1, 1]: first point, center, first turning point.</param>
        /// <param name="extent">Length of the path.</param>
        /// <param name="amplitude">Distance between the two sides of the zigzag.</param>
        /// <param name="turns">Number of turning points of the path.</param>
        /// <param name="subdivisions">Number of divisions of the vector represented by two turning points.</param>
        /// <param name="rotation">Rotation of the path around the direction vector.</param>
        /// <returns></returns>
        public static List <Vector3> Zigzag(Vector3 origin, Vector3 direction, int deviation, float extent, float amplitude, int turns, int subdivisions, float rotation)
        {
            Components.Plane plane = new Components.Plane(direction);

            float width = amplitude / 2;
            float span  = extent / (turns - 1);

            float horizontalDeviation = width * Mathf.Clamp(deviation, -1, 1);

            float vectorDirection = 1;

            List <Vector3> vectors = new List <Vector3>();

            for (int i = 0; i < turns; i++)
            {
                Vector3 point = new Vector3();
                point.x = vectorDirection * width + horizontalDeviation;
                point.y = 0f;
                point.z = span * i;

                point = plane.Rotate(point, rotation, Components.Plane.Axis.N);
                point = origin + plane.TransformPoint(point);

                vectors.Add(point);
                vectorDirection = -vectorDirection;
            }

            if (subdivisions <= 1)
            {
                return(vectors);
            }

            List <Vector3> points = new List <Vector3>();

            for (int i = 1; i < vectors.Count; i++)
            {
                List <Vector3> dividedVector = Subdivide(vectors[i - 1], vectors[i], subdivisions);
                points.AddRange(dividedVector);
            }

            points = points.Distinct().ToList();

            return(points);
        }
示例#4
0
        /// <summary>
        /// Returns points in a defined wave.
        /// </summary>
        /// <param name="origin">Origin of the wave.</param>
        /// <param name="direction">Direction in which the wave spans.</param>
        /// <param name="extent">Length of th wave.</param>
        /// <param name="amplitude">Amplitude of the wave; the distance between opposing peaks.</param>
        /// <param name="frequency">Frecuency of periods in the wave.</param>
        /// <param name="points">Points to draw accross the wave.</param>
        /// <param name="rotation">Rotation of the wave around the direction vector.</param>
        /// <returns></returns>
        public static List <Vector3> Wave(Vector3 origin, Vector3 direction, float extent, float amplitude, float frequency, int points, float rotation)
        {
            Components.Plane plane      = new Components.Plane(direction);
            float            separation = extent / (points - 1);

            List <Vector3> wavePoints = new List <Vector3>();

            for (int i = 0; i < points; i++)
            {
                Vector3 point = new Vector3();
                point.x = amplitude * Mathf.Sin(frequency * (separation * i));
                point.y = 0f;
                point.z = separation * i;

                point = plane.Rotate(point, rotation, Components.Plane.Axis.N);
                point = origin + plane.TransformPoint(point);

                wavePoints.Add(point);
            }

            return(wavePoints);
        }
示例#5
0
 /// <summary>
 /// Returns a point at given degrees and distance from origin around the normal of a geometrical plane.
 /// </summary>
 /// <param name="origin"></param>
 /// <param name="radius"></param>
 /// <param name="degrees"></param>
 /// <returns></returns>
 public static Vector3 GetPoint(Vector3 origin, Vector3 normal, float radius, float degrees)
 {
     Components.Plane plane = new Components.Plane(normal);
     return(plane.GetPoint(origin, radius, degrees));
 }