Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adrian-miasik/unity-cubic-bezier-curve
A cubic bézier curve created in Unity using line renderers 🏹
https://github.com/adrian-miasik/unity-cubic-bezier-curve
line-renderer mathematics open-source unity-cubic-bezier-curve unity3d
Last synced: 3 months ago
JSON representation
A cubic bézier curve created in Unity using line renderers 🏹
- Host: GitHub
- URL: https://github.com/adrian-miasik/unity-cubic-bezier-curve
- Owner: adrian-miasik
- License: gpl-3.0
- Created: 2020-01-23T03:11:50.000Z (about 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-09-04T03:59:48.000Z (over 1 year ago)
- Last Synced: 2024-10-14T07:48:29.200Z (4 months ago)
- Topics: line-renderer, mathematics, open-source, unity-cubic-bezier-curve, unity3d
- Language: ShaderLab
- Homepage:
- Size: 6.77 MB
- Stars: 35
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Unity Cubic Bézier Curve
![Sample Gif](promotional/cubic-bezier-curve-demo-preview.gif)
## About
Unity Cubic Bézier Curve is a project used to demonstrate a 3D [bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve) in Unity using line renderers.
**Version**: 1.0.0
**Author**: **[`Adrian Miasik`](https://adrian-miasik.com)**
**License**: [GPL-3.0](LICENSE)
**Contributor(s)**: `-`
Want to help? If you're interested in contributing to the project, please send me a message / reach out: [email protected]## Author Notes
Fun fact: This project inspired me to create [unity-shaders](https://github.com/adrian-miasik/unity-shaders/releases/tag/v1.0.0)## Bulk Logic
``` C#
///
/// Returns a 3D position on the provided cubic bezier curve at a specific time (0-1)
///
/// Start Anchor
/// Start Handle (tangent)
/// End Handle (tangent)
/// End Anchor
/// A number between 0-1. 0 representing P0 and 1 representing P3
public static Vector3 GetPointOnCubicBezierCurve(Vector3 _p0, Vector3 _p1, Vector3 _p2, Vector3 _p3, float _time)
{
float _term = 1 - _time;
float _termSquared = _term * _term;
float _timeSquared = _time * _time;
float _termCubed = _termSquared * _term;
float _timeCubed = _timeSquared * _time;
// Formula Source: https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Cubic_B%C3%A9zier_curves
return _p0 * _termCubed +
_p1 * (3 * _termSquared * _time) +
_p2 * (3 * _timeSquared * _term) +
_p3 * _timeCubed;
}
```