6using System.Collections.Generic;
24 static Vector2[] emptyCurve =
new Vector2[] {
new Vector2(0.0f, 0.0f),
new Vector2(0.0f, 0.0f) };
30 get {
return m_regen; }
39 get {
return m_start; }
60 get {
return m_slack; }
65 m_slack = Mathf.Max(0.0f, value);
70 get {
return m_steps; }
75 m_steps = Mathf.Max(2, value);
83 Vector2 mid = Vector2.zero;
86 return (points[0] + points[1]) * 0.5f;
91 if ((m_steps % 2) == 0)
93 mid = (points[m] + points[m + 1]) * 0.5f;
107 m_start = Vector2.up;
108 m_end = Vector2.up + Vector2.right;
116 points = inputPoints;
117 m_start = inputPoints[0];
118 m_end = inputPoints[1];
126 points = inputPoints.ToArray();
127 m_start = inputPoints[0];
128 m_end = inputPoints[1];
152 float lineDist = Vector2.Distance(m_end, m_start);
153 float lineDistH = Vector2.Distance(
new Vector2(m_end.x, m_start.y), m_start);
154 float l = lineDist + Mathf.Max(0.0001f, m_slack);
163 float ztarget = Mathf.Sqrt(Mathf.Pow(l, 2.0f) - Mathf.Pow(v - s, 2.0f)) / (u - r);
166 int iterationCount = 0;
167 int maxIterations = loops * 10;
172 float zstep = 100.0f;
173 float ztesttarget = 0.0f;
174 for (
int i = 0; i < loops; i++)
176 for (
int j = 0; j < 10; j++)
180 ztesttarget = (float)
Math.Sinh(ztest) / ztest;
182 if (
float.IsInfinity(ztesttarget))
185 if (ztesttarget == ztarget)
191 else if (ztesttarget > ztarget)
200 if (iterationCount > maxIterations)
213 float a = (u - r) / 2.0f / z;
214 float p = (r + u - a * Mathf.Log((l + v - s) / (l - v + s))) / 2.0f;
215 float q = (v + s - l * (float)
Math.Cosh(z) / (float)
Math.Sinh(z)) / 2.0f;
217 points =
new Vector2[m_steps];
218 float stepsf = m_steps - 1;
220 for (
int i = 0; i < m_steps; i++)
223 Vector2 pos = Vector2.zero;
224 pos.x = Mathf.Lerp(
start.x,
end.x, stepf);
225 pos.y = a * (float)
Math.Cosh(((stepf * lineDistH) - p) / a) + q;
CableCurve(List< Vector2 > inputPoints)
CableCurve(Vector2[] inputPoints)
Credit Erdener Gonenc - @PixelEnvision.