最近在做簽字筆的效果,最初用linerender直接幾個點連成一條線的效果並不是很好,特別是當拐彎的時候會有缺口。想要拐彎處變得圓滑起來,決定采用Bezier curve。
定義:起始點、終止點(也稱錨點)、控制點。通過調整控制點,貝塞爾曲線的形狀會發生變化。
- 由 P0 至 P1 的連續點 Q0,描述一條線段
- 由 P1 至 P2 的連續點 Q1,描述一條線段
- 由 Q0 至 Q1 的連續點 B(t),描述一條二次貝塞爾曲線
void GetPathPoints(Vector2 controlPoints) Vector2[] point = new List<Vector2>()/ /最終貝塞爾曲線上點的集合 int pointNumber = 5 //貝塞爾曲線上點的數量 Vector2[] temp_2 Vector2[] temp_3 for i = 0, pointNumber - 1 do temp_3 = temp_1; for j = temp_3.Length - 1, 0, -1 do temp_2 = new Vector2[j]; for k = 0, j do temp_2[k] = Vector3.Lerp(temp_3[k], temp_3[k + 1], i / pointNumber) end temp_3 = temp_2; end Vector2 find = temp_3 point.Add(find); end end
Reference
- https://blog.csdn.net/f_957995490/article/details/106571818
- https://www.jianshu.com/p/afccc4642621