public List <Vector3> SubdivideEvenly(int divisions) { List <Vector3> verts = new List <Vector3>(); float length = GetLength(); float deltaLength = length / divisions + 0.001f; float t = 0.000f; // we always start at the first control point Vector2 start = ControlPoints[0]; Vector2 end = GetPosition(t); // increment t until we are at half the distance while (deltaLength * 0.5f >= Vector2.Distance(start, end)) { end = GetPosition(t); t += 0.0001f; if (t >= 1f) { break; } } start = end; // for each box for (int i = 1; i < divisions; i++) { Vector2 normal = GetPositionNormal(t); float angle = (float)Math.Atan2(normal.y, normal.x); verts.Add(new Vector3(end, angle)); // until we reach the correct distance down the curve while (deltaLength >= Vector2.Distance(start, end)) { end = GetPosition(t); t += 0.00001f; if (t >= 1f) { break; } } if (t >= 1f) { break; } start = end; } return(verts); }
public float GetLength() { List <Vector2> verts = GetVertices(ControlPoints.Count * 25); float length = 0; for (int i = 1; i < verts.Count; i++) { length += Vector2.Distance(verts[i - 1], verts[i]); } if (Closed) { length += Vector2.Distance(verts[ControlPoints.Count - 1], verts[0]); } return(length); }