# How to find the length of a Vector3.Slerp curve

I have an object that is moving in a spherical arc between two points, using Vector3.Slerp.

My code snipped moves the object at an arbitrary speed, but I’d like to change it to control the exact movement speed along the curve. I figure that if I know the length of the curve, then I can figure out how much time it should take to Slerp between those point, and use that to calculate t in Vector3.Slerp.

So, I don’t suppose there’s a way to get at the length of the Slerp curve?
Or a different way to move in a spherical arc between two points that allows me to control the movement speed?

Does anyone know how to find the length of a Slerp curve?

``````	Vector3 unitRelativeVector = transform.position - groundTransform.position;
Vector3 targetRelativeCenter = moveTarget.position - groundTransform.position;
transform.position = Vector3.Slerp(unitRelativeVector, targetRelativeCenter, moveSpeed * Time.deltaTime) + groundTransform.position;
``````

Generally speaking “exact speed” and “slerp” do not belong in the same sentence. I think you’d be better served devising an alternate method of controlling motion. Maybe you require bezier curves for this?

If Slerp does exactly what you want except for the controlled speed thing, and really all you need is the length, you could pre-calculate the length of the slerp curve by sampling N points (same A, same B, different delta). Store these collected samples in an array, then measure the distance between consecutive points. This would be an approximation whose accuracy would improve with the number of samples taken, at the expense of performance.

Untested:

`````` int sampleCount = 10;
Vector3 previousSample = A;
float distance = 0;
for (int i=1; i<sampleCount; i++) {
Vector3 sample = Vector3.Slerp(A, B, (float)i/(float)sampleCount );
distance += Vector3.Distance(sample, previousSample);
previousSample = sample;
}
// distance approximated
``````