Skip to content

algorithm-planet/Smooth_Path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smooth_Path

Constant distance Bezeier Spline

public float Distance_(float t)
{
    int resolution = 100;
    float t_h = 1f / resolution;

    float sum = 0;
    for(float t_i = t_h; t_i <= t; t_i += t_h)
    {
        Vector3 current_v = bezier.position(t_i);
        Vector3 prev_v = bezier.position(t_i - t_h);

        sum += Vector3.Magnitude(current_v - prev_v);
    }
    return sum;
}
public float Ping_(float t)
{
    float d = Mathf.RoundToInt(t / t_s) * d_s;
    float t_current = t;

    int i = 0;
    while (true)
    {
        //
        float new_D = Distance_(t_current) - d;
        float new_v = bezier.velocity(t_current).magnitude;

        float t_next = t_current - new_D / new_v;

        float accuracy = 0.1f;
        i += 1;
        if (i > 10 || Mathf.Abs(t_current - t_next) < accuracy * t_s)
        {
            //Debug.Log(i);
            break;
        }

        t_current = t_next;
    }
    return t_current;
}

About

Constant distance Bezeier Spline

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages