-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBezier.cs
More file actions
20 lines (18 loc) · 1.04 KB
/
Copy pathBezier.cs
File metadata and controls
20 lines (18 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// Source: https://programmerbay.com/c-program-to-draw-bezier-curve-using-4-control-points/
namespace Flow.Utility;
public class Bezier
{
public static Vector3 Approach( Vector3 start, Vector3 end, float startCurveSize, float endCurveSize, float t )
{
var controlPoint1 = start + Vector3.Up * startCurveSize;
var controlPoint2 = end + Vector3.Up * endCurveSize;
float x = (float)(Math.Pow( 1 - t, 3 ) * start.x + 3 * t * Math.Pow( 1 - t, 2 ) * controlPoint1.x + 3 * t * t * (1 - t) * controlPoint2.x + Math.Pow( t, 3 ) * end.x);
float y = (float)(Math.Pow( 1 - t, 3 ) * start.y + 3 * t * Math.Pow( 1 - t, 2 ) * controlPoint1.y + 3 * t * t * (1 - t) * controlPoint2.y + Math.Pow( t, 3 ) * end.y);
float z = (float)(Math.Pow( 1 - t, 3 ) * start.z + 3 * t * Math.Pow( 1 - t, 2 ) * controlPoint1.z + 3 * t * t * (1 - t) * controlPoint2.z + Math.Pow( t, 3 ) * end.z);
return new Vector3( x, y, z );
}
public static Vector3 Approach( Vector3 start, Vector3 end, float curveSize, float t )
{
return Approach( start, end, curveSize, curveSize, t );
}
}