# How to spread points on a line evenly

Hi! I am working on a wing script and I want it to be quite realistic, so I have to make more physic calculation per wing than just one. I kinda got the spreading working after a few painful hours, but they arent in center…

``````        float interval = size.x / (PhysicSteps + 1);
for (int ps = 0; ps < PhysicSteps; ps++)
{
Vector3 offsetx = new Vector3((interval * ps) - size.x / 2, 0, 0);

Debug.DrawRay(transform.position + offsetx + positionOffset, liftDirection * liftforce, Color.green); //Lift
Debug.DrawRay(transform.position + offsetx + positionOffset, -velocity * dragforce, Color.blue); //Drag
}
``````

here with less physics for better visual

thoose should be in center…

Im not certain i understand your issue, but it seems that you just dont add enough points. heres the math of it at least.
you have a total of S steps, that you want to span X distance.

if you set your interaval I = X / S (you used X / (S + 1), so adjust the following accordingly if its necesary for parity or wtvr)
then step_0 starts at x = 0 * I = 0… this is good
your last step, step_n-1 = step_S-1 starts at x = (S - 1) * I = (S - 1) * (X / S) which does not equal X, as desired.

basically you want your last step to be EQUAL TO S, step_S starts at x = S * I = S * (X / S) = X

Well, it’s difficult to reason about your code without knowing any of the values involved here. Though obvious issues are for example this line:

Dividing by `(PhysicSteps + 1)` doesn’t make much sense. Your ps variables goes from 0 to `PhysicSteps - 1`, so why do you essentially offset one side by 2. So that `+1` probably should be a `-1`. That would make your offset to actually go from `-size.x/2` to `+size.x/2`.

What exactly is “positionOffset”? What value is size.x?

Note that those offsets are applied in worldspace. You probably should think in local space coordinates first and then just use transform.TransformPoint to get a worldspace point if necessary. Though the overall purpose of the script is not entirely clear since it’s just drawing lines at the moment. Certain physics calculations could probably be done in local space and you may just convert the final result to worldspace. Though we can’t really say anything definitely without more context.

1 Like

Thanks! till now I was still working on that… my brain is molten now lol

``````float interval = size.x / (PhysicSteps + 1);
Vector3 offsetx = new Vector3(((interval * (ps + 1)) - (size.x / 2)), 0, 0);
``````