# How to calculate the spline arc length?

hi,any body,
i testing the racing game,and need get the arc length in 3 contoller points spline,like this link:
Cg Programming/Unity/Bézier Curves - Wikibooks, open books for an open world ,
want getArcLenght at “f” point,need your help~,3Q!

``````   var t : float;
var position : Vector3;
for(var i : int = 0; i < numberOfPoints; i++)
{
t = i / (numberOfPoints - 1.0);
position = (1.0 - t) * (1.0 - t) * p0
+ 2.0 * (1.0 - t) * t * p1
+ t * t * p2;
lineRenderer.SetPosition(i, position);
}
``````

What,
Spain Lucy.

Store all positions to an array, because there is no other way to get LineRenderer positions. Then, calculate distance between those positions and sum them to variable. Here is how it would look like:

``````var lineRenderer : LineRenderer = GetComponent(LineRenderer);
var t : float;
var position : Vector3;
var positions : Vector3[] = new Vector3[numberOfPoints];
for(var i : int = 0; i < numberOfPoints; i++)
{
t = i / (numberOfPoints - 1.0);
position = (1.0 - t) * (1.0 - t) * p0
+ 2.0 * (1.0 - t) * t * p1
+ t * t * p2;
positions[i] = position;

lineRenderer.SetPosition(i, position);
}

var totalDistance : float;
for(var a : int = 0; a < numberOfPoints - 1; a++)
totalDistance += Vector3.Distance(positions[a], positions[a + 1]);
Debug.Log("distance:" + totalDistance);
``````

The only reliable way to get the curved arc length is to sample it several times and sum the step lengths… probably… is how I’m doing it