# Plot points along a curve

Hi,

I have a start and end position and need to create points along a curve, but i’m unsure how to achieve this.

I found this on a maths forum for creating a bezier curve:

``````        Vector2 start = new Vector2(10,10);
Vector2 end = new Vector2(300,10);
Vector2 bezier = new Vector2(150,200);

for(double t=0.0; t<=1; t+=0.01) {
int x = (int) ( (1-t)*(1-t)*start.x + 2*(1-t)*t*bezier.x+t*t*end.x);
int y = (int) ( (1-t)*(1-t)*start.y + 2*(1-t)*t*bezier.y+t*t*end.y);
//plot something @  x,y coordinate here...
}
``````

the trouble is, I need to instantiate game objects at specific points along this curve, all equally spaced apart, and i’ve no idea how to do this - how do I know at which point in this loop I should be instantiating one of my game objects?

Thanks

Mat

This isn’t mine. I think it was from the Unity3d Answers.

So you can either pass in the Vectors of the line or you can just have them at least created in the class this exists.
This will get you the point at a specified time interval. The time value is between 0 - 1. So however many segments you want just put that under 1. (1/10 → 10 segments)

``````public Vector3 CalculateBezierPoint(float time)
{
float u = 1 - time;

float tt = time * time;
float uu = u * u;
float uuu = uu * u;
float ttt = tt * time;

Vector3 p = uuu * StartVector; //first term
p += 3 * uu * time * StartTangent; //second term
p += 3 * u * tt * EndTangent; //third term
p += ttt * EndVector; //fourth term

return p;
}
``````