标签:画线 Vector3 贝塞尔 private Unity static pos1 pos3 bezierList
贝塞尔曲线 优化画线平滑
在代码中调用下面这个方法,传入自己所要平滑的曲线的点的List列表,BezierCheck()会计算出每2个点之间需要补充多少个贝塞尔补间的点。
private static Vector3 pos1;
private static Vector3 pos2;
private static Vector3 pos3;
private static Vector3 new_pos1;
private static Vector3 new_pos2;
private static Vector3 new_pos3;
#region 贝塞尔曲线优化检测
/// <summary>
/// 贝塞尔曲线优化检测
/// </summary>
public static void BezierCheck(List<Vector3> bezierList)
{
if (bezierList.Count > 2)
{
pos1 = bezierList[bezierList.Count - 3];
pos2 = bezierList[bezierList.Count - 2];
pos3 = bezierList[bezierList.Count - 1];
float count = (pos3 - pos1).magnitude / 0.25f;
if (count < 1)
{
return;
}
float pice = 1f / count;
new_pos1 = Bezier(pos1, pos2, pos3, 0f);
new_pos2 = Bezier(pos1, pos2, pos3, pice);
new_pos3 = Bezier(pos1, pos2, pos3, 2 * pice);
bezierList[bezierList.Count - 1] = new_pos3;
bezierList[bezierList.Count - 2] = new_pos2;
bezierList[bezierList.Count - 3] = new_pos1;
for (float i = 3f; i * pice < 1; i++)
{
bezierList.Add(Bezier(pos1, pos2, pos3, i * pice));
}
}
}
#endregion
上面那个方法里会调用到下面这个方法,这个方法的意义是计算出补间的贝塞尔点的坐标
private static Vector3 p0p1;
private static Vector3 p1p2;
private static Vector3 result;
#region 三点求贝塞尔曲线
/// <summary>
///三点求贝塞尔曲线
/// </summary>
/// <returns>The bezier.</returns>
/// <param name="p0">P0.</param>
/// <param name="p1">P1.</param>
/// <param name="p2">P2.</param>
/// <param name="t">T.</param>
public static Vector3 Bezier(Vector3 p0, Vector3 p1, Vector3 p2, float t)
{
p0p1 = (1 - t) * p0 + t * p1;
p1p2 = (1 - t) * p1 + t * p2;
result = (1 - t) * p0p1 + t * p1p2;
return result;
}
#endregion
标签:画线,Vector3,贝塞尔,private,Unity,static,pos1,pos3,bezierList 来源: https://blog.csdn.net/qq_41731286/article/details/122583971
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。