Get the App
SLTechnology News&Howtos  ›  Development  › 

The realization method of Unity Bezier Curve

Shulou Source: shulou.com Published: 2022-06-03 05:17:10 09月23日 Update

This article introduces the relevant knowledge of "Unity Bezier curve implementation method". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Bezier curve of first order

A first-order Bezier curve is just a line, and we can easily find the location of t from t.

P(t)=P0+(P1-P0)*t =(1-t)*P0+ tP1; t[ 0,1] , and it is equivalent to linear interpolation.

Bezier curve of second order

Take three points in the plane that are not collinear, AB:AC=CD:CE, and BD is a straight line at this time, and linear interpolation can be performed according to the first-order Bessel equation.

P(B)=(1-t)*P0+tP1 ;

P(D)=(1-t)P1+tP2 ;

P(t)=(1-t)*P(B)+tP(D)

=(1-t)*((1-t)*P0+tP1)+t((1-t)P1+tP2 )

=(1-t)² *P0+2t*(1-t)*P1+t²*P2 ;t[0,1];

Code:

public LineRenderer line_b;public LineRenderer line_a;public LineRenderer line_c; public Transform start;public Transform end;public Transform c; void Start() { } void Update() { line_a.SetPosition(0, start.position); line_a.SetPosition(1, c.position); line_c.SetPosition(0, end.position); line_c.SetPosition(1, c.position); // float distance = Vector3.Distance(start.position, end.position); Vector3 controlPoint = c.position; //start.position + (start.position+ c.position).normalized * distance / 1.6f; Vector3[] bcList = GetBeizerPathPointList(start.position, controlPoint, end.position, 50); line_b.positionCount = bcList.Length + 1; line_b.SetPosition(0, start.position); for (int i = 0; i < bcList.Length; i++) { Vector3 v = bcList[i]; line_b.SetPosition(i + 1, v); } } public static Vector3[] GetBeizerPathPointList(Vector3 startPoint, Vector3 controlPoint, Vector3 endPoint, int pointNum) { Vector3[] BeizerPathPointList = new Vector3[pointNum]; for (int i = 1; i

Tags: Bezier Bessel curve formula linear interpolation method code content equation more knowledge second order practical learned and then three position again dilemma. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Information MariaDB NVidia