Created
June 7, 2018 23:32
-
-
Save jselstad/1b25477d2a59305bb43d073f66878b74 to your computer and use it in GitHub Desktop.
Kinematic Interpretation of a Cubic Bezier Curve - For Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This function evaluates points along a bezier curve given by a starting position and velocity, and an ending position and velocity | |
// This can be thought of as interpolating between two linear trajectories | |
public static Vector3 cubicBezier(Vector3 aStart, Vector3 aVel, Vector3 bEnd, Vector3 bVel, float duration, float time) { | |
float alpha = time / duration; //Normalize the time | |
Vector3 aEnd = aStart + (aVel * duration); //Where it would end up if it were just A's dynamics | |
Vector3 bStart = bEnd - (bVel * duration); //Where it would start if it were just B's dynamics | |
return | |
(Mathf.Pow(1 - alpha, 3f) * aStart) + | |
(3f * Mathf.Pow(1 - alpha, 2f) * alpha * aEnd) + | |
((3f * (1f - alpha) * alpha * alpha) * bStart) + | |
(alpha * alpha * alpha * bEnd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment